Obj-C and iOS for .NET Developers

Post on 14-Jun-2015

7.498 views 5 download

Tags:

Transcript of Obj-C and iOS for .NET Developers

OBJECTIVE-C AND IOSFOR .NET DEVELOPERS

EDUARDO SCOZ

CHICAGO ALT.NET

SEPT 2011

ME

• Software Architect at

• .NET Developer for 5-6 years

• iOS Developer for the last 2 years

• Obj-C exclusively for 4 months

• http://escoz.com

• http://twitter.com/escoz

IOS DEV 101

What you need:

• A Mac• Register with Apple Dev Center - $100.00• Download XCode 4 (or beta) • Time and patience

Demo

SO, WHAT IS IT LIKE?

AFTER 6 MONTHS

IOS LIBRARIES ARE GREAT

• CocoaTouch works really well

• Really productive

• Easy to make good stuff fast

• NS objects get a while to get used to

• C functions are necessary every once in a while, which is strange, but not the end of the world

OBJ-C IS UGLY BUT ACCEPTABLE

• You’ll be missing features all the time

• Old language, learn to accept it

• Brackets everywhere

• You’ll go crazy for a few weeks• Once you’re over it, development is just like C#• C code in between is messy

XCODE JUST SUCKS

• Crash Fest

• IDE Helps you very little

• poor code navigation• poor refactoring

• Good to manage project, NIBs and CoreData mappings

• Great performance tool: Instruments

JETBRAINS APPCODE

Beautiful code development

• Doesn’t do everything, but it’s great at what it does

If you’re used to Resharper, you’ll feel at home

Still in beta, so buggy at times

• http://www.jetbrains.com/objc/

OBJ-CCreated in the early 80's, by StepStone

• Adds Smalltalk-like messaging to C

Steve Jobs/NeXT in 88

• added Obj-C compiler support to GCC in 88• uses it to create NeXTStep

Apple acquires NeXT in '96 and builds OSX

OBJECT ORIENTED

Just like C#

• Classes, Objects, Constructors• Class methods, instance methods

• No private methods, no class variables

• Brackets, brackets, brackets!

• Alloc/init vs Constructors

• “id” is a pointer to any Obj-C object

Demo

DYNAMIC LANGUAGE

Pointers always used to pass objects around.

Types is used to assist compiler/tools

Message Passing, not method invocation

• Think of every object as a Dictionary of methods• Extremely simple Reflection• Slower than C++, but still really fast

Messages can be executed in a different thread

Messages can be forwarded to other objects

Method swizzling – change implementations at runtime

MORE FEATURES

Categories == Extension methods

Protocols == kind of like interfaces

• @optional and @required

Properties

• every class becomes a dictionary• Convention allows dot notation - KVC

Blocks == lambda expressions

NSPredicates ~= LINQ, but ugly

MORE FEATURES

Key Value Coding

• Allows simple dot notation for properties:

• -(id) valueForUndefinedKey:(NSString *)key {}

KEY VALUE OBSERVING

Every object contains an observer pattern

MEMORY MANAGEMENT

GC, but only in OSX

Manual reference counting

• [obj retain]• [obj release]• [obj autorelease] - autorelease pools

ARC - Automatic Reference Counting

• Solution for GC envy• smart compiler can do exactly what you would do

manually• __block, __weak, __strong

COCOA TOUCH

Based on OSX Cocoa, but not the same

Frameworks to allow apps to run on iOS:

• UIKit, CoreAnimation, OpenAL, MediaLibrary• CoreAudio, Quartz2D, OpenGL, Address Book• Core Location, MapKit, StoreKit, Bonjour, WebKit• BSD Sockets, AV Foundation

UIKIT

Pretty much anything related to the screen:

• Displaying pixels• Handling user input• High level components, like tables, entry fields etc• Orientation, rotation

MVC-based framework to deal with UI

Demo

NIBs - WYSIWYG Editor

Demo

CORE DATA

Apple’s ORM

Managed object graph that can be persisted

• SQLite only for iOS4, Json for new versions

Manages object model versioning

Localization of names and properties

Demo

NOTES

XCode sucks

• Be prepared for a life of frustration• Use AppCode

ObjC is not bad, get used to it

iOS Frameworks are great

• They’re not simple, but they work really well

RESOURCES

http://developer.apple.com

• Apple developer Forums• irc.freenode.com #iPhoneDev

https://github.com/languages/Objective-C/most_watched

• Facebook three20• JSONKit• RestKit - great way of accessing RESTful services• QuickDialog – mine

THANKS!

Eduardo Scozescoz@redpointtech.com

http://escoz.com

http://twitter.com/escoz