CCRTViFormación en movilidad
Conceptos de desarrollo en iOS
1
LenguajeHerramientas
HerramientasDel simulador al dispositivo
2
iOS 6.1Xcode 4.6
3
Objective-C
@interface Video : NSObject
- (void)play;- (void)pause;
@end
@implementation Video
- (void)play {}
@end
4
Objective-C
@interface Video : NSObject
- (void)play;- (void)pause;
@end
@implementation Video
- (void)play {}
@end
Incomplete implementation
5
Objective-C
[myVideo play];[myVideo pause];
6
Objective-C
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Video pause]: unrecognized selector sent to instance 0x8334620'
[myVideo play];[myVideo pause]; Thread 1: signal SIGABRT
7
Objective-C
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Video pause]: unrecognized selector sent to instance 0x8334620'
[myVideo play];[myVideo pause]; Thread 1: signal SIGABRT
“un objeto puede enviar un mensaje sin temor a producir errores en tiempo de ejecución”
Wikipedia
8
Objective-C
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Video pause]: unrecognized selector sent to instance 0x8334620'
[myVideo play];[myVideo pause]; Thread 1: signal SIGABRT
“un objeto puede enviar un mensaje sin temor a producir errores en tiempo de ejecución”
No en la runtime library de iOS
9
Objective-C
10
Objective-CInitializers
Video *myVideo = [[Video alloc] init];// Es equivalente a:Video *myVideo = [Video new];
11
Objective-CInitializers
Video *myVideo = [[Video alloc] init];// Es equivalente a:Video *myVideo = [Video new];
Video *myVideo = [[Video alloc] initWithURL:theURL];
12
Objective-CInitializers
Video *myVideo = [[Video alloc] init];// Es equivalente a:Video *myVideo = [Video new];
NSString *theURL = @"http://youtu.be/THERgYM8gBM";Video *myVideo = [[Video alloc] initWithURL:theURL];
13
Objective-CInitializers
Video *myVideo = [[Video alloc] init];// Es equivalente a:Video *myVideo = [Video new];
NSString *theURL = @"http://youtu.be/THERgYM8gBM";Video *myVideo = [[Video alloc] initWithURL:theURL];
- (id)initWithURL:(NSString *)url {! self = [super init];! if(self) {! ! _url = url;! }! return self;}
14
Objective-CProperties
Declaración
@interface Video : NSObject
@property NSString *title;@property NSString *url;
@end
15
Objective-CProperties
Modificadores
@interface Video : NSObject
@property NSString *title;@property (readonly) NSString *url;
- (void)assignURL:(NSString *)url;
@end
16
Objective-CProperties
Modificadores
#import "Video.h"
@implementation Video
- (void)assignURL:(NSString *)url { // validaciones...! self.url = url;}
@end
17
Objective-CProperties
Modificadores
#import "Video.h"
@implementation Video
- (void)assignURL:(NSString *)url { // validaciones...! self.url = url;}
@end
Assignment to readonly property
18
Objective-CProperties
Extensiones
#import "Video.h"
@interface Video ()
@property (readwrite) NSString *url;
@end
@implementation Video
- (void)assignURL:(NSString *)url { // validaciones...! self.url = url;}
@end
19
Objective-CProperties
Modificadores cool
@interface Video : NSObject
@property (readonly) BOOL ready;
@end
if([myVideo ready]) {}
20
Objective-CProperties
Modificadores cool
@interface Video : NSObject
@property (readonly, getter = isReady) BOOL ready;
@end
if([myVideo isReady]) {}
21
Objective-CProperties
Atomicidad
@interface Video : NSObject
@property (nonatomic) NSObject *whatever;
@end
22
Objective-CProperties
strong & weak references
23
Objective-CProperties
strong & weak references
24
Objective-CProperties
strong & weak references
25
Objective-CProtocols
@protocol Playable
- (void)play;- (void)pause;
@optional
- (void)fastForward:(int)times;
@end
26
Objective-CProtocols
@interface Video : NSObject <Playable>@end
@implementation Video
#pragma mark - Playable
- (void)play {}
- (void)pause {}
- (void)fastForward:(int)times {}
@end
27
Objective-CProtocols
@interface PhotoSequence : NSObject <Playable>@end
@implementation PhotoSequence
#pragma mark - Playable
- (void)play {}
- (void)pause {}
@end
28
Objective-CProtocols
@interface PhotoSequence : NSObject <Playable>@end
@implementation PhotoSequence
#pragma mark - Playable
- (void)play {}
- (void)pause {}
@end
29
Objective-CBlocks
Tareas asíncronas
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{ // Long running task});
30
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{ // Long running task});
Objective-CBlocks
Tareas asíncronas
31
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{ // Long running task});
Objective-CBlocks
Tareas asíncronas
32
Xcode
33
XcodeCommand Line Tools
Instalación
34
RubyRuby Version Manager
Instalación$ export LANG=en_US.UTF-‐8
$ curl -‐L https://get.rvm.io | bash -‐s stable -‐-‐autolibs=3 -‐-‐ruby
$ rvm install 1.9.3
35
Coffee Break!
36
RubyRuby Version Manager
Instalación$ rvm use 1.9.3-‐p392
$ ruby -‐vruby 1.9.3p392 (2013-‐02-‐22 revision 39386) [x86_64-‐darwin12.3.0]
37
Ruby + XcodeCocoaPods
Instalación$ gem install cocoapods
$ pod setup...Setup completed (read-‐only access)
$ echo 'platform :ios' > Podfile
$ pod install...[!] From now on use `Workshop.xcworkspace`.
38
Xcode
⇧⌘N
Master-Detail Application
39
Xcode
Use Storyboards, Core Data, ARCand include Unit Tests
40
Xcode
Create local git repository for this project
try.github.com41
Xcode
42
XcodeSchemes & Targets
“An scheme defines a collection of targets to build, a configuration to use when building, and
a collection of tests to execute”
* Only one scheme can be active at a time
“A target specifies a product to build and contains the instructions for building the
product from a set of files in a project or workspace”
* A product can be an app or a static library
43
XcodeWorkspaces & Projects
“A workspace is a document that groups projects and other documents so you can
work on them together”* Workspaces provide implicit and explicit relationships among the
included projects and their targets
“A project is a repository for all the files, resources, and information required to build
one or more software products”
* Projects define default build settings for all their targets
44
XcodeRelación entre unidades de trabajo
Workspace
Project
Project
Target
Target
Target
Scheme
45
XcodePrimera ejecución
⌘R
46
XcodePrimera ejecución
App simulada
47
XcodePreparando para dispositivo
Firma del código
Code Signing Identity: Don’t Code Sign
48
XcodePreparando para dispositivo
Certificado de desarrollo
Request a Certificate From a Certificate Authority...
49
XcodePreparando para dispositivo
Certificado de desarrollo
Request is: Saved to disk50
XcodePreparando para dispositivo
Certificado de desarrollo
51
XcodePreparando para dispositivo
Certificado de desarrollo
52
XcodePreparando para dispositivo
Certificado de desarrollo
CER (certificado)+ CSR (clave privada)
P12 (PKCS#12)53
XcodePreparando para dispositivo
Certificado de desarrollo
CER (certificado)+ CSR (clave privada)
P12 (PKCS#12)54
XcodePreparando para dispositivo
Certificado de desarrollo
Certificado y clave privada
55
XcodePreparando para dispositivo
Certificado de desarrollo
File Format: Personal Information Exchange (.p12)
56
XcodePreparando para dispositivo
Certificado de desarrollo
57
XcodeGit
58
Próxima sesión...
59