13. String s = new String(); NSString *s = [[NSString alloc] init];
2Pointers
14. String s = new String(); NSString *s = [[NSString alloc] init];
0x3DE2FE Stuff
2Pointers
15. String s = new String(); NSString *s = [[NSString alloc] init];
0x3DE2FE Stuff
2Pointers
16. String s = new String(); NSString *s = [[NSString alloc] init];
0x3DE2FE Stuff
2Pointers
17. String s = new String(); NSString *s = [[NSString alloc] init];
0x3DE2FE
* Object
Stuff
2Pointers
18. String s = new String(); NSString *s = [[NSString alloc] init];
0x3DE2FE Stuff
2Pointers
19. "Many of those strange primitive wrapper classes, like Integer and
Number came from Lee Boynton, one of the early NeXT Obj-C class library
guys who hated 'int' and 'float' types."
Patrick Naughton (one of the original creators of Java)
2NSWhat?
23. NSString *one = @"1 +";
String one = "1 + ";
int two = 2;
int two = 2;
NSString *eq = @"=";
String equals = " = ";
float three = 3.0;
float three = 3.0f;
NSString *s = [NSString stringWithFormat:@"%@
String s = one + two + equals + three;
%d %@ %.1f", one, two, eq, three];
2“A” + “B”
24. NSString *one = @"1 +";
String one = "1 + ";
int two = 2;
int two = 2;
NSString *eq = @"=";
String equals = " = ";
float three = 3.0;
float three = 3.0f;
NSString *s = [NSString stringWithFormat:@"%@
String s = one + two + equals + three;
%d %@ %.1f", one, two, eq, three];
2“A” + “B”
25. NSString *one = @"1 +";
String one = "1 + ";
int two = 2;
int two = 2;
NSString *eq = @"=";
String equals = " = ";
float three = 3.0;
float three = 3.0f;
NSString *s = [NSString stringWithFormat:@"%@
String s = one + two + equals + three;
%d %@ %.1f", one, two, eq, three];
2“A” + “B”
26. NSString *one = @"1 +";
String one = "1 + ";
int two = 2;
int two = 2;
NSString *eq = @"=";
String equals = " = ";
float three = 3.0;
float three = 3.0f;
NSString *s = [NSString stringWithFormat:@"%@
String s = one + two + equals + three;
%d %@ %.1f", one, two, eq, three];
2“A” + “B”
27. NSString *one = @"1 +";
String one = "1 + ";
int two = 2;
int two = 2;
NSString *eq = @"=";
String equals = " = ";
float three = 3.0;
float three = 3.0f;
NSString *s = [NSString stringWithFormat:@"%@
String s = one + two + equals + three;
%d %@ %.1f", one, two, eq, three];
2“A” + “B”
28. NSString *one = @"1 +";
String one = "1 + ";
int two = 2;
int two = 2;
NSString *eq = @"=";
String equals = " = ";
float three = 3.0;
float three = 3.0f;
NSString *s = [NSString stringWithFormat:@"%@
String s = one + two + equals + three;
%d %@ %.1f", one, two, eq, three];
2“A” + “B”
29. But... If I can useNSStringthen I +";
C++ *one = @"1
String one = "1 + ";
int two = 2; can use operator overloading
int two = 2;
NSString *eq = @"=";
String equals = " = ";
float three = 3.0f;
to add that to Objective-C,
float three = 3.0;
NSString *s = [NSString stringWithFormat:@"%@
String s = one + two + equals + three; right?%d %@ %.1f", one, two, eq, three];
2“A” + “B”
30. But... If I can useNSStringthen I +";
C++ *one = @"1
String one = "1 + ";
int two = 2; can use operator overloading
int two = 2;
NSString *eq = @"=";
String equals = " = ";
float three = 3.0f;
to add that to Objective-C,
float three = 3.0;
NSString *s = [NSString stringWithFormat:@"%@
String s = one + two + equals + three; right?%d %@ %.1f", one, two, eq, three];
Nop :(
2“A” + “B”
51. "I'm pretty sure that Java's 'interface' is a direct rip-off of Obj-C's 'protocol'
which was largely designed by these ex-NeXT'ers..."
Patrick Naughton (one of the original creators of Java)
3NSWhat?
52. @protocol Color <NSObject>
- (int)red;
interface Color {
- (int)green;
public int getRed();
- (int)blue;
public int getBlue();
public int getGreen();
@opcional
}
- (int)rgb;
3Protocols
@end
54. Recap
Interface .H
IMPLEMENTATION .M
Interfaces are called
protocols and there’s
no abstract classes
PROPERTIES
ARE
AWESOME
55. Recap
Interface .H
IMPLEMENTATION .M
Interfaces are called
protocols and there’s And
no abstract classes imagine
PROPERTIES what you
can do
ARE with
AWESOME categories
58. "Objective-C is a hybrid programming language[…]formed by grafting the
Smalltalk-80 style of object-oriented programming onto a C language
rootstock. Objective-C adds precisely one new data type, the
object[...]and precisely one new operation, the message expression. "
4Why C?
Cox, Brad J. (1991). Object Oriented Programming: An Evolutionary Approach
60. Core Foundation is a library with a set of programming interfaces
conceptually derived from the Objective-C-based Foundation framework
but implemented in the C language. To do this, Core Foundation
implements a limited object model in C. Core Foundation defines opaque
types that encapsulate data and functions, hereafter referred to as
4CF
“objects.”
61. Recap
C Is at the
bottom of
objective-c
and YOU
SHOULD TAKE
ADVANTAGE OF
IT
62. Recap
C Is at the
bottom of
objective-c BUT C
and YOU DOES NOT
HAVE ARC
SHOULD TAKE SO YOU
ARE STUCK
ADVANTAGE OF WITH
IT MALLOC
AND FREE
64. //create the array
NSArray *arr = @[ @16, @11, @88 ];
//sort it using a block
NSArray *sortedArr = [arr sortedArrayUsingComparator:^(id obj1, id obj2) {
return [((NSNumber *)obj1) compare:(NSNumber *)obj2];
}];
//print
5Closures
NSLog(@"%@",sortedArr);
65. //save a block in a variable
int (^aBlock)(int, int) = ^(int i, int j) { return i * j; };
//execute it
int result = aBlock(1,2);
5Keep it
66. //get the block as a parameter
- (int)operationWithArg1:(int)i arg2:(int)j block:(int (^)(int, int))aBlock {
return aBlock(i,j);
}
5Get it
67. “If you are using ARC, object variables are retained and released automatically as the block is copied and later
released.”
“If you use a block within the implementation of a method [...] If you access an instance variable by reference,
self is retained; If you access an instance variable by value, the variable is retained.”
“When you copy a stack-based block, you get a new block. If you copy a heap-based block, however, you
simply increment the retain count of that block and get it back as the returned value of the copy function or
5Memory
method.”
Blocks &
68. Recap
BLOCKS Is MY
FAVORITE
OBJECTIVE-C
LIBRARY AND IT
WILL BE ONE OF
YOURS TOO
69. Recap
BLOCKS Is MY
FAVORITE
OBJECTIVE-C
LIBRARY AND IT The
WILL BE ONE OF notation
is hard to
YOURS TOO MASTER
though