Wayne Filkins Wayne Filkins - 8 months ago 57
iOS Question

How to append objects to a custom array in Swift

I have an array of strings:

var userIds = [String]()

I need to use those ID's to make an array of objects. This is what I need it to look like, I think the type needs to be [String, AnyObject]

var post: Dictionary<String, AnyObject>

let childUpdates = ["/user-posts/\(userIDs[0])": post,
"/user-posts/\(userIDs[1])": post,
"/user-posts/\(userIDs[2])": post,
"/user-posts/\(userIDs[3])": post]

The main problem I am running into here is when I try to use += in a for loop it doesn't let me, also if I try .append that doesn't work either. I think I can change the type of the post object if needed.

var post: Dictionary<String, AnyObject>

var childUpdates: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()

for userId:String in userIds
    childUpdates["/user-posts/\(userId)"] = post