Book Image

Swift Essentials

By : Alex Blewitt, Bandlem Limited
Book Image

Swift Essentials

By: Alex Blewitt, Bandlem Limited

Overview of this book

Table of Contents (16 chapters)
Swift Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Summary


This chapter presented the common techniques to deal with networked data in Swift-based applications, with a particular focus on how to maximize battery usage on portable devices using asynchronous techniques to access data.

Since most network requests are likely to provide either a JSON or XML based representation over HTTP(S), the first section of this chapter covered using NSURLSession and the asynchronous dataTask operations to pull data down from a remote server. The second and third sections then presented how this data can be parsed from either JSON or XML, depending on the format required.

The last section presented how to make network connections directly in order to deal with protocols other than HTTP, and as an example, showed how a remote git command can be executed to find out which references are available in a remote git repository. This was presented in two forms: as a synchronous API (to demonstrate the technique of how to work with streams and to explain the git protocol...