0

I'm storying an array of JavaScript key/value objects in a column of type Array on Parse like this:

[{"1432747073241":1.1},{"1432142558000":3.7}]

When I retrieve that column in Swift, I can see the data, but I'm unsure what data type to cast it as:

if let data = dashboardObject[graphColumn] as? [AnyObject]{  
  for pair in data{
    println(pair)
  }
}

That print yields this in the console (for the first pair):

{
  1432747073241 = "1.1";
}

I can't seem to cast its contents as a Dictionary [Int:Double] and I'm guessing that means this is a string.

How do I parse this data in Swift? Thanks.

3
  • 1
    The Dictionary you should parse it to is [String: AnyObject]. It seems as if the keys of this dictionary are timestamps which you probably don't know. You could iterate through the dictionary like this: for (key, value) in pair { } Commented May 27, 2015 at 20:21
  • 1
    Ah, great, thanks! Can you post that as an answer and I'll accept it? Commented May 27, 2015 at 21:00
  • And yes, I'm aware that they are time stamps. Thanks. Commented May 27, 2015 at 21:01

1 Answer 1

1

The Dictionary you should parse it to is [String: AnyObject]. It seems as if the keys of this dictionary are timestamps which you probably don't know. You could iterate through the dictionary like this:

for (key, value) in pair {
  // do what you want in here with the value and/or the key 
}
Sign up to request clarification or add additional context in comments.

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.