• 検索結果がありません。

Enoch ios programming and swift

N/A
N/A
Protected

Academic year: 2018

シェア "Enoch ios programming and swift"

Copied!
49
0
0

読み込み中.... (全文を見る)

全文

(1)

Introduction to

iOS Programming and Swift

Enoch Huang 黃心和

(2)

Outline

• Programming for Apple

• Swift

• Steps to create an iOS app

• An iOS app example

(3)

Outline

• Programming for Apple

• Swift

• Steps to create an iOS app

• An iOS app example

(4)

Programming for Apple (1/9)

Mac macOS

OS X

iPhone/iPad iOS

Apple Watch watchOS

Apple TV tvOS Apple Devices

(5)

Programming for Apple (2/9)

Two Programming Languages

Objective-C

- Developed since early 1980s - Superset of C

- Still popular

Swift

- Unveiled in June 2014

- Ideas from many programming languages - Open source since December 2015

(6)

Programming for Apple (3/9)

How to learn?

Start with Swift - Easier to learn

- Latest resources for beginners are in Swift, not Objective-C. - I ll new to everybody

Then Objective-C - More resources

- B l n al a pl . - For iOS developer career

(7)

Programming for Apple (4/9)

1. Computer – Mac

2. Account – Apple ID

3. Development Environment – Xcode

Development Requirement

(8)

Programming for Apple (5/9)

Mac

Development Requirements 1. Computer

(9)

Programming for Apple (6/9)

If you have an iPhone, you should already have an Apple ID.

Otherwise, create an Apple ID for free.

Development Requirements 2. Account Apple ID

(10)

Programming for Apple (7/9)

Development Requirements 2. Account

• Individual/Organization - US$99/year for App Store Distribution

• Enterprise Program – US$299/year for In-House App Distribution

• iOS University Program – Free for App Exchange between members

Apple Developer Programs

FYI only

(11)

Programming for Apple (8/9)

- Integrated Development Environment (IDE) - Free

- For OS X / iOS / watchOS / tvOS - Simulators included

Development Requirements 3. Development Environment

Xcode

(12)

Build & Run Xcode

Simulator Project

Navigator

Debug Area

Programming for Apple (9/9)

(13)

Outline

• Programming for Apple

• Swift

• Steps to create an iOS app

• An iOS app example

(14)

The Swift programming language (1/9)

- A fast growing programming language: Development started - 2010

Unveiled - June 2014

Swift 1.0 - September 2014

Swift 2.0 - September 2015 (try/catch) Swift 3.0 - Fall 2016? (work with C++) - Became Open Source in December 2015

(Available on Linux now)

History 雨燕

(15)

The Swift programming language (2/9)

- More efficient than Objective-C & Python

The Apple Worldwide Developers Converence (WWDC) 2014

(16)

The Swift programming language (3/9)

Swift Resources

Official Guide - The Swift Programming Language Tutorials - Ray Wenderlich

AppCoda (AppCoda中文版)

Q&A - Stack Overflow Slides - SlideShare

Video- Getting Started with Swift Ebook- Swift 起步走

Don’t buy any book!! Swift books become

outdated quickly.

(17)

The Swift programming language (4/9)

Learn Swift without a Mac!

Free website:

IBM Swift Sandbox

(18)

The Swift programming language (5/9)

Hello, World!

Constant

String

Show

No Semicolon ( ; ) let str = "Hello, World!"

print(str)

IBM Swift Sandbox Example

(19)

The Swift programming language (6/9)

Type Inference

IBM Swift Sandbox Example

let lab : String = "WIDM” let floor : Int = 3

Type Declaration

let lab = "WIDM” let floor = 3

(20)

The Swift programming language (7/9)

Switch Case

IBM Swift Sandbox Example

let condition = true if condition {

print("Condition is true!!") }

If Condition

var myCondition = 5

switch myCondition { case 0:

print("This is zero.") case 1:

print("myCondition is one.") case 2,3:

print("I like number two or three.") case 4...10:

print("Four to ten.\nfallthrough") fallthrough

default:

print("The default case.") }

(21)

The Swift programming language (8/9)

IBM Swift Sandbox Example

For Loop

for count in 0...5 {

print("count=\(count)") }

Condition //Explicit format:

var fruitList: Array<String> = ["apple", "banana"]

//Explicit shortcut format:

var fruitList: [String] = ["apple", "banana"]

//Type inference

var fruitList = ["apple", "banana"]

Array

(22)

The Swift programming language (9/9)

More …

While Loops, Array Manipulation, Dictionaries, Functions, Closures, Enumerations, Classes, Structures, Inheritance, Optional, Error Handling, Type Casting, Protocols…

(23)

Outline

• Programming for Apple

• Swift

• Steps to create an iOS app

• An iOS app example

(24)

Steps

Steps to create an iOS app (1/15)

1. Add Apple ID account to Xcode. 2. Create a new Xcode project.

3. Run the app. 4. Start coding.

(25)

Steps

Steps to create an iOS app (2/15)

