Top Banner
Using Xcode
39

Introduction of Xcode

Jul 16, 2015

Download

Technology

Dhaval Kaneria
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction of Xcode

Using Xcode

Page 2: Introduction of Xcode

Introduction to XCode

• This tutorial will walk you through Xcode, a software development tool for Apple’s iOS applications– We will explore its different parts and

their functions– This tutorial will teach you how to use

Xcode, but not how to build an app.• To build an app, you need to know Objective-

C.

Page 3: Introduction of Xcode

Useful Terms

• Objective-C: the programming language used to write iOS applications, based on C and using object oriented programming methods

• Object: a collection of code with its data and ways to manipulate that data

Page 4: Introduction of Xcode

Useful Terms

• View: how your program presents information to the user

• Model: how your data is represented inside of your application

Page 5: Introduction of Xcode

App Templates, Pt 2

Tabbed: Like the iPod app, with lots of different ways to view the same database items

Utility: Like the weather app, a main view and a configuration view

Empty: You build everything from scratch

Page 6: Introduction of Xcode

Starting an App

Choose the name you want for your app

Click ‘Next’

Choose a folder in which to save your app

Finally, choose your device

Writing a universal iOS app is more difficult than writing for just one device

Page 7: Introduction of Xcode

This is what your screen looks like now….

Page 8: Introduction of Xcode

The main parts we’ll be focusing on…1. Navigator Panel

3. Libraries

2. Inspector Panel

Page 9: Introduction of Xcode

Navigator Panel

Page 10: Introduction of Xcode

The Classes folder contains two objects:

- The App Delegate

- The View Controller

The extensions:- .h = header, defines

object- .m= main/body-.xib= XML interface

builder

Page 11: Introduction of Xcode

The App Delegate

• Handles starting and ending your app

• Serves as a go-between between iOS and your app– Hands off control to your code after

starting

Page 12: Introduction of Xcode

The View Controller

• Handles everything that shows up on screen

• Handles all the info that the onscreen objects need to display themselves

• Translates between the view and the model

• Responds to user input and uses that to change model data– Responsible for updating view from the

model

Page 13: Introduction of Xcode

To help visualize…

From developer.apple.com

Page 14: Introduction of Xcode

XML Interface Builder

This is where you lay out graphic views

The view controller knows how to talk to the objects that have been created here

Lots of formatting options

Page 15: Introduction of Xcode

Supporting Files, Pt. 1

These are system files

.plist = property list

Appname-Info.plist = contains info about your app for the iOS. It is an XML file that includes the options you put on your app (which device, etc.)

InfoPlist.strings = helps to internationalize your app

- Language translation cues

- .strings is any text

Page 16: Introduction of Xcode

Supporting Files, Pt. 2

Main.m = low level. Starts app and gives to the App Delegate. Never change this file.

.pch = pre-compiled header

Appname-Prefix.pch = generated by the system to speed up builds

Page 17: Introduction of Xcode

Frameworks

Frameworks contains a lot of already written code provided by the system

- A library of code bits- Related to the Libraries menu on the right of

Xcode

UIKit = contains code for everything that interfaces with the user (views)

Foundation = alll the components used to build the model

CoreGraphics = handles drawing on the screen

Page 18: Introduction of Xcode

Inspector Panel

• This area contains utilities panels that let you change properties of your app’s view objects, like:

• Colors• Sizes• Images• Button actions

Page 19: Introduction of Xcode

Libraries

• Different goodies depending on which icon you click– From left to right:

• File templates• Code snippets• View Objects• Media/Images

Page 20: Introduction of Xcode

Model, View, Controller (MVC)iOS applications follows

the MVC design pattern.

• Model: Represents the business logic of your application

• View: Represents what the user sees in the device

Page 21: Introduction of Xcode

• Controller: Acts as a mediator between the Model and View. There should not be any direct conversation between the View and the Model. The Controller updates the View based on any changes in the underlying Model. If the user enters or updates any information in the View, the changes are reflected in the Model with the help of the Controller.

