Question: we have json data that is put into a custom object:

```
 "sentMoney": [
                {
                    "amount": 3840.83,
                    "currency": "MXN",
                    "isMajor": false
                },
                {
                    "amount": 200,
                    "currency": "USD",
                    "isMajor": true
                }
        ]

public final class SentMoney: NSCoding {
  public var currency: String?
  public var isMajor: Bool? = false
  public var amount: Double?
}

```

the custom object is then made reference to in a variable:

```
 public var sentMoney: [SentMoney]?

```

Now what we are trying to do is only get the FIRST amount (3840.83).

I tried doing it this way but there were errors:

```
 let amountsOnlyArray = self.postTransferSuccess?.sentMoney.map({ $0["amount"] })//Error -Cannot subscript a value of type '[SentMoney]' with an index of type 'String' 
 let firstAmountOnly = self.postTransferSuccess?.sentMoney![0]["amount"]//Error -Type 'BSentMoney' has no subscript members

```

Is there a better way to get that first amount?

Answer: 
Your algorithm, although slow, seems to be correct on most parts except for the fact that you are not handling the boundary conditions well. E.g. 2 is a prime number, you are running iterations only till n-1, you are not reseting the isPrime flag for every number, and a few small things. Here's a revised working version. Try to compare it with yours and understand where you didn't get it right.

```
    int n = 10;
    System.out.println("All the prime numbers up to "+n+" are -->\n");

    boolean isPrime = true; 
    for(int i = 2; i <= n; i++)
    {
        for (int j = 2; j < i; j++)
        {   
            if(i % j == 0)
            {
                isPrime = false; 
                break;
            }
        }
        if(isPrime) {
            System.out.println(i);
        }
        isPrime = true;
    }

```
I think is a logical problem in your script.
You should count with a loop all the number from 2 to n-1 which are = to 0 with a test 

```
n%i = 0

```

If the counter = 0 then no divider then prime number