ios course day 2

26
Day 2

Upload: rich-allen

Post on 05-Apr-2017

196 views

Category:

Engineering


0 download

TRANSCRIPT

Day 2

Recap

Story BoardsStoryboards are the user interface elements of an App

In modern versions of Xcode this is integrated in the program.

Story Boards ExplainedThe top pain allows you to edit the file / element your working on. The Bottom allows you to choose elements/ objects to add

Choose the View Controller Class that is associated with this view (MVC)

Choose objects to add to a view such as UITextField, UIButton or objects such as a new View.

Delegation "A delegate is an object that acts on behalf of, or in coordination with, another object when that object encounters an event in a program."

Classes acting as delegates must fulfil some obligations (delegate methods) usually declared in a protocol (interface)

Examples: AppDelegate

UITableViewDelegate

Table ViewsOne of the most commonly used elements is UITable View

Two of Types of UI Table ViewPlain Grouped

Table ViewsA Table View consists of many parts all of which are

able to be customised.

Table ViewSection

Section Headerwith Label

Table View Cellwith Label

Table ViewsApple has created a controller for a UITableView

Called UITableViewController and if you subclass it in your View Controller then it will set this stuff up for you.

Header file (.h)

Subclass UITableViewController

Declare the Delegate and Datasource Protocols

Implementation file (.m)

UITableViewDelegate Methods

Demo(TableView)

View Controller Lifecycle

viewDidLoad

viewWillAppear

viewDidAppear

viewWillDisappear

viewDidDisappear

viewDidUnload

Demo(Image View, Web View, Collection View)

Navigation Controller

The Navigation Controller is a very common way to display multiple views and works with a stack

Navigation ControllerBy using the navigation controller iOS creates a container and then automatically creates the bar at the top with the back button allowing users to easily navigate. There is also a lot of performance enhancements behind the scenes too.

To create a navigation stack you can easily do that in the storyboard.

Demo Linking Nav Controller

Persistence In iOS there are a range of ways to persist data on and off the device.On Device

• NSUserDefaults (max 300kb) - This is for small amounts of data, usually used for saving settings / User data in apps

• Plist / Disk - This is for slightly larger data and doesn't really have a limit but can be low on performance. Mainly used for media on disk.

• Core Data - This is the most common way for storing data and is the iOS internal DB. It runs on a NO-SQL basis.

• SQL Lite - This is another option for a DB and uses SQL.

Off Device• Web Service - Third party API’s allow you to easily store data off device and

usually charge based on concurrent requests to the server. Some examples are below.

1. AWS2. Parse3. Other 3rd Party

Persistence

File System: Property Lists

- NSArray and NSDictionary can do this - Can only save supported “plist” types - - NSString- - NSNumber- - NSDate - - NSData

Persistence

File System: Saving Images

- Get resources from the main app bundle (images, databases, mp4)

Blocks and Multi Threading

One of the main ways in which computers since the 90’s have dealt with multiple processes is Multi Threading

Multi Threading means that you can run multiple concurrent processes separately on whats called threads.

Number 1 rule is that all UI should be called on the main thread.

Why use Threads? One use is so that if were pulling data over the network then we don’t block the UI of the app. If we do it will give a bad experience and make our user think the app has crashed.

Blocks and Multi Threading

To use threads on iOS we use something called Blocks. Blocks are very common is iOS since the release of iOS 5.

Blocks

Further info on blocks - http://www.raywenderlich.com/9438/how-to-use-blocks-in-ios-5-tutorial-part-2

What is a block?- a block of code (i.e a sequence of statements inside {}).

Usually included “in-line” with the calling of a method that is going to use that block of code.

Example of Block

Blocks and Multi Threading

To dispatch a task to a different Thread we use a C API called ‘Grand Central Dispatch’ (GCD).

Animations

You can easily animate any UI View using core animation. An example of this is below

Categories

Categories allow us to add extra methods to existing classes even if we didn't write them.

Header (.h)

CategoriesInterface (.m)

Frameworks and Coca Pods

Frameworks in iOS are collections of code that allow apps to take use of extended functionality.

Examples of Apple Frameworks: MapkitCore AudioCore Animation

Examples of 3rd Party Frameworks: StripeFacebookParseTwitter

Testing Your App

To test your app on the simulator then simply build and run and in Xcode and it will launch in the simulator.

To test your app on a device you will need to be enrolled in the Apple Developer Program and then generate a Development Provisioning Profile.

Instruments and Other Apps

Apple automatically installs a range of applications that can be used to find where issues lie in your app. Such as Memory leaks and others.

• String with format

• App Coda

• Ray Weinerlich