TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Aug 2015 |
SPMSupports SPM | ✗ |
Maintained by Kyle Goslan.
Depends on: | |
Alamofire | ~> 1.3 |
SwiftyJSON | ~> 2.2.1 |
TwitterJSON makes it very easy to get up and running with the Twitter REST api on iOS devices. You can start getting responses in just a few lines of code. It uses the account from the persons device to authorize requests.
You can start getting results from Twitter with just one method call. For example, to get the main feed of the user:
TwitterJSON.getHomeFeed { (tweets) -> Void in
}
All methods are class methods of the TWitterJSON
class, so no need to initilize any objects. In the example above the completion handler contains an array of TJTweet objects. Each of which represent a tweet. You can now do what you want with this array of tweets, for example:
TwitterJSON.getHomeFeed { (tweets) -> Void in
for tweet in tweets {
println(tweet.user.name)
println(tweet.text)
}
}
Thats it!
By default all requests that return an array of either tweets or users will return 20 results. This is defined as a static class variable, meaning that when you set it it will remain at that until it is later changed. To change the number of results:
TwitterJSON.numberOfResults = 5
Note: Twitters REST API requests have limits.
The following methods get tweets, and will return an array of TJTweet objects.
TwitterJSON.getHomeFeed { (tweets) -> Void in
//Returns tweets from the users home feed.
}
TwitterJSON.searchForTweets("Apple", completion: { (tweets) -> Void in
//Returns tweets containing the given search query.
})
Note: All tweets also contain a TJUser
object which is the infomation about the user who posted the tweet.
The following methods get users, and will return an array of TJUser objects.
TwitterJSON.getFollowersForUser("KyleGoslan", completion: { (users) -> Void in
//Returns a list of followers following the specified user.
})
TwitterJSON.getFollowingForUser("KyleGoslan", completion: { (users) -> Void in
//Returns a list of people the specified user is following.
})
The following methods will post data to Twitter and return a bool value to represent success.
TwitterJSON.postTweet("Hello World", completion: { (success) -> Void in
//Will post the given string to twitter.
})
TwitterJSON.retweet(123456789, completion: { (success) -> Void in
//Will retweet the tweet with the given ID.
})
TwitterJSON.favoriteTweet(123456789, completion: { (success) -> Void in
//Will favorite the tweet with the given ID.
})