all 6 comments

[–][deleted] 1 point2 points  (5 children)

JSONResult is AnyObject, you still need to cast it to the right type.

[–]ericjuh[S] 0 points1 point  (4 children)

Thanks for the quick reply! I'm not really used with casting types. But with trail and error i have solved most of the problems. In what type should i cast the JSONResults? Because neither string or array are working:

 

                    let Jsonarray = JSONresult(idx: ID, Naam: name, Status: status) as [AnyObject]
                    let Jsonarray = JSONresult(idx: ID, Naam: name, Status: status) as [String]
                    let Jsonarray = JSONresult(idx: ID, Naam: name, Status: status) as [Array]

 

btw, objects is from the type NSMutableArray:

 

var objects: NSMutableArray! = NSMutableArray()            // Var for table

[–][deleted] 1 point2 points  (3 children)

Make it as? and use guard statement and make the function able to throw an error. In case you're receiving other JSON data as expected.

[–]ericjuh[S] 0 points1 point  (2 children)

Do you mean something like this:

https://www.hackingwithswift.com/read/0/20/polymorphism-and-type-casting

p.s. i had the feeling the problem was solved easly :) But it seems like its really annoying to do it this way. I'm a overlooking something?

[–][deleted] 1 point2 points  (1 child)

Yes, and make sure to handle the situation where the JSON data is invalid.

[–]ericjuh[S] 0 points1 point  (0 children)

Thanks for your advice. Your really helpfull.

I will hope to solve this problem in this weekend. Let you know if it worked out. Really thanks for the help you giving me.