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: 
You want to test if `i` is dividable by any number in the range of [2..i-1] and if it is, then it is not a prime number. Your `j`-loop starts at 1, that is the first error.

Knowing when a number is dividable by another is tested like this: `if (i % j == 0) {` (if the division remainder is zero) where in your code you test for equality with 1 instead.

Third thing is that you make your decision in the first iteration (when j is 1) and always print something in your inner loop. You need to take the logic out of the inner loop. Only if i is not dividable by **any** of the `j`s then it is prime.

Here is a modified version of your code:

```
static void primeNumbers(int n) {
    System.out.println("All the prime numbers up to "+n+" are -->\n");

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

```
```
if (i % j == 0) {
    isPrime = false;
    System.out.print(" ");
}

```

This if statement is always true for any `i` because `j` starts at 1. As a result, you print a space for every number < `n` and >= `2`

Also, `isPrime` may be an unnecessary variable.