O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Todo item

To create a Todo item, we can call sendRequest function in our MasterViewController viewDidLoad() method to be sure that it is working:

let newRequest = TodoRequest(id: 1,                             name: "First request",                             description: "description",                             notes: "notes",                             completed: false) sendRequest(Alamofire.Method.POST, request: newRequest) 

This should add a new Todo item to our backend.

Our sendRequest method is incomplete and it does not provide a call back to receive the data. Let's improve it:

func sendRequest(method: Alamofire.Method,                 request: RequestProtocol,                 completion: @escaping (_ responseData: AnyObject?,                  _ error: Error?) -> Void) {     // Add Headers     let headers = configureHeaders(request)     // Fetch Request  Alamofire.request(method, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required