1. Add Apple ID account to Xcode.

2. Create a new Xcode project. 3. Run the app.

4. Start coding.

(26)

1. Add Apple ID Account to Xcode

Steps to create an iOS app (3/15)

(1) Run Xcode.

(2) Select Xcode  Preferences

(3) Select Accounts  + sign  Add Apple ID

(27)

Steps to create an iOS app (4/15)

(4) Enter the Apple ID (email address) and password. Select Sign In.

(5) The account information such as team and role of the Apple ID is shown as below.

1. Add Apple ID Account to Xcode

(28)

Steps

Steps to create an iOS app (5/15)

1. Add Apple ID account to Xcode. 2. Create a new Xcode project.

3. Run the app. 4. Start coding.

(29)

Steps to create an iOS app (6/15)

(1) Create a new project

2. Create a new Xcode project

(2)

Select iOS  Application

 Single View Application

 Next

(30)

Steps to create an iOS app (7/15) 2. Create a new Xcode project

(3) Configure project settings:

• Product name

Organization Name/Identifier

• Language (Swift/Objective-C)

• Devices (iPhone/iPad/Universal)

• CoreData and Unit/UI tests options

(31)

Steps

Steps to create an iOS app (8/15)

1. Add Apple ID account to Xcode. 2. Create a new Xcode project.

3. Run the app. 4. Start coding.

(32)

Steps to create an iOS app (9/15)

1. Select the iOS simulator or device 2. Click

the Run button.

3. Run the app

(33)

Steps to create an iOS app (10/15)

Wait for the simulator to launch.

Ignore any error messages.

Run Run

A white screen should be

displayed.

3. Run the app

(34)

Steps

Steps to create an iOS app (11/15)

1. Add Apple ID account to Xcode. 2. Create a new Xcode project.

3. Run the app. 4. Start coding.

(35)

. - 4s (Before iOS 10) - 5 / 5s / 5c / SE

.7 - 6 / 6s

. - 6 Plus / 6s Plus

Source:http://www.idev101.com/code/User_Interface/sizes.html

iPhones on market

3:2 16:9

2011 ’12/’13/’16 2014/2015

Steps to create an iOS app (12/15) 4. Start coding

(36)

Storyboard

Programmatically

Two UI implementation methods

Steps to create an iOS app (13/15) 4. Start coding

(37)

ViewController Structure

4. Start coding

Steps to create an iOS app (14/15)

(38)

Steps to create an iOS app (15/15)

Open ViewController.swift and add the two lines in func viewDidLoad(): view.backgroundColor = UIColor.orangeColor()

print("Hello, World!")

Called when app is started.

UIKit Framework

4. Start coding

(39)

Outline

• Programming for Apple

• Swift

• Steps to create an iOS app

• An iOS app example

(40)

An iOS app example (1/7)

• Button at the center

• Change the background color

A Simple Example

(41)

Storyboard

Two UI implementation methods

An iOS app example (2/7) ViewController.swift

Programmatically

(42)

An iOS app example (3/7)

• Button added to the root view.

• Background color of

the root view is changed.

ViewController Structure

No child views in this example.

(43)

ViewController.swift

An iOS app example (4/7)

(1) Add a UIButton to the root view of the ViewController in func viewDidLoad():

Size and position

Show in view

Color

(44)

ViewController.swift

An iOS app example (5/7)

(2) Add an action pressed() to the UIButton:

(45)

ViewController.swift

An iOS app example (6/7)

(3) Create a constant array of various colors and a color variable above func viewDidLoad():

(4) Modify the button action function pressed() as below:

(46)

ViewController.swift

An iOS app example (7/7)

Complete code:

(47)

Outline

• Programming for Apple

• Swift

• Steps to create an iOS app

• An iOS app example

(48)

W a Nex ?

(49)

Now Begin Your iOS Developer Journey!

参照

関連したドキュメント

We show how the tau constant changes under graph oper- ations such as the deletion of an edge, the contraction of an edge into its end points, identifying any two vertices,

Finally, we give an example to show how the generalized zeta function can be applied to graphs to distinguish non-isomorphic graphs with the same Ihara-Selberg zeta

As a direct corollary of our results, a Dunkl harmonic function bounded below or above is actually constant, which extends the corresponding result of Gallardo and Godefroy for

As with subword order, the M¨obius function for compositions is given by a signed sum over normal embeddings, although here the sign of a normal embedding depends on the

Making use, from the preceding paper, of the affirmative solution of the Spectral Conjecture, it is shown here that the general boundaries, of the minimal Gerschgorin sets for

We show that a discrete fixed point theorem of Eilenberg is equivalent to the restriction of the contraction principle to the class of non-Archimedean bounded metric spaces.. We

In particular, we show that the q-heat polynomials and the q-associated functions are closely related to the discrete q-Hermite I polynomials and the discrete q-Hermite II

In [9] a free energy encoding marked length spectra of closed geodesics was introduced, thus our objective is to analyze facts of the free energy of herein comparing with the