Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without...

19
CS 4720 Xcode and Swift CS 4720 – Mobile Application Development

Transcript of Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without...

Page 1: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Xcode andSwift

CS4720– MobileApplicationDevelopment

Page 2: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

WhyJavaforAndroid?• Let’sfirstrecap:whydoyouthinkAndroidusesJava?

2

Page 3: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

WhyJavaforAndroid?• Somegoodreasons:

– Youcan’tfindaCSmajorthatdoesn’tknowJava– Java’srelativelyeasytopickup– CoderunsinaVM,whichmeansyoudon’thavetorecompileforeverydifferentphoneplatform

– Tonsoftoolsandsupport– Javamanagespointersandgarbagecollectionautomatically,solesslikelytogetintrouble

– JavaMEalreadyathingformobile

3

Page 4: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

HistoryofAppleDevelopment• ToappreciatewhereiOSdevelopmentcamefrom,weneedtolookbackathowdevelopingforAppleplatformsbecamewhatitis

• AndthatstorybeginswithSmalltalk

4

Page 5: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Smalltalk• Createdinthe1970satXeroxPARC• Originallybuiltforeducationalpurposes• SmalltalkisbasicallyTHEancestorforobject-orienteddevelopment

• ManyoftheOOpatternsweknow(likeMVC)startedwithSmalltalk

• MajorinfluenceinAgile,GUIs,andIDEs

5

Page 6: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Smalltalk• Yes,attheheartofSmalltalkisobjects(everythingisanobject)

• Buttherealtakeawayismessaging• Methodcallsareeffectivelymessageswithanswers

6

Page 7: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Smalltalk42 factorial

2 raisedTo: 4

‘hello world’ indexOf: $o startingAt: 6

Rectangle width: 100 height: 200

3 + 4

3 > 4

7

Page 8: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Objective-C• Inthe1980s,workonObjective-Cbeganatatelecomcompany,ITT

• ThethoughtwasOOwasthefuture(andSmalltalkwastheblueprint)butbackwardscompatibilitywithClegacysystemswasimportant

• ThemaindescriptionofObjective-Cwaspublishedin1986

8

Page 9: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Objective-C• In1988,NeXTlicensedObjective-CandbeganworktoextendtheGCCcompiler

• NeXTbuiltfoundationaltoolsforbuildinggooduserinterfaces

• NeXTcomputersneverreallytookoff…• …butbasicallyeveryonethoughtthetoolsetswerereallygreat

• So,NeXTstartedfocusingonsoftware

9

Page 10: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

NeXTSTEP

10

Page 11: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Objective-C• Oh,bytheway…• NeXTwasfoundedbySteveJobsafterhewasforcedoutofAppleinthelate1980s…

• NeXTwaspurchasedinfullbyApplein1997• JobstookoverasCEOofthecombinedcompanyatthesametime

• Jobscannedseveralsmallerprojects(liketheNewton)

11

Page 12: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Objective-C• However,onemajorprojecthadstalledout• Thecreationofthe“nextgeneration”MacOS• WiththepurchaseofNeXT…• …andtheUnixunderpinningsofNeXTSTEP…• …builtusingObjective-C…• CocoaandOSXwereborn!

12

Page 13: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Cocoa• CocoaisthenativeOOAPIforOSX• BuiltusingObjective-C• CocoaappswerecreatedusingProjectBuilderandInterfaceBuilder– ToolsoriginallycreatedfortheNeXTSTEP system

• Cocoaisimportantinthatit“forces”applicationstoadheretoAppleUIguidelines

• ProjectBuilder+InterfaceBuilder=Xcode

13

Page 14: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

CocoaTouch• WiththecreationofiOS,cameCocoaTouch• StillObjective-C• StillMVC• StillUnix-basedunderneathitall• So,Objective-CbecamethedefaultlanguageforbuildingforiOS

• Until…

14

Page 15: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Swift• IntroducedatWWDC2014as“Objective-CwithouttheC”

• MeanttoaddressmemoryandtypesafetyissuespresentinObjective-C

• Switchesthemessage-passingsyntaxofObjective-CforthemorecommondotnotationfoundinJava,etc.

• BuildsinmanyoftheoldstandardAppledatatypes(likeNSString)

15

Page 16: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Swift• Thelanguageitselflooksmuchmore“Java-like”withmanykeywordscarriedover

• Semicolonsnotrequiredthough• Ingeneral,shouldn’ttaketoolongforaJavaprogrammertopickup

• UsesObjective-Cruntime,soitcanimportanyObjective-Clibraries

• Swift2.0releasedSeptember16,2015• OpensourcedonDecember3,2015

16

Page 17: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Wheredoesthisleaveus?• Youdon’tHAVEtodevelopiOSappsusingObjective-CorSwift

• However,thatisthewaytodonativedevelopment(yes,youcanKINDAdothiswithsomethirdpartytools…)

• Asofnow,tobuildiOSappsusingObjective-CorSwift,youneedtouseXcode

• TouseXcode,youneedaMac…

17

Page 18: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

DevelopingwithXcode• Ifyoudon’townaMac• MacMinisinRice340• Unixloginsshouldwork• Checktoseeifyoucanswipein• Anotheroptionishttp://www.macincloud.com/

18

Page 19: Xcodeand Swift - cs4720.cs.virginia.edu · • Introduced at WWDC 2014 as “Objective-C without the C” • Meant to address memory and type safety issues present in Objective-C

CS4720

Xcode andSwift• Thingstocover:

– Simulatorsvs.Emulators– HowtohookuptoGithub– UsingtheInterfaceBuildertoconnectcodetoUIobjects

19