Page 22: Introduction of Xcode

How does a View or Model interact with the Controller?

• Views can interact with the Controller with the help of targets or delegates.

• Whenever the user interacts with a View, for example by touching a button, the View can set the Controller associated with it as the target of the user’s action. Thus the Controller can decide on further actions to be taken. We will see how this can be achieved in the later part of this tutorial.

• Views can also delegate some of the actions to the Controller by setting the Controller as its delegate.

Page 23: Introduction of Xcode

MVC

Page 24: Introduction of Xcode

• The Model notifies the Controller of any data changes, and in turn, the Controller updates the data in the Views. The View can then notify the Controller of actions the user performed and the Controller will either update the Model if necessary or retrieve any requested data.

Page 25: Introduction of Xcode

Outlet And ActionsOutlet: • ViewController talks to View by using

Outlet. Any object (UILabel, UIButton, UIImage, UIView etc) in View can have an Outlet connection to ViewController. Outlet is used as @property in ViewController which means that:

• you can set something (like Update UILabel's text, Set background image of a UIView etc.) of an object by using outlet.

• you can get something from an object (like current value of UIStepper, current font size of a NSAttributedString etc.)

Page 26: Introduction of Xcode

Action:•   View pass on messages about view to

ViewController by using Action (Or in technical terms ViewController set itself as Target for any Action in View). Action is a Method in ViewController (unlike Outlet which is @property in ViewController).

• Whenever something (any Event) happens to an object (like UIbutton is tapped) then Action pass on message to ViewController. Action (or Action method) can do something after receiving the message.Note: Action can be set only by UIControl's child object; means you can't set Action for UILabel, UIView etc.

Page 27: Introduction of Xcode

Application Life Cycle

Page 28: Introduction of Xcode
Page 30: Introduction of Xcode

• applicationWillResignActive:—Lets you know that your app is transitioning away from being the foreground app. Use this method to put your app into a quiescent state.

• applicationDidEnterBackground:—Lets you know that your app is now running in the background and may be suspended at any time.

• applicationWillEnterForeground:—Lets you know that your app is moving out of the background and back into the foreground, but that it is not yet active.

• applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.

Page 31: Introduction of Xcode

Application State• Not running

• Inactive

• Active

• Background

• Suspended

Page 32: Introduction of Xcode
Page 33: Introduction of Xcode

View controller

• Connect the view and the controller with

IBOutlet

Page 34: Introduction of Xcode

View Controller Life Cycle

• - (void)viewDidLoad;

• - (void)viewWillAppear:(BOOL)animated;

• - (void)viewDidAppear:(BOOL)animated;

• - (void)viewWillDisappear:(BOOL)animated;

• - (void)viewDidDisappear:(BOOL)animated:

• -(void) viewDidUnload;

Page 35: Introduction of Xcode
Page 36: Introduction of Xcode

UINavigationController• The UINavigationController class

implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and makes it easier for the user to navigate that content.

• A navigation controller object manages the currently displayed screens using the navigation stack

Page 37: Introduction of Xcode

TableView Control

• Table View is one of the common UI elements in iOS apps

• Most apps, in some ways, make use of Table View to display list of data

• The “UITableViewDelegate” and “UITableViewDataSource” are known as protocol in Objective-C. Basically, in order to display data in Table View, we have to conform to the requirements defined in the protocols and implement all the mandatory methods.

Page 38: Introduction of Xcode

UITableViewDelegate

• UITableViewDelegate, deals with the appearance of the UITableView. Optional methods of the protocols let you manage the height of a table row, configure section headings and footers, re-order table cells, etc.

Page 39: Introduction of Xcode

UITableViewDataSource

• We’ll use the table view to present a list of recipes. So how do you tell UITableView the list of data to display? UITableViewDataSource is the answer. It’s the link between your data and the table view. The UITableViewDataSource protocol declares two required methods

• tableView:cellForRowAtIndexPath • tableView:numberOfRowsInSection