简体   繁体   中英

STTwitter swift type 'Any' has no subscript members on getHomeTimeline method

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"])
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM