Upload
sasha-goldshtein
View
3.649
Download
3
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
First Steps in iOS Development
Sasha Goldshtein
CTO, Sela Group
@goldshtn blog.sashag.net
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
The iOS Platform
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
Platform Philosophy
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
iOS Devices and VersionsSeptember 2013:
≈95% of iOS devices run iOS 6
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
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
Developing for iOS
self.title = [NSString initWithFormat:@"%d", n];[button setTitle:self.title forState:UIControlStateNormal];
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
Objective C Classes
• Declare in .h file, implement in .m file– @interface and @implementation keywords
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
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
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
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];}
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
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
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
DEMOOur first iOS app
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
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
iOS MVC Fundamentals
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
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
DEMOConnecting UI to code
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
iOS Navigation Types
• Tab bar controller
• Navigation controller
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
Storyboards
• The storyboard describes your application’s view controllers and connects them with segues
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
Types of Segues
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}
Join the conversation on Twitter: @SoftArchConf #SoftArchConf
DEMOStoryboards and segues
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, …
Thank You!
Sasha Goldshtein
CTO, Sela Group
@goldshtn blog.sashag.net