CS4720
Xcode andSwift
CS4720– MobileApplicationDevelopment
CS4720
WhyJavaforAndroid?• Let’sfirstrecap:whydoyouthinkAndroidusesJava?
2
CS4720
WhyJavaforAndroid?• Somegoodreasons:
– Youcan’tfindaCSmajorthatdoesn’tknowJava– Java’srelativelyeasytopickup– CoderunsinaVM,whichmeansyoudon’thavetorecompileforeverydifferentphoneplatform
– Tonsoftoolsandsupport– Javamanagespointersandgarbagecollectionautomatically,solesslikelytogetintrouble
– JavaMEalreadyathingformobile
3
CS4720
HistoryofAppleDevelopment• ToappreciatewhereiOSdevelopmentcamefrom,weneedtolookbackathowdevelopingforAppleplatformsbecamewhatitis
• AndthatstorybeginswithSmalltalk
4
CS4720
Smalltalk• Createdinthe1970satXeroxPARC• Originallybuiltforeducationalpurposes• SmalltalkisbasicallyTHEancestorforobject-orienteddevelopment
• ManyoftheOOpatternsweknow(likeMVC)startedwithSmalltalk
• MajorinfluenceinAgile,GUIs,andIDEs
5
CS4720
Smalltalk• Yes,attheheartofSmalltalkisobjects(everythingisanobject)
• Buttherealtakeawayismessaging• Methodcallsareeffectivelymessageswithanswers
6
CS4720
Smalltalk42 factorial
2 raisedTo: 4
‘hello world’ indexOf: $o startingAt: 6
Rectangle width: 100 height: 200
3 + 4
3 > 4
7
CS4720
Objective-C• Inthe1980s,workonObjective-Cbeganatatelecomcompany,ITT
• ThethoughtwasOOwasthefuture(andSmalltalkwastheblueprint)butbackwardscompatibilitywithClegacysystemswasimportant
• ThemaindescriptionofObjective-Cwaspublishedin1986
8
CS4720
Objective-C• In1988,NeXTlicensedObjective-CandbeganworktoextendtheGCCcompiler
• NeXTbuiltfoundationaltoolsforbuildinggooduserinterfaces
• NeXTcomputersneverreallytookoff…• …butbasicallyeveryonethoughtthetoolsetswerereallygreat
• So,NeXTstartedfocusingonsoftware
9
CS4720
NeXTSTEP
10
CS4720
Objective-C• Oh,bytheway…• NeXTwasfoundedbySteveJobsafterhewasforcedoutofAppleinthelate1980s…
• NeXTwaspurchasedinfullbyApplein1997• JobstookoverasCEOofthecombinedcompanyatthesametime
• Jobscannedseveralsmallerprojects(liketheNewton)
11
CS4720
Objective-C• However,onemajorprojecthadstalledout• Thecreationofthe“nextgeneration”MacOS• WiththepurchaseofNeXT…• …andtheUnixunderpinningsofNeXTSTEP…• …builtusingObjective-C…• CocoaandOSXwereborn!
12
CS4720
Cocoa• CocoaisthenativeOOAPIforOSX• BuiltusingObjective-C• CocoaappswerecreatedusingProjectBuilderandInterfaceBuilder– ToolsoriginallycreatedfortheNeXTSTEP system
• Cocoaisimportantinthatit“forces”applicationstoadheretoAppleUIguidelines
• ProjectBuilder+InterfaceBuilder=Xcode
13
CS4720
CocoaTouch• WiththecreationofiOS,cameCocoaTouch• StillObjective-C• StillMVC• StillUnix-basedunderneathitall• So,Objective-CbecamethedefaultlanguageforbuildingforiOS
• Until…
14
CS4720
Swift• IntroducedatWWDC2014as“Objective-CwithouttheC”
• MeanttoaddressmemoryandtypesafetyissuespresentinObjective-C
• Switchesthemessage-passingsyntaxofObjective-CforthemorecommondotnotationfoundinJava,etc.
• BuildsinmanyoftheoldstandardAppledatatypes(likeNSString)
15
CS4720
Swift• Thelanguageitselflooksmuchmore“Java-like”withmanykeywordscarriedover
• Semicolonsnotrequiredthough• Ingeneral,shouldn’ttaketoolongforaJavaprogrammertopickup
• UsesObjective-Cruntime,soitcanimportanyObjective-Clibraries
• Swift2.0releasedSeptember16,2015• OpensourcedonDecember3,2015
16
CS4720
Wheredoesthisleaveus?• Youdon’tHAVEtodevelopiOSappsusingObjective-CorSwift
• However,thatisthewaytodonativedevelopment(yes,youcanKINDAdothiswithsomethirdpartytools…)
• Asofnow,tobuildiOSappsusingObjective-CorSwift,youneedtouseXcode
• TouseXcode,youneedaMac…
17
CS4720
DevelopingwithXcode• Ifyoudon’townaMac• MacMinisinRice340• Unixloginsshouldwork• Checktoseeifyoucanswipein• Anotheroptionishttp://www.macincloud.com/
18
CS4720
Xcode andSwift• Thingstocover:
– Simulatorsvs.Emulators– HowtohookuptoGithub– UsingtheInterfaceBuildertoconnectcodetoUIobjects
19