Transcript
Page 1: C# On The iPhone with MonoTouch at DDD8

C# on the iPhonewith MonoTouch

Chris Hardyfollow on Twitter - @chrisntr

Page 2: C# On The iPhone with MonoTouch at DDD8

http://greatfridays.com

Page 3: C# On The iPhone with MonoTouch at DDD8

Covering...

• What is MonoTouch?

• How does it work?

• Why would you use it?

• Demos

Page 4: C# On The iPhone with MonoTouch at DDD8

Starting point....

Page 5: C# On The iPhone with MonoTouch at DDD8

Objective C and Xcode

Page 6: C# On The iPhone with MonoTouch at DDD8

Learn to read Objective-C

Page 7: C# On The iPhone with MonoTouch at DDD8

Learn to read Objective-C

• All Apple documentation is in Obj-C

• Most examples are in Obj-C

• It’s not too hard to understand

• It might even be fun...

Page 8: C# On The iPhone with MonoTouch at DDD8

What is MonoTouch?

Page 9: C# On The iPhone with MonoTouch at DDD8

What is Mono?

Page 10: C# On The iPhone with MonoTouch at DDD8

What is Mono?

Open Source .Net Implementation of the

Microsoft .Net Framework

Page 11: C# On The iPhone with MonoTouch at DDD8

Mono’s JIT Engine

CIL

Mono

Memory

Page 12: C# On The iPhone with MonoTouch at DDD8

Apple No No...

• Contractual Requirements

• No interpreted code

• No shared libraries

• Kernel Limitations

• iPhone OS 2.0+ disables JIT

Page 13: C# On The iPhone with MonoTouch at DDD8

Mono’s AOT Engine

CIL

Mono

AOTMono Runtime

ARM

Native Code

Page 14: C# On The iPhone with MonoTouch at DDD8

Monotouch Features• mtouch• MonoDevelop iPhone Add-In• CocoaTouch.NET• Full static AOT compiler• Support for all your existing code• Reflection• Generics• LINQ• Anonymous Methods• Lambda’s etc...

Page 15: C# On The iPhone with MonoTouch at DDD8

MonoTouch’s APIs

Page 16: C# On The iPhone with MonoTouch at DDD8

The Bindings• MonoTouch namespace

• MonoTouch.Foo namespace

• Maps to CocoaTouch’s Foo Framework

• 1:1 Mapping of classes.

• MonoTouch.UIKit.UILabel

• CocoaTouch’s UIKit framework, UILabel class

Page 17: C# On The iPhone with MonoTouch at DDD8

Strong Types

• Objective-C

• Arrays are weakly typed:• NSArray return values.

• MonoTouch has strong types

• UIView[] Subviews { get; }• vs• NSArray *subviews;

• Intellisense - explore the API...

Page 18: C# On The iPhone with MonoTouch at DDD8

Garbage Collection• Automatic:

• Mono’s GC will collect objects on demand

• Deterministic:

• Use when you need control.

• Every object in MonoTouch implements IDisposable

using (var image = UIImage.FromFile(“foo.png”)){

surface.DrawImage(image, 20, 20);

}

Page 19: C# On The iPhone with MonoTouch at DDD8

Linker

Page 20: C# On The iPhone with MonoTouch at DDD8

What about App Size?

• 10 MB (compressed) limit on 3G/Edge downloads

• .Net BCL and other libraries are huge

• Mono Linker to the rescue!

Page 21: C# On The iPhone with MonoTouch at DDD8

Linking Assemblies

Page 22: C# On The iPhone with MonoTouch at DDD8

Linker Options

• No Link

• Link SDK Only

• Full Link

Page 23: C# On The iPhone with MonoTouch at DDD8

Pipeline

• Interface Builder GUI Designer

• Exact same tool used by Xcode

• Support for existing Xcode interfaces

• MonoDevelop IDE

Page 24: C# On The iPhone with MonoTouch at DDD8

Integration

• Tight integration between MD and IB

• IB produces XIBs with MD parses

• Automatic class generation in MD

• Generates partial classes for all types, outlets and actions defined in Interface Builder

Page 25: C# On The iPhone with MonoTouch at DDD8

Outlets

• Instance Variables

• Can be strong or loosely typed

• MD will strong type

Page 26: C# On The iPhone with MonoTouch at DDD8

Actions

• Objects emit broadcast messages to receivers

• You can do this C#

• MonoDevelop takes care of the details for you

• Creates partial methods for you extend

Page 27: C# On The iPhone with MonoTouch at DDD8

MonoTouch Events

• Supports Objective-C pattern:

webView.Delegate = new MyWebViewDelegate();

• C# style events as well:

webView.PageLoaded += delegate {HideSpinningWheel();

}

Page 28: C# On The iPhone with MonoTouch at DDD8

Debugging

• Console.WriteLine(“Debugging inside of MonoTouch”);

• printf(“I made it to this line!\n”)

Page 29: C# On The iPhone with MonoTouch at DDD8

Well...

• MonoTouch released around 15th September 2009

• MonoTouch 1.1 on 2nd October 2009

• MonoTouch 1.2 (Beta) released on 28th October 2009... With Debugging support

• Currently on MonoTouch 1.4.5

Page 30: C# On The iPhone with MonoTouch at DDD8

Debugger

• MonoTouch debugger leverages Mono’s new Soft-Debugger

• Supports the Simulator

• Supports the Device...

• even over WiFi

Page 31: C# On The iPhone with MonoTouch at DDD8

Debugger Features• Breakpoints

• Catchpoints

• Inspection

• Watches

• Immediate / Expression Evaluator

• Call Stack

• Stepping

Page 32: C# On The iPhone with MonoTouch at DDD8

Caveats

• Debug binaries on devices are very large

• Cannot debug Main or FinishedLaunching on device

• Consumes more memory runtime

• Performance hit

Page 33: C# On The iPhone with MonoTouch at DDD8

Getting started

• Get iPhone SDK from Apple

• Get Mono from Novell

• Get MonoTouch (evaluation version is free)

• Get MonoDevelop

• Register with Apple iPhone Developer Program and purchase MonoTouch for putting apps on device and AppStore.

Page 34: C# On The iPhone with MonoTouch at DDD8

One more thing...

Page 35: C# On The iPhone with MonoTouch at DDD8

iPad

• But you want to develop for the iPad...

• 24 Hours after the SDK was released...

• MonoTouch support for iPad

Page 36: C# On The iPhone with MonoTouch at DDD8

Demo time...


Top Related