developing ios apps with swift

22
Swift Programming in iOS Developing Apps using Swift

Upload: new-generation-applications

Post on 15-Jan-2015

3.226 views

Category:

Mobile


5 download

DESCRIPTION

Swift is a new programming language introduced by Apple for iOS and Mac app development. It has the best of both C and Objective-C with speed, interactivity and modern conventions.

TRANSCRIPT

Page 1: Developing iOS apps with Swift

Swift Programming in

iOSDeveloping Apps using Swift

Page 2: Developing iOS apps with Swift

App Extensions - for sharing, photo editing, storage, custom keyboards (yay!) and much more

Touch ID - forget registration and login, Touch ID authentication is here

Games - many improvements to SpriteKit, SceneKit, OpenGL and a new framework Metal - for high performance in games

Health Kit - a new framework for managing health-related info. Make way for revolutionary health apps

iOS 8- New Features

Page 3: Developing iOS apps with Swift

Home Kit - communicate with connected devices (you don’t need to go to the switch now)

Handoff - seamless continuity of activities across devices

Photos - there is so much more you can do with Photos now And much more

Sharing documents between apps

More inclusive notifications

Better search

iOS 8- New Features

Page 4: Developing iOS apps with Swift

Why Swift?

Page 5: Developing iOS apps with Swift

What Apple saysFast - performance wise, Swift is much faster than Objective-C

Modern - borrows from Haskell, Ruby, Javascript - skill barrier greatly lowered

Interactive - a Playground allows programmers to experiment with Swift code and see results immediately - no building and running

Page 6: Developing iOS apps with Swift

The announcement of Swift got mixed reactions

What developers say

Page 7: Developing iOS apps with Swift

Show me the code!

Page 8: Developing iOS apps with Swift

Some key pointsDeclaration and implementation are in the same file (no .h and .m files)

Project size is largely reduced with Swift

Swift auto-detects data types

The code does not use semi-colons

Braces are compulsory for if-else conditions

Page 9: Developing iOS apps with Swift

Variables (and type inference)

//variablesvar name: String = "Jane Doe"var year: Int = 2014var isFast: Bool = true

//Data type detectionname = "John Doe"year = 2016isFast = false

//Data type detectionvar name = "Jane Doe"var year = 2014var isFast = true

Page 10: Developing iOS apps with Swift

//constants

let name: String = "Jane Doe"

let year: Int = 2014

let isFast: Bool = true

//These will give an error

name = "John Doe"

year = 2016

isFast = false

Constants

Page 11: Developing iOS apps with Swift

let hello = "Hello"

let world = "World"

let firstString = hello + " " + world //Will print Hello World

let a = 4, b = 5

println ("\(a) * \(b) = \(a * b)") //Will print 4 * 5 = 20

isFast = false

String Operations

Page 12: Developing iOS apps with Swift

//Typed arrays

var typedList: String[] = ["Yes", "No", "Cancel"]

typedList += ["OK"] //typedList - Yes, No, Cancel, OK

//Mixed objects in an array

var mixedList: String[] = ["India", 40.5, 3, false]

//Dictionaries

var comments = ["article1":4, "article2":6, "article3":0]

comments["article4"] = 5;

comments += ["article5":2, "article6":8]

Arrays and Dictionaries

Page 13: Developing iOS apps with Swift

//Arrays

typedList.insert("Later", atIndex:0) //typedList - Later, Yes...

typedList.removeAtIndex(0) //typedList - Yes, No...

typedList.append("Later") //typedList - Yes, No...Later

typedList.removeLast()

//Dictionaries

let numberOfComments = comments["article4"] //will be 5

Accessing Collections

Page 14: Developing iOS apps with Swift

//Functions return more than 1 values as tuples

let result = (404, "Not found")

let code = result.0 //will be 404

let status = result.1 //will be “Not found”

//Defining functions

func getStatus (var1:String, var2:String)->(Int, String)

//Calling function

var result:(code:Int, status:String) =

self.getStatus(var1: "googleegoo.com", var2: "http")

print("Result is \(result.code) - \(result.status)")

Tuples

Page 15: Developing iOS apps with Swift

//if statementsif val == 0 { //Some code here} else if val == 1 { //Some code here} else { //Some code here}

//switch casesswitch val { case 1, 3, 5: println ("odd"); case: 2, 4, 6: println ("even"); case: 7...9: println ("7, 8, 9"); default: println ("other");}

Conditions

Page 16: Developing iOS apps with Swift

Conditions

//switch with where clause and tuplesswitch rgb { ... case let (r,g,b) where r==g && g==b: println("GREY"); default: println ("colored");}

//while loopwhile !finished {//Some code here}

//for loop and for infor var i=0; i<10; i++ {//Some code here}for num in 1...10 {//iterate from 1 to 10}for num in 1..10 {//iterate from 1 to 9, not 10 - just 2 dots here}

Page 17: Developing iOS apps with Swift

Playground

Run a project without compiling

Run as you type (has its disadvantages)

Error symbols show as you type your code

Quick look button shows graphical display for a piece of code

Page 18: Developing iOS apps with Swift

There’s a lot more to Swift

Classes and structures, Protocols

Optional and non-optional parameters

Properties and methods

Getters and Setters

Property Observers

Closures

Page 19: Developing iOS apps with Swift

Designated and convenience initializers

Labeled statements

Lazy stored properties

Downcasting

Class methods

Extensions

There’s a lot more to Swift

Page 20: Developing iOS apps with Swift

Mapping Obj-C to Swift- changes to func

+ changes to class func

# define changes to let

#pragma changes to //MARK :

No init and initWith

Change complex macros to functions

let myCustomColor = UIColor(red:0.5,green:0.5,blue:0.0,alpha:1.0)

Page 21: Developing iOS apps with Swift

References

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/

http://www.raywenderlich.com/74438/swift-tutorial-a-quick-start

https://www.bloc.io/swiftris-build-your-first-ios-game-with-swift

Page 22: Developing iOS apps with Swift

What to get your iOS app developed with

Swift?Contact us for a FREE 15-minute consultation

http://newgenapps.com/contact/

Skype: lata.nga / newgenapps

Phone: +1 415 800 4445