CCRTVi
Formación en movilidad
Conceptos de desarrollo en iOS
1
Lenguaje
Herramientas
Herramientas
Del simulador al dispositivo
2
iOS 6.1
Xcode 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-C
Initializers
Video *myVideo = [[Video alloc] init];
// Es equivalente a:
Video *myVideo = [Video new];
11
Objective-C
Initializers
Video *myVideo = [[Video alloc] init];
// Es equivalente a:
Video *myVideo = [Video new];
Video *myVideo = [[Video alloc] initWithURL:theURL];
12
Objective-C
Initializers
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-C
Initializers
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-C
Properties
Declaración
@interface Video : NSObject
@property NSString *title;
@property NSString *url;
@end
15
Objective-C
Properties
Modificadores
@interface Video : NSObject
@property NSString *title;
@property (readonly) NSString *url;
- (void)assignURL:(NSString *)url;
@end
16
Objective-C
Properties
Modificadores
#import "Video.h"
@implementation Video
- (void)assignURL:(NSString *)url {
// validaciones...
! self.url = url;
}
@end
17
Objective-C
Properties
Modificadores
#import "Video.h"
@implementation Video
- (void)assignURL:(NSString *)url {
// validaciones...
! self.url = url;
}
@end
Assignment to readonly property
18
Objective-C
Properties
Extensiones
#import "Video.h"
@interface Video ()
@property (readwrite) NSString *url;
@end
@implementation Video
- (void)assignURL:(NSString *)url {
// validaciones...
! self.url = url;
}
@end
19
Objective-C
Properties
Modificadores cool
@interface Video : NSObject
@property (readonly) BOOL ready;
@end
if([myVideo ready]) {
}
20
Objective-C
Properties
Modificadores cool
@interface Video : NSObject
@property (readonly, getter = isReady) BOOL ready;
@end
if([myVideo isReady]) {
}
21
Objective-C
Properties
Atomicidad
@interface Video : NSObject
@property (nonatomic) NSObject *whatever;
@end
22
Objective-C
Properties
strong & weak references
23
Objective-C
Properties
strong & weak references
24
Objective-C
Properties
strong & weak references
25
Objective-C
Protocols
@protocol Playable
- (void)play;
- (void)pause;
@optional
- (void)fastForward:(int)times;
@end
26
Objective-C
Protocols
@interface Video : NSObject <Playable>
@end
@implementation Video
#pragma mark - Playable
- (void)play {
}
- (void)pause {
}
- (void)fastForward:(int)times {
}
@end
27
Objective-C
Protocols
@interface PhotoSequence : NSObject <Playable>
@end
@implementation PhotoSequence
#pragma mark - Playable
- (void)play {
}
- (void)pause {
}
@end
28
Objective-C
Protocols
@interface PhotoSequence : NSObject <Playable>
@end
@implementation PhotoSequence
#pragma mark - Playable
- (void)play {
}
- (void)pause {
}
@end
29
Objective-C
Blocks
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-C
Blocks
Tareas asíncronas
31
dispatch_queue_t queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// Long running task
});
Objective-C
Blocks
Tareas asíncronas
32
Xcode
33
Xcode
Command LineTools
Instalación
34
Ruby
RubyVersion 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
Ruby
RubyVersion Manager
Instalación
$  rvm  use  1.9.3-­‐p392
$  ruby  -­‐v
ruby  1.9.3p392  (2013-­‐02-­‐22  revision  39386)  [x86_64-­‐darwin12.3.0]
37
Ruby + Xcode
CocoaPods
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,ARC
and include UnitTests
40
Xcode
Create local git repository for this project
try.github.com
41
Xcode
42
Xcode
Schemes &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
Xcode
Workspaces & 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
Xcode
Relación entre unidades de trabajo
Workspace
Project
Project
Target
Target
Target
Scheme
45
Xcode
Primera ejecución
⌘R
46
Xcode
Primera ejecución
App simulada
47
Xcode
Preparando para dispositivo
Firma del código
Code Signing Identity: Don’t Code Sign
48
Xcode
Preparando para dispositivo
Certificado de desarrollo
Request a Certificate From a Certificate Authority...
49
Xcode
Preparando para dispositivo
Certificado de desarrollo
Request is: Saved to disk
50
Xcode
Preparando para dispositivo
Certificado de desarrollo
51
Xcode
Preparando para dispositivo
Certificado de desarrollo
52
Xcode
Preparando para dispositivo
Certificado de desarrollo
CER (certificado)
+ CSR (clave privada)
P12 (PKCS#12)
53
Xcode
Preparando para dispositivo
Certificado de desarrollo
CER (certificado)
+ CSR (clave privada)
P12 (PKCS#12)
54
Xcode
Preparando para dispositivo
Certificado de desarrollo
Certificado y clave privada
55
Xcode
Preparando para dispositivo
Certificado de desarrollo
File Format: Personal Information Exchange (.p12)
56
Xcode
Preparando para dispositivo
Certificado de desarrollo
57
Xcode
Git
58
Próxima sesión...
59

Formacion en movilidad: Conceptos de desarrollo en iOS (I)