Developing iOS apps with Swift

Download Developing iOS apps with Swift

Post on 15-Jan-2015

3.174 views

Category:

Mobile

4 download

Embed Size (px)

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

  • 1. SwiftProgramming inDevelopinigO AppSs using Swift

2. iOS 8- NewFeaturesApp Extensions - for sharing, photo editing, storage,custom keyboards (yay!) and much moreTouch ID - forget registration and login, Touch IDauthentication is hereGames - many improvements to SpriteKit, SceneKit,OpenGL and a new framework Metal - for highperformance in gamesHealth Kit - a new framework for managing health-relatedinfo. Make way for revolutionary health apps 3. iOS 8- NewFeaturesHome Kit - communicate with connected devices(you dont need to go to the switch now)Handoff - seamless continuity of activities acrossdevicesPhotos - there is so much more you can do withPhotos now And much moreSharing documents between appsMore inclusive notificationsBetter search 4. Why Swift? 5. What Apple saysFast - performance wise, Swift is much faster thanObjective-CModern - borrows from Haskell, Ruby, Javascript -skill barrier greatly loweredInteractive - a Playground allows programmers toexperiment with Swift code and see resultsimmediately - no building and running 6. What developers sayThe announcement of Swift got mixedreactions 7. Show me the code! 8. Some key pointsDeclaration and implementation are in the same file(no .h and .m files)Project size is largely reduced with SwiftSwift auto-detects data typesThe code does not use semi-colonsBraces are compulsory for if-else conditions 9. Variables (and typeinference)//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 10. Constants//constantslet name: String = "Jane Doe"let year: Int = 2014let isFast: Bool = true//These will give an errorname = "John Doe"year = 2016isFast = false 11. String Operationslet hello = "Hello"let world = "World"let firstString = hello + " " + world //Will print Hello Worldlet a = 4, b = 5println ("(a) * (b) = (a * b)") //Will print 4 * 5 = 20isFast = false 12. Arrays and Dictionaries//Typed arraysvar typedList: String[] = ["Yes", "No", "Cancel"]typedList += ["OK"] //typedList - Yes, No, Cancel, OK//Mixed objects in an arrayvar mixedList: String[] = ["India", 40.5, 3, false]//Dictionariesvar comments = ["article1":4, "article2":6, "article3":0]comments["article4"] = 5;comments += ["article5":2, "article6":8] 13. Accessing Collections//ArraystypedList.insert("Later", atIndex:0) //typedList - Later, Yes...typedList.removeAtIndex(0) //typedList - Yes, No...typedList.append("Later") //typedList - Yes, No...LatertypedList.removeLast()//Dictionarieslet numberOfComments = comments["article4"] //will be 5 14. Tuples//Functions return more than 1 values as tupleslet result = (404, "Not found")let code = result.0 //will be 404let status = result.1 //will be Not found//Defining functionsfunc getStatus (var1:String, var2:String)->(Int, String)//Calling functionvar result:(code:Int, status:String) =self.getStatus(var1: "googleegoo.com", var2: "http")print("Result is (result.code) - (result.status)") 15. //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 16. 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