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

Loading data from URLs


The most common way to load data from a remote network source is to use an HTTP (or HTTPS) URL of the form https://raw.githubusercontent.com/alblue/com.packtpub.swift.essentials/master/CustomViews/CustomViews/SampleTable.json.

URLs can be manipulated with the NSURL class, which comes from the Foundation module (which is transitively imported from the UIKit module). The main NSURL initializer takes a String initializer with a full URL, although other initializers exist for creating relative URLs or for references to file paths.

The NSURLSession class is typically used to perform operations with URLs, and individual sessions can be created through the initializer or the standard shared session can be used.

Tip

The NSURLConnection class was used in older versions of iOS and Mac OS X. References to this class might still be seen in some tutorials, or might be required if Mac OS X 10.8 or iOS 6 needs to be supported; otherwise, the NSURLSession class should be preferred.

The...