1

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.

1 Answer 1

1
var post: Dictionary<String, AnyObject>

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

for userId:String in userIds
{
    childUpdates["/user-posts/\(userId)"] = post
}
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.