All, I am really new to iOS development so that means I am new to Swift. I have knowledge of other programming languages like c#, PHP, Node JS, etc. However, I have found myself stuck and can't find any answers.
I am working with STTwitter and I am trying to pull the status of my Twitter. I can pull it fine using the normal method. When I try to add a loop, I get an error: Type 'Any' has no subscript members.
// Verifying Twitter API creds
twitter?.verifyCredentials(userSuccessBlock: { (username, userId) in
// Get Twitter Timeline Status
twitter?.getHomeTimeline(sinceID: nil, count: 10, successBlock: { (statuses) -> Void in
for status in statuses! {
print(status["text"])
}
}, errorBlock: { (error) in
print(error)
})
print(username, userId)
}, errorBlock: { (error) in
print(error)
})
Here is a screenshot of the actual editor with the error
The error is on the "status" inside the print statement inside the for loop.
Any help would be great!
getHomeTimeline
accepts a "block" (or Swift closure) that is passed an NSArray *
, which is translated in Swift to [Any]. So
// Get Twitter Timeline Status
twitter?.getHomeTimeline(sinceID: nil, count: 10, successBlock: { (statuses) -> Void in
for status in statuses! {
print((status as? NSDictionary)?["text"])
}
}