25
First Steps in iOS Development Sasha Goldshtein CTO, Sela Group @goldshtn blog.sashag.net

First Steps in iOS Development

Embed Size (px)

DESCRIPTION

Have you always been interested in iOS development but never took the plunge and installed the dev tools? In this presentation we look at the basic steps of iOS application development, and then move on to slightly more advanced features like storyboards and segues (introduced with iOS 5).

Citation preview

Page 1: First Steps in iOS Development

First Steps in iOS Development

Sasha Goldshtein

CTO, Sela Group

@goldshtn blog.sashag.net

Page 2: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

The iOS Platform

Page 3: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Platform Philosophy

Page 4: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

iOS Devices and VersionsSeptember 2013:

≈95% of iOS devices run iOS 6

Page 5: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Devices and Resolutions

Don’t worry about Retina: all you need to do is provide 2x images for your graphical assets

Don’t worry about iPhone 5: most views will resize correctly with AutoLayout or require minimal tweaks

Page 6: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Developing for iOS

self.title = [NSString initWithFormat:@"%d", n];[button setTitle:self.title forState:UIControlStateNormal];

Page 7: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Objective C Classes

• Declare in .h file, implement in .m file– @interface and @implementation keywords

Page 8: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Methods

@interface Cat : NSObject- (void)meow;- (BOOL)doesLikeOtherCat:(Cat *)other;- (int)age;@end

@implementation Cat- (void)meow { NSLog(@"Meow"); }- (int)age { return 7; }- (BOOL)doesLikeOtherCat:(Cat *)other { if ([self age] <= [other age]) return YES; return NO;}@end

Q: What about nil checks?!A: Messages sent to nil return 0/nil/NO

Page 9: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Initializers

@interface Cat : Mammal { int age_; // This is a public instance field}- (id)initWithAge:(int)age;@end

@implementation Cat- (id)initWithAge:(int)age { self = [super init]; if (self) age_ = age; return self;}@end

Page 10: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Properties

@interface Cat : NSObject@property (nonatomic) int age;- (id)initWithAge:(int)age;@end

@implementation Cat

- (id)initWithAge:(int)age { if (self = [super init]) _age = age; // Auto-generated field! return self;}

@end

Page 11: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Using Objects

Cat *felix = [[Cat alloc] initWithAge:5];Cat *shadow = [[Cat alloc] initWithAge:4];

if ([felix likesOtherCat:shadow]) { // Left to your imagination}

NSDate *today = [NSDate date]; // Current dateif ([Calendar isBirthday:shadow onDate:today]) { shadow.age++; [shadow meow];}

Page 12: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Memory Management: ARC

• Heap objects are reference counted– Support release, retain, retainCount

messages

• Automatic Reference Counting (ARC) takes care of memory management– The compiler embeds the appropriate

reference counting messages automatically– Introduced in iOS 4 with LLVM compiler– With one caveat: reference cycles

Page 13: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Basic Foundation Classes

• Strings– Immutable/mutable, @"foo" syntax

• Arrays– May contain any object type (NSObject)– Immutable/mutable, @[a, b, c] syntax

• Dictionaries– Keys are usually strings, but don’t have to be– Immutable/mutable, @{ a : b } syntax

Page 14: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

DEMOOur first iOS app

Page 15: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Project Components• Generated files:

– Application delegate– Initial view controller– Main storyboard– Property list– File for localizable strings– Application icons

• Xcode also adds basic frameworks to your app

Page 16: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

iOS MVC Fundamentals

Page 17: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Outlets and Actions

• Xcode connects views and controllers– Controller manipulates views through outlets– Controller receives events through actions

@interface MyViewController : UIViewController

@property (nonatomic, weak) IBOutlet UITextField *petName;- (IBAction)getQuote;

@end

Page 18: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

DEMOConnecting UI to code

Page 19: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

iOS Navigation Types

• Tab bar controller

• Navigation controller

Page 20: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Storyboards

• The storyboard describes your application’s view controllers and connects them with segues

Page 21: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Types of Segues

Page 22: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Passing Parameters

• Usually the source view controller sets properties or calls methods on the destination view controller

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ MySecondVC *vc = segue.destinationViewController; vc.itemToDisplay = [self selectedItem]; vc.delegate = self; // For callbacks}

Page 23: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

DEMOStoryboards and segues

Page 24: First Steps in iOS Development

Join the conversation on Twitter: @SoftArchConf #SoftArchConf

Summary

• It’s just another{language, IDE, UI framework}

• The rest is just details: data, networking, settings, table views, styling, …

Page 25: First Steps in iOS Development

Thank You!

Sasha Goldshtein

CTO, Sela Group

@goldshtn blog.sashag.net