0

I have an array column in Parse that is called homeAddress. Inside it is the following value for a single row:

["111111","222222"]

I wish to access this in swift. I created a local array called homeAddress of String type. How can I store the first element in the Parse column (i.e. 111111) in the first element holder in local array i.e. homeAddress[0]? And then I need to store the 222222 in the homeAddress[1].

1
  • Are you trying to query this from parse to use in your application? Commented Dec 7, 2015 at 22:53

3 Answers 3

1

So what you want is load this data from parse. You can just call a Parse Query get the results and work with them:

let query = PFQuery(className:"ClassName")
query.findObjectsInBackgroundWithBlock {
      (results, error) -> Void in
          if (error == nil) {
                for object in results!{
                    let homeAddress = object["homeAddress"] as! NSArray
                }
          }else {
                    print(error?.userInfo)
                }
}
Sign up to request clarification or add additional context in comments.

Comments

1

One way would be to trim first and last character and just separate values by comma:

var test = "[\("111111"),\("222222")]"
var trimmedStringRange = Range<String.Index>(start: test.startIndex.successor(), end: test.endIndex.predecessor())
var homeAddress = test.substringWithRange(trimmedStringRange).componentsSeparatedByString(",")

Comments

0

If your local array is empty, you can add your values from the parse array like this (after getting the array from Parse):

localHomeAddress.append(homeAddress)

This will put all values from homeAddress array in localHomeAddress array.

If you use a splice, you can ensure you are adding the values from index 0:

localHomeAddress.insertContentsOf(homeAddress, at:0)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.