Getting started with Xcode

47
Computer Science Large Practical: Programming with Xcode Stephen Gilmore School of Informatics Friday 19th October, 2012 Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 1 / 47

description

Installing Xcode and writing your first simple program. Shows the usefulness of static analysis.

Transcript of Getting started with Xcode

Page 1: Getting started with Xcode

Computer Science Large Practical:

Programming with Xcode

Stephen Gilmore

School of Informatics

Friday 19th October, 2012

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 1 / 47

Page 2: Getting started with Xcode

News

There will be no CSLP lecture next week. The next CSLP lecture willbe on Friday 2nd November.

As of Tuesday, Xcode is now available on all the Open Access LabApple Macs in the Main Library in George Square.

If you are developing on the Macs in the library you do not need toinstall Xcode.We see first how to install Xcode if you are working on your (Mac)laptop.

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 2 / 47

Page 3: Getting started with Xcode

Xcode is available from the App Store

shot 2012-10-18 at 10.00.38.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 3 / 47

Page 4: Getting started with Xcode

Click to install

shot 2012-10-18 at 10.00.49.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 4 / 47

Page 5: Getting started with Xcode

Supply your Apple ID password

shot 2012-10-18 at 10.01.00.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 5 / 47

Page 6: Getting started with Xcode

The button will change to “Installing”

shot 2012-10-18 at 10.01.22.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 6 / 47

Page 7: Getting started with Xcode

Foo

shot 2012-10-18 at 10.06.58.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 7 / 47

Page 8: Getting started with Xcode

Accept the License Agreement

shot 2012-10-18 at 10.07.19.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 8 / 47

Page 9: Getting started with Xcode

Some components may be updated

shot 2012-10-18 at 10.07.28.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 9 / 47

Page 10: Getting started with Xcode

Requires system permission

shot 2012-10-18 at 10.07.36.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 10 / 47

Page 11: Getting started with Xcode

Installing ...

shot 2012-10-18 at 10.07.53.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 11 / 47

Page 12: Getting started with Xcode

Installing ...

shot 2012-10-18 at 10.08.03.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 12 / 47

Page 13: Getting started with Xcode

Installation complete

shot 2012-10-18 at 10.08.27.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 13 / 47

Page 14: Getting started with Xcode

Welcome screen

shot 2012-10-18 at 10.08.37.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 14 / 47

Page 15: Getting started with Xcode

Create a new project

shot 2012-10-18 at 10.08.53.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 15 / 47

Page 16: Getting started with Xcode

Many options, including iOS projects

shot 2012-10-18 at 10.09.04.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 16 / 47

Page 17: Getting started with Xcode

Choose an OS X application

shot 2012-10-18 at 10.09.26.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 17 / 47

Page 18: Getting started with Xcode

Choose a command-line tool

shot 2012-10-18 at 10.09.32.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 18 / 47

Page 19: Getting started with Xcode

Choose options

shot 2012-10-18 at 10.09.49.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 19 / 47

Page 20: Getting started with Xcode

Choose options

shot 2012-10-18 at 10.10.16.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 20 / 47

Page 21: Getting started with Xcode

Choose Foundation for Objective-C

shot 2012-10-18 at 10.10.24.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 21 / 47

Page 22: Getting started with Xcode

Can choose to create a git repository

shot 2012-10-18 at 10.10.52.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 22 / 47

Page 23: Getting started with Xcode

Project main screen

shot 2012-10-18 at 10.11.36.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 23 / 47

Page 24: Getting started with Xcode

Project has sample “Hello World” code

shot 2012-10-18 at 10.13.15.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 24 / 47

Page 25: Getting started with Xcode

Autocompletion suggests options

shot 2012-10-18 at 10.19.09.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 25 / 47

Page 26: Getting started with Xcode

Autocompletion suggests options

shot 2012-10-18 at 10.19.33.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 26 / 47

Page 27: Getting started with Xcode

Autocompletion suggests options

shot 2012-10-18 at 10.19.42.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 27 / 47

Page 28: Getting started with Xcode

Static analysis warns about code problems

shot 2012-10-18 at 10.20.48.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 28 / 47

Page 29: Getting started with Xcode

Autocompletion works on literals too

shot 2012-10-18 at 10.21.03.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 29 / 47

Page 30: Getting started with Xcode

Deliberately seeding a bug, overwriting a needed value

shot 2012-10-18 at 10.23.43.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 30 / 47

Page 31: Getting started with Xcode

Static analysis warns about format string errors

shot 2012-10-18 at 10.23.43.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 31 / 47

Page 32: Getting started with Xcode

Fixing the format string error

shot 2012-10-18 at 10.23.51.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 32 / 47

Page 33: Getting started with Xcode

Running the code (first time)

shot 2012-10-18 at 10.24.10.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 33 / 47

Page 34: Getting started with Xcode

Requires authentication

shot 2012-10-18 at 10.24.21.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 34 / 47

Page 35: Getting started with Xcode

Build succeeded

shot 2012-10-18 at 10.24.34.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 35 / 47

Page 36: Getting started with Xcode

Output in console

shot 2012-10-18 at 10.24.48.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 36 / 47

Page 37: Getting started with Xcode

Using static analysis to find errors (choose Analyze)

shot 2012-10-18 at 10.25.13.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 37 / 47

Page 38: Getting started with Xcode

Errors detected: value stored to ‘s’ is never read

shot 2012-10-18 at 10.25.22.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 38 / 47

Page 39: Getting started with Xcode

Xcode decides to download libraries

shot 2012-10-18 at 10.27.33.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 39 / 47

Page 40: Getting started with Xcode

Xcode decides to download libraries

shot 2012-10-18 at 10.28.04.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 40 / 47

Page 41: Getting started with Xcode

Decide to initialise string

shot 2012-10-18 at 10.29.38.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 41 / 47

Page 42: Getting started with Xcode

Looking for appropriate init method

shot 2012-10-18 at 10.30.10.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 42 / 47

Page 43: Getting started with Xcode

Looking for appropriate init method (initWithString: ?)

shot 2012-10-18 at 10.30.18.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 43 / 47

Page 44: Getting started with Xcode

Using “initWithString:” with a literal is redundant

shot 2012-10-18 at 10.31.17.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 44 / 47

Page 45: Getting started with Xcode

Checking documentation

shot 2012-10-18 at 10.32.14.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 45 / 47

Page 46: Getting started with Xcode

Code compiles without warnings — even with Analyze

shot 2012-10-18 at 10.34.39.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 46 / 47

Page 47: Getting started with Xcode

Produces expected result

shot 2012-10-18 at 10.35.20.png

Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 19th October, 2012 47 / 47