Description
Hey everyone! I recently published Swift Twitch, a wrapper around the New Twitch API that’s written in Swift. If anyone is thinking about starting an iOS / Swift-based project that uses the Twitch API, I would highly suggest using Swift Twitch as a basis point.
Link: GitHub - Chris-Perkins/SwiftTwitch: 👾 The New Twitch API for iOS; wrapped in Swift goodness 👾
I wrap around most of the client-facing functions (currently missing checking/updating active user extensions) available from the Helix API. I made sure that usability and typed-data classes were of utmost importance. For example, using Swift Twitch, you can check if two users are following each other by using the following function:
Example Function
func spectacularFunction() {
TwitchTokenManager.shared.accessToken = "$SomeValidToken"
let user1Id = "1234"
let user2Id = "5678"
Twitch.Users.getUsersFollows(followerId: user1Id, followedId: user2Id) { result in
switch result {
case .success(let getUsersFollowsData):
/* If the total = 1, we know that user1 is following user2
as it is documented in the Twitch Reference docs. */
if getUsersFollowsData.total == 1 {
print("User \(user1Id) is following user \(user2Id)!")
} else {
print("User \(user1Id) is not following user \(user2Id)")
}
case .failure(let data, let response, let error):
print("The API call failed! Unable to determine relationship.")
}
}
}
Example Project
I also included an example project that pulls video data from a pre-selected user. This is included in the Swift Twitch repository. Simply follow the instructions of the “Example” section in the README to get started.
I hope that some of you find this library useful for beginning your Twitch-based iOS projects! I will be using it personally for my capstone project this semester, so expect continued development.
Cheers,
Chris