Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Swift Essentials
  • Toc
  • feedback
Swift Essentials

Swift Essentials

By : Alex Blewitt, Bandlem Limited
4.8 (4)
close
Swift Essentials

Swift Essentials

4.8 (4)
By: Alex Blewitt, Bandlem Limited

Overview of this book

Whether you are a seasoned Objective-C developer or new to the Xcode platform, Swift Essentials will provide you with all you need to know to get started with the language. Prior experience with iOS development is not necessary, but will be helpful to get the most out of the book.
Table of Contents (10 chapters)
close
9
Index

Creating the client


Now that the utilities are complete, the GitHub client API can be created. Once that is complete, it can be integrated with the user interface.

Talking to the GitHub API

A Swift class will be created to talk to the GitHub API. This will connect to the root endpoint host and download the JSON for the service URLs so that subsequent network connections can be made.

To ensure that network requests are not repeated, an NSCache will be used to save the responses. This will automatically be emptied when the application is under memory pressure:

import Foundation
class GitHubAPI {
  let base:NSURL
  let services:[String:String]
  let cache = NSCache()
  class func connect() -> GitHubAPI? {
    return connect("https://api.github.com")
  }
  class func connect(url:String) -> GitHubAPI? {
    if let nsurl = NSURL(string:url) {
      return connect(nsurl)
    } else {
      return nil
    }
  }
  class func connect(url:NSURL) -> GitHubAPI? {
    if let data = NSData(contentsOfURL...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete