Вы находитесь на странице: 1из 384

iS

Objective-C, Xcode

-
2014

32.973.26-018.2.75
78

681.3.07
""

. ..
.. ,

. .-. .. , . . ..
. .-. ..
"" :

info@williamspublishing.com, http://www.williamspublishing.com
r, .

78

".. ~

iOS 7. Objective-C. Xcode


2014. - 384 . : . - . . r.

ISBN 978-5-8459-1895-6

: . . -

(.)
66

32.973.26-018.2.75

JJ J1J1r r

.
JJ
, ,
, JJ

O'Reilly

Media, Inc.
Authorized Russian translation of the Englisl! edltion of iOS 7 Programming Fundamntals: Ojctlve-C, Q:t, and d
Basics (ISBN 9781491945575) 2014 Matt Neuburg.
This translation 11 published and sold permlasion of O'Reilly Media, lnc" whlch owna or controls 11 rights to pubUsh and
s11 thc samc.
11 rights rescrved. No part of thil work reproduced or transmitted ln any form or any means, elctronic or me
chanical, includlng photocopylng. recon:Ung. or any informatlon storage or rctrieval systm, without the prlor wrltten permlsslon
of the copyright owncr and thc Publishcr.

r r

r iOS 7.
Objective-C, Xcode

..
..
.. 1>1

..

12.03.2014. 70100/16
Times.
. . . 30,96. .-. . 26,87.
1500 . No 3084

rJJ "

199034, -,
. . ",

127055,

9- JJ,

12/28

. , . , .

43,

ISBN 978-5-8459-1895-6

(.)

2014,

"

ISBN 978-1-4919-4557-5

(.)

2014,

att

Neuburg

rnn
11

11

&111r

14

17

19

1.

1111

1. 1 1 ~

21

1111

2. -1 r

49

11

3. Objective-C

59

11 4. 11
11

Objective-C

5. 11 Objective-C

11. r

85
95

119

11

6. Xcode

121

11

7. 11 i-11

161

11

8.

191

11

9. n

201

111.

261

11

1. 11 1

263

11

11. 1

293

11

12. &11 1

319

1111

13.

367

111

381


811088

11

12

&111r

14

r Pogramming IOS 4

14
15
16

081nop

17

Or

17
18

1. 1

11

, r

1"11181 1. 1 n1 111111111

21

22

24

27
28

30

32

34
37
40
41
44

45

46

1111

41

2. h-1 nr11

49

50

51

52

54

55

1"11111 3. &11111 & ObJtlvC

51

59
61
63
65
65
66
67

nil

68
69
69
70
71
72
74
77
78
79
80

1"11 4. ll Objectlve-C

85

nil

id

CF'ypeRef

85
87
89
91
92

n 5. unn Objectlve-C

15

95
95

96

nib

99

100
102
105
107
109
111
112
115

111

self
SUPER

-

11. 1r11 1116

1"11 6. 111 n Xcode

121

122
123
125
130
131
134
137
138
140
141
142
144

ero

u

r
u

11111

Or

Ni-


n11

SDK

7. n1n nlb-1in1

ni-

145
147
147
148
149
152
155
161

162
163

166

, Ni-

169
170
172
176
178
180
180
184
184
187

n11

191

ni-
ni-

8. 111

192
193
197
197
197
198
199

200

Quick Hdp

n11

9. 111n n

fix-it

201

201
205
207
208
210
210

211

214
215
215
217
223
227
229
230

Xcode

232
234
236
237
237
242
247
249
250
252
253
254
255
256
258

Store

111.

261

n11 1. n1 1

263
263
266
268
268
269
273
274
275
275
276
278
279
281
281
281
282
282
284
285
287
287
288
289

Foundation

NSStrinq
NSDate

NSNumer

NSValue
NSData

NSindexSet
NSArray NSMutaleArray
NSSet
NSDictionary NSMutaeDictionary
NSNull

NSOject

n1

11. R 1

213
294
294
296
297
299

1111111

Paccvuca

300
301
302
302
304

NSTimer

306

307
310
311
311
312
316

12. 111~1n111 ynpallll8Hll18 IMRTblO

311

I<VC :


:
r

ARC

ARC)

(
:

r ni-
r:

CFTypeRef

n111

13. 11 h

, r

ARC)

319
320
323
323
324
325
326
327
330
332
334
337
340
342
345
349
350
351
355
356
357
358
360
363

367

"--"

368
370
371
372
373
378

111~1I 11n

381

, r

10

1111111

IOS Programming iOS 6 (


III ( 13).

Programming iOS 4

2011), Programming iOS 5

2013) -

2012)

, ,

1-13

iOS 7 Programming Fundamentals,

Programming iOS 7,

14-40

Programming IOS 6 1150

. ,

2010

Programming IOS 4. O'Reilly Media


Fundamentals of Programming,

, .
,

IOS).

2010

Touch (

, ,

. ,
,

.. , ,

13

400, 401 14. , O'Reilly Media


.
,

Programming iOS 7, 1 1,
IOS 7 Programming Fundamentals.

. ,

iOS, ,

, . , ,
.
, , ,

Objective-C,

Xcode,

13 ""

iOS, - 13 , iOS 7
Programming Fundamentals. , Programming IOS 7, ""
- ,
Xcode. ,
, IOS 7 Programming Fundamentals -

iOS 7 Programming Fundamentals,

Programming iOS 5 Programming iOS 6.

- Programming iOS 4,

, -,

iOS.

Objective-C

. ( .

Objective-C , ).

-
.

11, . Xcode, .

Xcode

iOS. .,

Xcode , - ,
Store.
. , lnterface Builder,
, ni-;
, , ,

, .

III . Objective-C,
Touch.
, , ,

, .

ey-Value

Coding ey-Value Observing.

IOS.

IOS

, Gitub,
http://github.com/mattneu/Programrning-iOS-Book-Examples),


r . , r

IOS 7.

IOS

IOS 7 Xcode 5. , ,
Xcode .

r - ,
r ( , r).
,
r, .

Xcode 5 r r

r ,

(ARC). r r
IOS. Xcode 5 ARC

. , r r r,

12

ARC.

11n111

ARC

ARC,
ARC, 12, ARC, ,

, .

Xcode

. ( ) ;

i-

, ,
. ni-

. i-.

, ,
, .

- -
IOS 7 Xcode 5. Apple ,
, iOS
, - ( , ). ,
, ,

,
,

13

6nr

O'Reilly Media,
(Rachel
(Sarah Schneider), (risten Brown)

Roumeliotis),
(Adam Witwer). , ,
(Brian Jepson), ,
.

(Peter Olsen),

.
,

, .
, :

git (http: //git-sc.co)

SourceTree (http://www. sourcetreeapp. )

Textate

AsciiDoc(http://www.ethods.eo.nz/asciidoc)

BBEdit (http: / /barebones. co/products/bbedit/)

Snapz Pro (http://www. amrosiasw. )

GrapblcConverter (http://www. lekesoft. )

OmniGraffle (http://www. onigroup. )

(http: / /acroates. )

Model

(http: / /pckeyboard, ),

Unicomp

.
:

http: / /att. neuburg. usesthis. .

11 r

iPhone,

Programming iOS 4

iPad

, ,
, , ,

IOS,

Apple WWDC,

OS

OS

iOS - ,
. iOS ,
,
. , ,
,
, ,

.
,

iOS

iOS.

(, rr, ) , ,
, ,

IOS.

Objective-C (

),

- ,
, , ,
, . ,
, ,

.
,

Apple

. , ;
. ,

, .
, ;

, .
, .
- , :
, .

, ,
,

Objective-C, 1 2.

, .

'; ,
, , .
, , ,
, , .

,
. , ,
, . , ,
,

rnw, nn r
.

, .

&111r111

15

r 11

URL, , r r,

r, , , ,
..

D~IDI 8111L-+ 81J*'J:I

.
I I

r , ,

, , .

r , .

11
" ,

"
~
r .

nn
( , ..) r

https: //github. com/mattneu/Programming-iOS-Book-Examples.

r .
r r .

,
. , r,

r r, .

ROM

O'Reilly

CD-

r .
r r r

r, r ,
, ,

ISBN, "IOS 7 Programming


Fundamentals Matt Neuburg (O'Reilly). Copyright 2014 Matt Neuburg. 978-1-491-94557-5':
,
, ,

16

permissions@oreilly. .

&narOAIPNOCTll

(Matt Neuburg)

1968

14 ,

PDP-10,

, I-360/67 ,

, .

1981

,
, .

Apple

1990

Macintosh.

,
- TidBIS,

1996
Frontier: The
Definitive Guide, REALbasic: The Definitive Guide AppleScript: The Definitive Guide,
Programming IOS 7 ( O'Reilly & Associates), Take Control of Using
Moutain Lion ( TidBIS Pulishing).
1995

MacTech.

n
, ,

groenkandicus),

(Pagophilus

" ':


, . ,

, ,
. , ,
, , .

,
.

130-180 .

1,5-2

. .

16 ,

, .

,
, .

12

, (

). ,
,

4-8

35 .

Wood, Animate Creation.

( )

11
, , . ,

,
. .
.
- .
, , ,
, .
, ,
.
.
:

E-mail:
VVVVVV:

info@dialektika.
http://www.dialektika.com

:
:

18

127055, . , . , . 43, . 1
03150, , / 152

Apple
iOS, ,
. API (
). API,
. Objective-C,
. API .

. , ,

, ,

API

Objective-C, API

2 Objective-C. -

,
, ,
, .

4 Objective-C,
Objective-C .

3 Objective-C.

Objective-C.

, , ,
, ,

self

super,

- .

III Objective-C,

, .

? ?

(Leonard Bernstein)
(Stephen Schwartz), Mass

r
. ,

iOS,

iOS,

API

(.. r r,
, .) ,
r , .

IOS Objective-C,
IOS Objective-C. ObjectiveC . , Objective-C
; , , Objective-C.
, "Objective-C - ~

API

r .

API IOS ,
Objective-C

Objective-C.

. ,

CGRect,
CGRect n CGRectMake.
API IOS
.

- r (Brian W.
(Dennis . Ritchie) h rg/g Language (PTR Prentice Hall,
1988) 1, Kd-R (
). - : , ,
. K&R
ernighan)

IOS, ,

( ). r r

(Mike Banahan). (Declan Brady) (ark Doran)


Book, http: //puications .gbdirect. . uk/c_book/.

r : r ., . 31111 tWI ,
- .: ".. ~ 2013, ISBN 978-5-8459-1874-1. - U. .

2- .

.
, " " ,
. ,
, ,

, .

Objective-C,

iOS.

Objective-C
- " ':

.
,

Kd-R.

1.

2-4.

; , ,

Objective-C ,
. ( )

*.

6 Kd-R ; , ,

, ,
, (,
, CGRect ).

K&R2,

; , ,

Kd-R,
Objective-C.
( ANSI , 89,

Kd-R
Xcode
. Xcode
, GNU99
99),

( 99,
). ,

Xcode

Kd-R

, ,

Kd-R

n11,
.

; , .
2

22

r KO-R.
11t

1.

. .

; .

, ,
.

(, )

, .

, ,

, ,
, , .

, .

r, . ,

, ,

, - ,
. , , -

, . ,

, r.
,
. , ,

() .
, ,

.
,

Xcode

ProductQPerform ActiOQPreprocess [ ]),

, , .
. .

. . (

.)

: (, , -

Objective-C) !R ,

- .
; , " ".

( );

Xcode

"" , ,

, , ,
.
r

K&R

... */;
(K&R 1.2).
{/ / );

/*

, , ,

r:

int lower

11

++,

n111

K&R.

1. n11111

23

(, ,

Objective-C)

. . , ,

int.

lower int,

Int,

Lower, , .

: .

nn

(h t tp: / / gcc. gnu. org).

Xcode

Apple

GCC

LLVM (http: / /11 vm. org),

Clag, ,

,

Apple

GCC.

Xcode 3

LLVM,

LLVM-GCC,

LLVM

GCC

Apple

fi

GCC,

Xcode 4 LLVM-GCC
GCC .

Xcode 4.2

LLVM 3.0,

GCC

Xcode 4.6

Xcode 5 LLVM-GCC;
GCC LLVM .

LLVM 4.2.

- LLVM 5.0,

n, n

, .
, ; ,
(
, ).

K6'R

,
, :

int height 2;
int width height * 2;
height height + 1;
int area height * width;
:

char
int (4 ), float doue ( )
short ( ), long ( ), unsigned short ..

( ),
,

( ) :

24

1.

doule,

4. Of

int,

4UL unsigned long; 4.0


float. Objective-C

, (

typedef,

K&R 6.7), 64- ;


NSinteger ( NSUinteger) CGFloat.

float,

API , ,

NSinteger int, CGFloat

int height = 2:
float fheight = (float)height;
,

Objective-C

, ,
(

3).
enum (K&R 2.3).

, ,
.

API

. ,

typedef enum { UIStatusBarAnimationNone,


UIStatusBarAnimationFade,
UIStatusBarAnimationSlide,
UIStatusBarAnimation;

UIStatusBarAnimationFade

UIStatusBarAnimationNone, 1
2 UIStatusBarAnimationSlide.

, (
), . ,

UIStatusBarAnimation

. ,
, , .
, , :

UIStatusBarAnimation anim

UIInterfaceOrientationPortrait;

UIInterfaceOrientationPortrait

, , ,

UIStatusBarAnimationNone.
UIInterfaceOrientation.

. ,
.

IOS 7

typedef NS_ENU(NSinteger,UIStatusBarAnimation)
UIStatusBarAnimationNone,
UIStatusBarAnimationFade,
UIStatusBarAnimationSlide, };

1.

25

LLVM 4.0,
Xcode 4.4. NS_ ENU ,

, r; 11 n

typedef enum UIStatusBarAnimation :


NSinteqer UIStatusBarAnimation;
enum UIStatusBarAnimation : NSinteqer (
UIStatusBarAnimationNone,
UIStatusBarAnimationFade,
UIStatusBarAnimationSlide, };
r , r ,

111 , r , r
, (

NSinteger).

UIStatusBarAnimation

; r,

Xcode
9. ,

11, r r

NS_OPTIONS,

Objective-C JCaJC NS_ENU (


'

++, Jr ).

, 1111;
r JCaJC

char, .

"strinq"

7 ,

(ASCII)

. . -,

IOS.
Objective-C, NSString. -.
Objective-C NSString ,

l!"strinq"

@1
Objective-C , NSString.
- @, r

-, r
.

NSString

-,

- ( , , ). , Jr

Kd-R
(Kd-R 2.3). NSString,

\n

\t

\"

( , ,

Unix.

r ).

\\

26

1.

"".'.

NSString
Unicode, ,
11,
S-, NSString; ".~.
~----.:,
, .
\ \u,

K&R

, ,
.

Objective-C

NSString,

@:
@" !l,

"

@" J!/i .";

.
? : ,
.

IOS.
Objective-C

NSArray.
(K&R 6.1) :

, . ,

, ,
.

API

IOS

.
,

IOS , CGPoint

struct CGPoint
CGFloat ;
CGFloat ;
};

typedef struct CGPoint CGPoint;


,

CGFloat ,

,
; ,

CGPoint

CGFloat

. (

CGPoint struct CGPoint.) ,

CGPoint myPoint;
myPoint.x 4.3;
myPoint.y 7.1;

myPoin t. ,
myPoint. ,
myPoint. .

,
. ,

n111

1. 11 n11111 1

27

r, ,
.

iOS, CGSize:

struct CGSize {
CGFloat width;
CGFloat height;
};

typedef struct CGSize CGSize;


CGPoint

CGSize

CGRect:

struct CGRect {
CGPoint origin;
CGSize size;
};

typedef struct CGRect CGRect;


,

CGRect
rnyRect. r rnyRect. origin CGPoint,
rnyRect. origin. - CGFloat. r rnyRect. size
CGSize, rnyRect. size. width - CGFloat.
width CGRect,

myRect.size.width

= 8.6;

,
r :

CGPoint myPoint
CGRect myRect =

=
{

{ 4.3, 7.1 };
myPoint, (10, 20} };


r . , r

;
, , r :

CGContextFillRect(con, (CGRect) {myPoint, (10, 20}});


CGContextFillRect -

r,

CGRect,

, ,

CGRect,

CGRect.

11
r r

(K&R 5.1).

(r r

), , .
, r

ero

, r ,

Objective-C

, , , ,

, .

. r
,

int i;

28

1.

"i ': :

int* intPtr;

- "intPtr

': ,

, , , ,

, .
, :

int *intPtr;
(
):

int * intPtr;
, ,

Apple

, ,

. ,
,

intPtr,

in t *. ,
int* ( int);

( in t

*) .

(int *) .

, "

void" (void*).

. , ,

. , :

int* pl;
void* 2;
2 = pl;
pl = 2;

11

pl

Objective-C,
2), , ,
, Objective-C ,


(.

Objective-C. Objective-C , ,

Objective-C . ,
Objective-C NSString. ,
NSString

NSString:

NSString* s;

NSString

NSString,

NSString,

Objective-C:
NSString* s = @"Hello, world!";
3

. ,

ptr2

int*,
int, ptr2 -

int *ptrl, *ptr2; ptrl


int* ptrl, ptr2; ptrl
int. - . .

11

1. n

29

intPtr,
*intPtr. ",
intPtr". * intPtr,

" " , , . .
.

Objective-C

; r.
,

NSString,

ero . ,

, .

*s;

Objective-C .

, r ,

Objective-C " "

, , ,

, . . ,
r : , , "s
NSString~ , ,

NSString.

Objective-C

.
. .

. n, ptrl ptr2 - ,

ptrl ptr2;

ptrl

ptr2

ptrl, , ptr2,

(.

1.1).

, , ,

ptrl, . ,

Objective-C,

3.

(K&R 5.3)

, n. ,

, :

int arr[3]; // arr

3 int

, n.
. . ,
, :

int arr(3];
arr[O]
123;
arr[l] = 456;
arr[2] = 789;
,
, , .
,

(K&R 4.9):

int arr[]

30

{123, 456, 789};

1. 111

plr1 =plr2

ptr1

. 1.1. Q.
, .

, , ,

arr

int*

int).

5 K&R

-, ).
,

IOS.

CGContextStrokeLineSegments

void CGContextStrokeLineSegments(
CGContextRef ,
const CGPoint points[],
size t count
);

1.

31

CGPoint

). ,
, . , ,
:

CGPoint arr[]

{{4,5}, {6,7}, {8,9}, {10,11}};

CGContextStrokeLineSegments.
, , - .
,

NSString

stringWi thUTF8String:

) "- UF8 ~
,

char*.

, ,

-.

Objective-C

stringWi thUTF8String: - ;
. - 3.)

l (Kd-R 2.5),
: " ~
.
, ,
:

int i ~
float f

;
z

i/2;

//!

1.5

1.5, i/2. (float) i/2.


(K&R 2.8), ++ --,

- ,

++i

i ++

i,

(K&R 2.9),

""(&) ""

( 1);

, .
":

API

. , ,

UIView , ,
UIViewAnimationOptions,

typedef NS_OPTIONS(NSUinteger, UIViewAnimationOptions)


UIViewAnimation0ptionLayoutSubviews
1 << ,
UIViewAnimation0ptionAllowUserinteraction
1 << 1,
UIViewAnimation0ptionBeginFromCurrentState
1 << 2,
UIViewAnimation0ptionRepeat
1 << ,
UIViewAnimation0ptionAutoreverse
1 << 4,
11 ".
};

32

1.

<< ;

, .
,

NSUinteger

( ,

), , -

( ):
UIViewAnimationOptionLayoutSuviews

UIViewAnimationOptionAllowUserinteraction
UIViewAnimationOptionBeginFromCurrentState
UIViewAnimationOptionRepeat
UIViewAnimationOptionAutoreverse

00000001
00000010
00000100
00001000
00010000

( ),
. , ,

nAutoreverse

1. , , 00011000 ,
UIViewAnimationOptionRepeat UIViewAnimationOptio

( , , ).

00011000,

. ,

24,

00011000

, ,

. ""
:

(UIViewAnimationOptionRepeat

UIViewAnimationOptionAutoreverse)

, ""
, ,
,

00001000

00010000

00011000,

. ( ,

? "':)

(K&R 2.10)

,
. ,

height *= 2; 11

height - height * 2;

(? : )
(K&R 2.11). (

( , ),
! ;

2 . ,

:
myVariae

()

1l

12;

myVariale, .

-,
,
, .

1.

11111

33

nn nn
, r
11r , r . r
,, , , :

it

7)

int i
i + l;

(
;

r u

i,

11111

, , , r

r . , r , ,
, 11 ,, r
. u (, ,
)

r r .

, r

1.1.

n111111111 nr11111

(:)

if

3 KO-R, 11 , , 1.1.

(::)

if

} else {
;

i f ( :)

else if

(:)

else {
;

while

(::)

do {
;

) while (::);
for ( ;

:;

: KaJl;ll'O )

i f ... 1 s i f ... 1 se ,
i f, 1 s .
if ... else if ... else if ... else, , r, ,

1 s

, ,

swi tch;

, , , ,

r ( ,

K&R 3.4). h -
case break, ""
case ( 1.2).

34

1. 1

1.2. swltch

NSStrinq* key;
switch (taq) {
case 1: { // .. taq
key @"lesson";
break;

case 2: { // .. taq 2
key @"lessonsection";
break1
case 3: 1 11 .. taq
key @"lessonSectionPartFirstWord";
break;

f r r
(.

1.1).

, r

r , .
, , ;
, r r rr . r

,
; . ,

. ,

i 1, 2, 3, 4 5, i

int i;
for (i = 1; i < 6; i++) {
11 . . .
, r ,
, 99

; r
:

for (int i 1; i < 6; i++)


11 . . .

for r , Objective-C
Objective-C,
NSArray, ; ""

r .

, ,

r . (

10. Objective-C
for, , , in, r :

SomeType* oneitem;
for (oneitem in myCollection)
11 . . .

1.

n11111 1111

35

J(]J

oneitem (
for 99,

. J(]J

r J(]J

for,

oneitem

J(]J:

for (SomeType* oneitem in myCollection)


'l'.\

/ /

J(]J

break.

continue. J(]J while do


continue J(]J; J(]J for
continue ,
J(]J

J(]J.

( )

goto,

(K&R 3.8); , goto

" ~ ,

..

, - .

".

r
, .

".

~--

. , ,

, . r
() ; ,
, , .

==

(K&R 2.6);

<

""(&&) "";

( ! ),

"" "" , ..
( ""

""), .
""

(&&)

""

""(&) ""

. &,

&&

( 1 1)
( 1),

( ). -

, .

== ;

, : ,

, ,

. () :

int i

while (i 1) {

36

1.

, I

while

. :

, I . ? .
I

while , i

. , I

, . , I ,

. ,

, ,

I. , .
,

,
, .
,

Objective-C, , ,

nil.
s nil, :

(.

3), ,

if ( !s) {

11 ".

Objective-C

8001,

YES

NO

), .

8001,

YES

NO, 2
YES, NO. ( -

,
, .)

8001

. :

BOOL isnil = (nil == s);


if (isnil) {
11 ~: if (isnil == YES)
11 ".

(K&R 4.1).

, , .

, . ,
.
, :

int square(int i)
return i * i;
:

int i

= square();
n111

1. 1 n111 11111111

37

int i 9;
, .
.

intO square8(8int i) {0
return i i;
;

int.
8
8

square.

, .

square

int,

i.

i ( ) ;

, .
,

(
).

, , .
;
. ,
, . ,

i
i ,

i (,
i). i

, ;

3,

9.

. ,
:

int myfunction(int i, int j) { // ...


, :

int result

= myfunction(,

4);

i 4

j.

return,

, .
;

return

, ,

void.

, . ,

square (3);

38

1.

9;
, . , ,
,
,
.

. ,
. ,
, , .
, , ,
.
,
( }, .
,
. ,
:

int square(int i)
return i * i;
int i

= square();

, ,

square

square

, , ,

square

1.3). ,

, , .

1.3. ,

int square(int i);


int i square();
int square(int i) {
return i * i;
,

(, , ).
. ,

int square(int j);


, ,

Objective-C

square ,
int int. (

; . "

Objective-C").
Objective-C, ( 2),

, ( ).

n111

1.

n1 1111

. ,

CGPoint,
CGPoint,

, . r,

CGPointMake, u:

CGPoint CGPointake(
CGFloat ,
CGFloat
);

, , ,

square.

r,

CGPointMake ,
CGFloat CGPoint.

, , ,
r:

= CGPointake(4.3, 7.1);

CGPoint myPoint

-n n

Objective-C J1 ( },
Objective-C ,

- -.

r.

Objective-C .

Objective-C,

stringByAppendingString:

NSString.

NSString

r ,

- (NSString *)stringByAppendingString: (NSString *)aString


r ,

NSString*

Objective-C,

NSString*.

, ,

NSString*.

NSString
, NSString,

NSString* sl
NSString* s2
NSString* s

@"Hello, ";

= @"World!";
=

[sl stringByAppendingString: s2);

r -;
"-~ r.

(K&R 5.1), ,

, .
, N S S t

NSString,

r i n g

+ (id)stringWithContentsOfFile: (NSString *)path

encoding: (NSStringEncoding)enc
error: (NSError **)error
, id,

Objective-C. . - NSString*;

40

1. 1

NSString

NSString. NSStringEncoding r
NSUinteger, .

r ,

NSError**?
NSError**

NSError.
NSError.

NSError r:

NSError* err;
? !

r :

NSString* path
11 -
NSStringEncoding enc 11 -
NSError* err nil;
NSString* result =
[NSString stringWithContentsOfFile: path
encoding: enc
error: &err];
. r r

NSError, &err

NSError, ,
3, ,

. , . r

err .


. r ,

! r, r
: , r .
,

&square

square. r, ,
ero ,

;
. r

3, ,

. r r r

r , r , r

: , , r
h. ""
, .
, "" r ,
. ,
. ( } ,

r "" r ,

tinclude. * ,
tinclude, pyroro

, ,
11 r .

11111

1.

n11111 111111

41

. -

, ;

. h-
. -.

, r

. - . h-,

.
, , functionl filel. ,
file2. functionl,
functionl filel . h. filel.
filel. h, r functionl
. file2.
filel. h,
functionl (. 1.2). ,

(
) .
fuctio 1

filt1.h

filt2.h

!t2.

fuctlo1
fuctlo 1

fuctlo 1

1.2. " "' "'

. -

main,

: ,

main.

, ,
,

IOS. Dr , .
. m-, . m
Objective-C, .

42

Xcode,

1. 1111

main. m;

Xcode IOS,

, ,

main.

Objective-C ,
#include Objective-C #import.
# import Kd-R. Objective-C
. #include,

, ,

.
, r ;

#import

iOS

Apple.

III)

Apple

( , .

. -

#import

h-,

Apple.

. h- Apple,

Xcode IOS, ,
main. m

timport <UIKit/UIKit.h>

. m-

API IOS.

#import,

. ,

. h-,
AppDelegate .m,

. h-

Hmport "AppDelegate.h"

AppDelegate. h

<UIKit/UIKi t. h>. ,
IOS.
#import, #include

(Kd-R 4.11), .

- .
. 11 ,
(. m-, #import).

.
, . ( ,
.)
J ,

API

, J

. ,

#import, ,
<Command>, ,

IOS 7

Xcode 5

, " ",

IOS

( J ).


UIIOt IOS API
CGPoint

. , ,

11111

1.

1 n11111 111

43

struct CGPoint
CGFloat ;
CGFloat ;
};

typedef struct CGPoint CGPoint;


. m-
- .
CGPoint
30 , .

CGPoint

. ,

( ),
; .
,

@import UIKit;
@import Foundation;
( Product~Perform Action~Preprocess [
].)

Xcode 5

@import

. ,

@import

6.

4.3, Objectlve-C

LLVM

3.1,

Objective-C

Xcode

,
. ,

Objectlve-C

Objectlve-C. ,
Objectlve-C,

.
,

Objectlve-C m-
m- l
, - h-,

. m-,

, ,

m-,

-.

Objectlve-C,

. m-

( ),

4.

n
.
,

. h-, ,

44

1.

, ,

r r r . r

ceil

(""). ,

man ceil.

r ,

#include

r rr ,
. r r
, , r :

#include <math.h>
float f = 4.5;
int i = ceilf(f);
r

//

IOS math. h

UIit,

ero

. r

#import.
r

K&R.
K&R ;
, K&R. , K&R
ceil, ceilf . r, r

{, r r,
), , , r

K&R;
arc4random_uniform.

rand,
random

r ,

Objective-C

r
.

r
r r

#define.

; r

.
r

K&R

1.4),

r "r

" r, .
,

iOS,

, , r .
, ,

3.0 .

3.0.

#define MIDSPACE 3.0


"rr "

MIDSPACE,

3.0

ero

MIDSPACE;

3.0.

, , ,

3.0

#define

#define.

. ,

NSString. .

NSString r

. { ,

.)

r .

11111

1.

n1111 11111

45

@"mykey"

@"myKey"

@"mikey",

, .
:

tdefine

@"rnykey"

@"mykey",

, ),

#define

iOS

(K&R 4.11.2),

, ;
, .

#warning

Xcode

twarning

Xcode

Xcode

#pragma;
9.

n
.

, . ,

const,

(K&R 2.4),

;
, , .
,
(

#define)

const,

" "

. :

NSString* const

API

@"Howdy";

. ,

, . ,
,

const

NSString:
UIKIT_EXTERN NSString *const
UIApplicationStatusBarOrientationUserinfoKey;
( , UIKIT_EXTERN.) , UIAp
plicationStatusBarOrientationUserinfoKey NSString
. ,

. ,
, , , .

, ,

static.

; ,

46

1.

1111

, .

static , ,

, ;
, , .

, ,
( ).
, : ,

, ;
, . :

int myfunction() {
static int result
if (result == 0) {
11

=;

11
11

return resul t;

Objective-C
- , .
, - .
, , , Objective-C.

(CardPainter*) sharedPainter {
static CardPainter* sp = nil;
if (nil == sp)
sp = [CardPainter new];
return sp;

sp CardPainter

, ,

. , ,
, ,
.

Objective-C.

; , ,

. , ,
.

C,

Objective-


. ,

Objective-C ( 2).

, , , .

11111

1.

11n1111111111

47

-
r

..

Objective-C,

""

- .
(W.S. Gilbert), ""

API

- , ,

- .

Objective-C

, . .

.
. ,
, . ,

, , . -

, - . , ~
, ,
,
: , , .

, ;
, . (
,

.)

-
.

. ,
.
.

( , - ), .
, .

, ,
, , , .
, , ,

. ,
. , ,
, . ,
. .

.
, . -
, .
- ,

, , . , ,

. ,
: , , , , , .
, .
-,
: ! ! !

- , ,
. "" ,

eat

()

dog

().

. ,
.
- ,
( )
:

, .

. - . ,
,

eat,

dog

t.

dog

eat.

, ,
. , .
, .

. ,
. , . ,

, ,

. (

. , ,

.)

Objective-C

, .
.

50

1. 1

..

Objective-C

-;

:.

'----~.

Objective-C.

n n
-

. , -
. , ,

- .

int

float, -
dog NSString. -

,
.
, . , ,

. , , . -
, Dog.

Dog.

, Dog.
: , ,

. , ,
.

Dog.

, -
. , ,

" ~
, . Dog , ,
. :

Dog, ?
, .

, Dog, .
- ,

Dog. Dog,

"~ , Dog (
), . ,

, .
,
: .

.
, ,

. r ;
, , .
, ;
(.

n111

2.1).

2. 61111t11t111 nr11111

51

Dg

Dog
.

2.1.

, ,

, ,
.

API

. ( , ;
,

.)

Apple

. , , m ()

NSString,

NSString.
NSString.

, ,

NSString, .

11
, ,

. , ,
. .
!

m -, . ,
m " "!
,
m . , ,
, ,

, , .

2.1.

, , , ,

. ,
.

52

2.2.

1.

Dg

Dog

2.2.

, , :
, m (,

Dog

). , (,

) . . ,
, :
. , .
, .

Objective-C

"" "~ ,

NSString

+ string
- init

string

ini t -

, , ,
. , ,

. ,

(,
, ). , ,

. ,

NSString:

+ string
+ stringWithFormat :
+ stringWithContentsOfFile:encoding:error:
. , string,
NSString ( ). , stringWithFormat: ,
NSString ,

. , ,

11111

2. 6-1111

53

9 NSString @" 9".


NSString .

, ,

n
, ,
,

? ?

, ,
: . ,

: , .
, .

'
. ,
.

, ,

Dog ,

. .

Dog,

.
,

name,

Dog

(,

NSString, Objective-C).
Dog}
name).

(
(

Dog

. ,

(.

Dog,

@"",

@"".

name

2.3).

, ,
; . ,
, .

,
.
.

, . ,
, ,

. ,
.

. ,

.

54

1.

n Dog

Dog

2.3.

-
:
. (

REALbasic: The Definitive Gide.)



, ,

, ,
. ,

, ;

.

.
, ;

, .

, .

,
,

Stack. - ,
LIFO (last in, flrst out; -
). : push . push
-

. ,
. :

, ,

n111

2.

6-1111111 nr1111

55

, , ,
(.

2.4).

------------------------------------------------------------------------------------------------------------------.

2.4.

,
r , . ,

, r .

, , puh ,
r , :
r , .
r, r

r r . ,
r ,
. ,

ero

push

.
,

. r r

,
. ;
r . , r ,

56

-
push . ,

1.

, , .
,
, r - .

-r r
, r

REALbasic.

, r, ""

, . ,

, r r -
r r.

r r

Target.

r . , ,

. ,
, r

. ,
.

r , r
. , , r , .

color.
Target
color ero
.

. , r : r

, ,
. ,
, . (,

, r },
r , .. .

r , . ,

explode,

Target

. ,

explode, -

Score.

, , ,

r , ,

increase

() .

, ,

. r ,

increase; ,

, ,
r

increase

r.

r - r
, ,
r. .
(}, , r r (
). r r
( ).

r.
r r, ,

n111

2. 6-1111111

nr1111111

57

. JilllOC . r,

,
r ,

.
. r , r,
.. r r. r r
. r,
r,

-
1; ero 2, ,

. . r
r

-r r.
-r r r,
r , , r

. ,
- r.
r.

(Martin Fowler) (Addison-Wesley, 1999),

Refactoring

, ,

' ( ).
r r Design Patterns (Erich Gamma), (Richard
Helm), (Ralph Johnson) (John Vlissides) (
" ") (Addison-Wesley, 1994),
- r.

58

1. 1111

ObjectiveC

- ,
,

Smalltalk. 1970- Xerox PARC


(Alan ) 1980- .
Objective-C, (Brad ) (Tom Love) 1986 ,
, Smalltalk,
. Objective-C NeXT
1988 API NeXTStep.
NeXT Apple , NeXT ,
OS , - Objective-C.
, Objective-C IOS. (
, "NS" -
"NeXTStep':)
( 1) -
( 2), Objective-C.
Objective-C; ,
Objective-C. (
10.) ,
, Objective-C, , ,

, ,

iOS.

n n n
W1 , ,

, "
, ':

"

': .
, (
) .


. .
.

- ,
(.

Objective-C
1). ,

, r. ,

Objective-C
Objective-C , }.
, Objective-C ,
(. r 2). - ,
Objective-C, ero . ,
Objective-C , r .

. , ,
, r

Objective-C

rr .

MyClass,

Objective-C

Objective-C

MyClass*,

..

MyClass.

, ,

, r .
r .
,

1,

Objective-C

, - ,
. , , ,
, r. ,
, , , ,

NSString* s = @"Hello, world!";


NSString* s2 = [s uppercaseString];
,

NSString*, r
*s) ""
NSString. r , NSString.

(.. r r

, , r

uppercaseString
( uppercaseString NSString

NSString,

r; ,
r

s2

@"LL,

WORLD! ".)

, r ,

MyClass* "
"MyClass': r Objective-C, r
, , s NSString,
uppercaseString NSString . ,

MyClass':

MyClass*

r,

. "

NSString':

, , , ,
,

NSString*,

..

NSString.

Objective-C ,

- , ,
. r

1, r ,

. ,

60

1. 1

Objective-C.

, r r

"Interface type cannot statically allocated~

n nn, n

nll


r . :

NSString* s; //
11

NSString,

s,

NSString.

NSString,

. , ,

( ,

@"Hello, world!" 'l). ,


.

, , :

NSString* s;
/ / . . . ...
s - @"Hello, world!";
.
( ):

NSString* s

= @"Hello, world!";


, . r

12)

ARC (r

NSString* s;

ARC s

, ,

NSString.

, ,

NSString.

s,

ero

r.

r, r ,

, r r.

nil

, ,

, .

ARC

" " r

ero nil, -

NSString* s

= nil;

ARC

, , ,

NSString* s; // ARC

nil

n111 . 611

Objectlve-C

61

niH

11J1

11J1.

nil

, 11J1

: 11J1

11J1~ , ,
11J1,

if (nil

8)

// ,,,

nil.

1, nil

11J1 r ;

11J1 , , ,

nil

if

/1 ".

(!8)

, , r
, r.
,

r .

nil

, r

, , 11J1-

( -

nil

).

nil

11J1 11J1 , - ~ , . ,
, 11

stringWi thContentsOfFile: encoding: error:

nil.

NSString , " ,
path, enc.

ni 1 ~ ,

1,

NSString* path =
11 -
NSStringEncoding enc = // -
NSError* err ~ nil;
NSString* result =
[NSString stringWithContentsOfFile: path
encoding: enc error: &err];

stringWi thContentsOfFile: encoding: error:

. , ,

NSString,

, pyroro ,
,

NSError.
NSError ,

. (, ,
.)

NSError, 11J1
stringWi thContentsOfFile: encoding: erro
r: err nil; stringWi thC
ontentsOfFile: encoding: error:, , 11J1,
err NSError, . (n
.

r .)
, r r

nil, ,
11J1 . nil, ; ,
. nil, NSError, ,
.

62

1.

NSStrinq* path
11 -
NSStrinqEncodinq enc 11 -
NSError* err nil;
NSStrinq* result
[NSStrinq strinqWithContentsOfFile: path
encodinq: enc error: &err];
if (nil result) ( //! - noWJio
11 err ,
. /
r - strinqWithCont

entsOfFile: encodinq: error:


( - err). r! , err
r. r (

resul t).

, , r

NSError,

r .

".
~

r "

~:

NULL. NULL nil ,


nil.

n nn
r r

1,

" ': ;
. r, r r

, r

. ,
.
,

Stack,

2,

Stack* myStackl

//

11

... N Stack
myStacki ...

Stack* myStack2 myStackl;


myStack2 = myStackl
myStackl. .
, myStack2

, ,
;

myStackl.

, ,

, ,

r . ( -, r

NSCopyinq

10; .

.)

r, : , ,
, .
, r ,
r .

Stack* myStackl 11 ...

11

Stack

myStackl

Stack* myStack2 myStackl;


[myStackl push: @"Hello"J;

3.

611

11

61111

ObjectlveC

63

[myStackl push: @"World"J;


NSString s [myStack2 ];

myStack2, s
myStack2; myStackl
@"Hello", myStackl.
, myStackl myStack2,
myStackl myStack2 - ,

@"World",

. ,
.

, .
,

, ( )
, .

, , ,
, ,
, . ,

myObj ect

Stack* myStack // .. nn Stack


11 myStack
[myObject doSomethingWithThis: myStack]; // myStack
11 myObject

myObj ect ,
myStack. .
myObject myStack ! ,
myObj ect (,
) - , , ,

. ,
, (.

3.1).

my()ther()bje<t

64

3.1.

1. 1

J11 1
""

Objective-C

. , ,
:
, ,
.

(K&R 1.10). :
void myFunction() {
int i; // int
i = 7; // 7
} // ,
//

, :
, , , ,
.
, :

void myFunction() {
NSString* s = @"Hello, world!";
NSString* s2 = [s uppercaseString];

//
//

//

// ...

NSString
NSString

..

- ,
, ,

REALbasic

Ruby).

Objective-C

.
, ,
. (

Objective-C
12) ,

. ,

ARC

, ; -

, - ,
.

Objective-C .


, .
, .

1),

Objective-C

; . , ,
, .

3.

void.

11 611

Objectlve-C

65

Objective-C

; , ,

ero


, ,
r .
r,
. , ;

. :

NSString* s2

[s uppercaseString]; //
// "uppercaseString" s
11 s2

, ,
r :

[myStackl push: @"Hello"]; // myStackl


11 "push:"
11 NSString @"Hello"
( ),
:

NSString* s

[NSString string];

//
//

"string"
NSString

( )
, ( ) :

NSString* s
= @"Hello, world!";
NSString* s2
= [s uppercaseString];

// s
// NSString
//
// "uppercaseString" s

, , ,
. , @" l

NSString* s2

NSString,

lo, wor ld ! "

[@"Hello, world!" uppercaseString];

,
,

ero

ero , ,
uppercaseString NSString.

push:

r r .

,
.
. , ,

hereAreThreeStrings: : : .

r ,

, ..

[someObject hereAreThreeStrings: @"stringl" : @"string2" :

66

1.

@"string"];

, ,

, .
, , , ,
, .

UIColor, UIColor
CGFloat, , , ,
colorWi thRed: green: ue: alpha:.
. colorWi th :
,

. , Red:green:ue:alpha:,
. :

UIColor*

[UIColor colorWithRed: . green: 0.5


u: 0.25 alpha: 1.0];

thContentsOfFile: encoding: error:.

NSString stringWi

, ,
( ).

Objective-C,

(
), , ,
a:getBytes:maxLength:usedLength:encoding:options:range:remainingRa

nge : .

Objective-C.

, ,
.

n
,
,

. ,

Apple

. , .
ft.

+ -, ,
.

.
, .
, ,
.

, ,

Red: green: ue: alpha:

Apple

UIColor

+ (UIColor*) colorWithRed: (CGFloat) red


u:

(CGFloat)

colorWith-

green: (CGFloat) green


alpha: (CGFloat) alpha

( , ,

.
.)

3.

11

Objective-C

67

11
, , ,

+ -, ,
.

-, , .
,
,

iOS 7 , iOS 7

iOS 6:

-[NSScanner scanUnsignedLongLong:]
.

Objective-C.

, ,

NSScanner

scanUnsignedLongLong:.

, !
: "

- colorWi thRed: green: ue: alpha:.

11,

CGFloat UIColor~

..

. ,

\~
'---~~.

.
.


, ,
, . ,
. :

11 , :
NSString* s [[NSString string] uppercaseString];
,

string NSString
NSString (, NSString*},
NSString .

[myStack push:

string]]; // ,
// push: NSStrig*

[NSStrig

.
( ).

, ,
.
.

NSArray* arr

[[MPediaQuery

albumsQuery] collections];

68

1.

MPMediaQuery* query = [MPMediaQuery albumsQuery];


NSArray* arr = [query collections];

query

collection

),

. , ,

alburnsQuery
9).

(.

.
,

( [ [query

11 t

i n s ] ] )
([ [ query collections]) "Expected identifier"
(" ").

r
,

, .

( )
, .

, ,

MyClass
void, - NSString.
MyClass rnyMethod:,
void, CGFloat, - NSString.

rnyMethod,

"duplicate declaration"

(" ").

, , ,

, .
, ,

rnyMethod: CGFloa t, - NSString,


rnyMethod:, Objective-C
. Objective-C . ,

,
,

, ,
,

Objective-C

Objective-C

arrayWi thObj ects:

NSArray,

, ,
, . ,

NSArray. ,
nil. ,
, NSArray ),

NSArray (nil

, , .

11

3.

11

Objective-C

69

, :

NSArray*

[NSArray

arrayWithObjects:@"anny",

@"Jack", nil];

@"",

061.

arrayWithObjects:

, , :

+ (id)arrayWithObjects: (id)firstObj, ... ;


( 061.

nil

id.)

, ,

-
NSArray .
- nil,

, ,

Objective-C ,
- "missing sentinel in method dispatch".

, !

nil

,
),

arrayWi thObj ects:

LLVM 4.0 (Xcode 4.4

NSArray ,

@[ ] :

NSArray*

@[@"anny",

@"",

@"Jack"];

, " "

arrayWithObjects:,

nil,

arrayWi thObj ects:

( ).

Objective-C,
nil.
, UIAppearance appearanceWhenContainedin:
ini tWithTitle :messaqe: deleqate: cancelButtonTitle: otherButtonTi
tles: UIAlertView. , Apple - Objective-C (
:), nil; ,
,

, , .


Objective-C arrayWi thObj ects: "

~ ,
, , , .

K&R 7.3.

r
,

Objective-C.

. , ,

, , . -
? , , ,
, :

[s uppercaseString]

70

1.

s , uppercaseString - .
uppercaseString s. ?

114 114 '


. ,

- . ,
s? , .
nil. . , ,

. , .
114 114
. ,
, , .
, , , ,
, , .
; .
, , ,

. ; .
, , ,
". , , ,

. ,

, ,


, , :

nil

, .

nll

nil.

nil

ARC)

, - . ,

nil

, ,

nil,

,
,

nil.

( 7~

, .)
, ..

NSString

nil.

NSString :

* s2 - [s uppercaseString];

uppercaseString s. s
NSString. s nil? -
ccl11J<e nil

(
,

nil

REALbasic Ruby).

Objective-C .

Objective-C

. ,

3. 11 611 Objectlve-C

71

NSString* s = nil;
NSString* s2 = [s uppercaseString];

//
//

nil:

s nil
s2 nil
,

Objective-C

.
, ,

nil,

, . ,
, ( , )
,

(
).

nil

- ,
nil .

. ! ,
, "
"

, , ,

nil

nil

, - ,

( , , ).
,

9).

, ,

nil.

nil,

, -

- ! ,
nil stringWi thContentsOfFile: encoding: error: -

. , ,
, ,

nil!

n n
m ,
. , :

; .

, , , - ;

, :

NSString* s = @"Hello, world!";


[s rockTheCasbah];

NSString

rockTheCasbah.

ARC

, ,
. ARC

72

1.

"No visile @interface f 'NSString'

declares the selector 'rockTheCasbah~ ( ARC ,


ARC , m
.)
,

MyClass,

ARC.
rockTheCasbah.

MyClass* m = @"Hello, world!";


[m rockTheCasbah];
,

m-

NSString.

MyClass,

, .

("incompatile

pointer types"),

. .

NSString

rockTheCasbah,

( )

rockTheCasbah]: unrecognized
selector sent to instance 8650.

-[~NSCFConstantString

(unrecognized selector)

. "" "~
, ,
.

- [ __ NSCFConstantString rockTheCasbah]
,

NSCFConstantString rockTheCasbah. (
NSString NSCFConstantString
.)

8650

; ,

."..

.......

m.

'

, -

"'

~---4'

Objective-C "" , 11

, m , ,
, .

exception"

"Terminating

due to uncaught

( - ).

,
, , . ,
, , . ,

, , , .
, , , ,

. , ;

n11

3. 11 1111 Objectlve-C

73

, .,

, ,
,

.
,

"unrecognized selector~

, !

, .

id

, ,

, , ,
,

, , .

, . . ,
(.

1).

, .
. , ; ,
.

. .
(.

4),

Controller

UINavigationController. topView
UIViewController.

UIViewController.

. ,

topViewController, ,

, . .

[[navigationController topViewController] setAlburns: arr];


;

"no

visie

@interface", .. topView
Controller UIViewController, UIViewController
setAlbums.
,

J<

RootViewController

RootViewController.
setAlburns; . ,

- , . !
, , , ,
, , topViewController, .

RootViewController.

[(RootVieWController*) [navigationcontroller topViewController]


setAlburns: arr];
. .
,

setAlburns:, RootViewController
setAlburns:, .
, nry : topViewController
u RootViewController.

74

111

1. w

. !

MyClass* m @"Hello, world!";


[m rockTheCasbah];
"incompatile

pointer types"

); :

rockTheCasbah

("unrecognized selector")

NSString.

MyClass* m (MyClass*)@"Hello, world!";


[m rockTheCasbah);
, . :

rockTheCasbah,

NSString.

: ,
, .

""
.ll,
'

\~ "
~---~

. (MyClass*)@"Hello,
world!" NSString,

@"Hello, world!

",

MyClass!

- .

, ,
id.

Objective-C

.
,

id*.

" ~ .
, id.

id

. ,
, (
- ) . ,

id , id
id ,

.
; , id
, r . (

i d :
id:

.)

NSString* s @"Hello, world!";


id unknown s;
[unknown rockTheCasbahJ;
,

id

id.

. (,

, ,

unknown NSString rockTheCasbah!)


n111

3.

111

Ob)ectlve-C

75

ARC

.
:

"No known instance method for selector 'rockheCasbah~ ,


rockTheCasbah . rockTheCasbah

, ,

rockTheCasbah

nil,
nil ; r
, nil. , id
, , id nil ;
nil ,
id

. ,

, , .
,

id

. , , ,
.

id . - r;
.

id.

, . ,

id

API

, ,

, -
.

, ,

NSArray,

. ,
; , " int~

Objective-C,

NSArray, . NSArray
id, , .
NSArray ,
id (id ).
NSArray , id
(id ).
lastObject NSArray, ,
id. arr NSArray
:

id unknown [arr lastObject];


. r

unknown

; .

, , r

, . , , ,

arr

NSString

). r

NSString* s [arr lastObject];


,

id
(id ). ,
NSString

, ,

76

111

1.

, ,

NSString.

NSString,

r r

. ,

NSArray

NSArray
, lastObject id,
, NSString.
NSString.

r ; r ,

. , ,

uppercaseString s. : ,
NSString, uppercaseString NSString.
s NSString, , , r

r.

id . r

, r r (

) , r.

r, , r
, r. - ,

, , :
r . -

id,
ARC : "Multiple methods named
'rockheCasbah' found with mismatched result, parameter type or attributes" {
rockTheCasbah ,

). , r:
r, ,
r r r .


r r ,

Objective-C

, . :

Objective-C

, .
,

ero

.
, ,

NSNotificationCenter

- (void)addObserver:
selector:
name:
object:
( r

11)

(id)notificationObserver
(SEL)notificationSelector
(NSString *)notificationName
(id)notificationSender

, . ,

r ,
. , r ,

tickleMeElmo:

myObj ect. r

, .

(observer:)
id,

r .

3.

61111

Objective-C

77

observer:
selector:,

myObject.

SEL.
tickleMeElmo:.
tickleMeElmo: :
. , NSString, ..
@"tickleMeElmo: ", . ,
,

@selector(tickleMeElmo:)

@selector ()

:r , ,

, , .
,

NSString;

,
.

: ,

@selector.

SEL,

myObj ect
@selector ( tickleMeElmo),

, , .

tickleMeElmo:,

, ,

myObj ect,

tickleMeElmo

, , -

Xcode 5, Objective-C, ,
("Undeclared selector 'tickleMeElmom).

observer:

, . :

tickleMeElmo

- ,

, ,

tickleMeElmo,


, ,

Objective-C, ,
1,

. ,

CGPoint,
CGPointMake, :

CGPoint CGPointMake
CGFloat ,
CGFloat
);

, , ,
.

Objective-C
Objective-C

, ;

, ,
.

78

1.

. ,
; , -
, , ,
.
, ,

" ':

ArrayUsingFunction: context:

NSArray.

sorted

NSinteger (*) (id, id, void *)



,

NSinteger.

id, id void ( ).

(.
,

sortedArrayUsingFunction: context:,

1).

, ,
.

NSArray

NSString

. (,

, !)

NSinteger,

, : , ,
.

NSString,

NSinteger

compare:
3.1
sortedArrayUsingFunction: contex

t : .

3.1.

NSinteger sortByLastCharacter(id stringl, id string2,


void* context) {
NSString* sl = stringl;
NSString* s2 = string2;
NSString* stringlend =
[sl substringFromindex: [sl length] - 1];
NSString* string2end =
[s2 substringFromindex: [s2 length] - 1];
return [stringlend compare:string2end];
}

11 (,
11 arr NSArray NSString)
NSArray* arr2 = [arr
sortedArrayUsingFunction:sortByLastCharacter
context: nil 1;

CFTypeRef
r

Objective-C

.
,

NSString, Objective-C , CFString; "CF"


"Core Foundation" API
. CFString "" ; "" ,
, , CFString

3. 11 11 Objective-C

79

CFString

NSString

CFString CFStringRef.
,
. , ,

NSString,

CFString. , NSString (,
( CFStringRef) :

NSString*)

CFString

, , , ,
. .

CFString

NSString,

, (

CFString,

NSString

intValue):

NSString* answer = @"42";


int ans - CFStringGetintValue((CFStringRef)answer);
, ,
, Ref~

void.

CE1'ypeRef,

, ..

id

void*

void*

id. ,
NSString

CFString) ,
id NSObj ect ( , . 4) CFTypeRef.

..

611
,

iOS 4.0.

OS 10.6

Objective-C.

3.1,

. ,
.

3.1
sortedArrayUsingFunction: context:
sortedArrayUsingComparator:, .

NSComparisonResult

()

(id objl, id obj2)

*. , id
NSComparisonResult ( NSinteger,
, 3.1).
sortedArrayUsingComparator:, 3.2.

3.2.

NSArray* arr2 = [arr sortedArrayUsingComparator:


NSString* sl = objl;

80

1.

(id

objl, id obj2) {

NSString s2 = obj2;
NSString stringlend = [sl substringFromindex: [sl length] - 1];
NSString string2end = [s2 substringFromindex: [s2 length] - 1];
return [stringlend compare:string2end];
)];


O(id

objl, id obj2)8
11 . ..

"

8
8

, .
, .

. .".

\ti~,'

.
,

~-_,..""

",

return,

3.2, ;
sortedArrayUsingComparator:,

. ,

, ,
(

3.3).

3.3.

NSComparisonResult (sortByLastCharacter) ( id, id)


(id obj 1, id obj2) {
NSString sl = objl;
NSString s2 = obj2;
NSString stringlend = [sl substringFromindex : [sl length] - 1];
NSString string2end = [s2 substringFromindex: [s2 length] - 1];
return [stringlend compare:string2end];
);

NSArray arr2
NSArray arr4

=
=

[arr sortedArrayUsingComparator: sortByLastCharacter];


[arr sortedArrayUsingComparator: sortByLastCharacter];

, :

, ,
, ,
. ( ,
. )

,
.

CGPoint = [v center];
CGPoint pOrig = ;
. += 100;
void (anim) (void)
{
[v setCenter: ];
);

void

(after)

(BOOL)

(BOOL f) {

11

3.

11

61111

Objective-C

81

[v setCenter: pOrig];
};

NSUinteger opts = UIViewAnimationOptionAutoreverse;


[UIView animateWithDuration:l delay:O options:opts
animations:anim completion:after];
.

options: animations: completion:

laoiii animateWi thDuration: delay:

; , , ,

, ,
.

CGPoint

CGPoint pOrig.

v UIView,
pOrig -

.
,

v.

,
, ;
"variale

is not

assignae" (

):

CGPoint ;
void (lk) (void) = {
= CGPointMake(l,2); //
};


_k.

,
, . :

_ bl ock

, .

enumerateObjectsUsingBlock: NSArray

for ... in,


1). ,
; , (di r)
(

. ,

.
_k, :

CGFloat h = newHeading.magneticHeading;
NSString* dir = @"N";
NSArray* cards = @[@"N", @"NE", @"", @"SE",

_k

@"S",

[cards

@"SW",

@"W",

@"NW"];

obj,
NSUinteger idx, BOOL *stop) {
if (h < 45.0/2.0 + 45*idx) {
dir = obj;
*stop = YES;
enumerateObjectsUsingBlock:(id

}];

82

//

1.

dir

( , L.

;
, .

for.

YES

break,
enumerateObjectsUsingBlock:
BOOL

iOS,

.)

_k .
, ,
, , ,

. ,
, ( )
().
,

beginBackgroundTaskWi thExpirationHandler:

UIBackgroundTaskidentifier,
- ,

. :
, , ,
. _k :

UIBackgroundTaskidentifier bti =
[[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:
[[UIApplication sharedApplication]

~k

endackgroundTask:bti];

}] ;

Objective-C , Apple
Grand Central Dispatch (GCD),
GCD ,

,
. ,

GCD

). , "

UIView vl,

, ":

dispatch_time_t popTime

2 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), (void) {
CGRect r = [vl bounds];
r.size.width += 40;
r.size.height -= 50;
[vl setBounds: r];
dispatch_time(DISPATCH_TIE_NOW,

}) ;

1,

-.

1)

GCD dispatch_once -

( )

. , ,
:

3.

11

11

Objective-C

83

+ (CardPainter*) sharedPainter {

static CardPainter* sp = nil;


static dispatch once t onceToken;
dispatch_once(&onceToken, !
sp = [CardPainter new];
));

return sp;

_k,

sp
sp static, ,

: , _k

static
ero -
sp ,
. ,
k.

Apple
http: / /developer. apple. com/library/ios/idocumentation/cocoa/
Conceptual/Blocks/, "Blocks Programming Topics"
Xcode.
http://clang.llvm.org/docs/BlockLanguageSpec.html.

84

1.

Objective-C

Objective-C,

;
.

n n

Objective-C,

- ,

. ,

Quadruped ()
Dog.

Dog (},

Quadruped

, .

"~ ,
, , , "4,
"4, .

, ,
, ,

.
(!) ,

.
, ,

.. Xcode (.

4.1):
IOS VlewQNavigatorsQShow Symbol Navigator

Hierarchical ( )

Ulaaponcler

"

AppOe/eptll

" 1.1 UIApplkallon

llU.W

" 11 UIAttlon5hut

".~
".uw..w

""~Vlew

" 11
~
" 11

Ullullan

U.O.flcker

" l.l IJlll8pCOl'llral


"
"

&lllfreshConlro
Ul51. . .1118dCanlnlf

11 Ullllr
" . . u&lpplr

" 11 UISwltdl

4.1. : Xcode

- ,

. , ,

Dog

t,

. , ,

walk ()
Quadruped Dog Cat Quadruped.
, Dog, Cat walk,

, ,

walk.

, .

r . . ,
, , :

: .

Dog

, ,

Dog , -,
Quadruped - , , -
. bark
Dog walk Quadruped Dog Quadruped, Dog
Quadruped, .

Quadruped.

, .
, , , r. ,

86

1. 1

NoisyDog, Dog. Dog bark,


NoisyDog bark, , Dog.
(overriding). ,

., ,

, ,
.

, .

11
2, . .
- , . . " "
Objective-C. Objective-C , , " .

, ,

. - "?
. , . ,
, .
, .

MyClass.

, . :

@interface MyClass
@end
@implementation MyClass
@end

@interface @implementation
MyClass;

. ,

@end ,

. .

MyClass

. .

, - :

@interface MyClass
@end
@irnplementation MyClass
- (NSString*) sayGoodnightGracie
return @"Good night, Gracie!";

1
@end
, .
, ( ),
, , (

3).

, , ,
(

1).

- ,
. , ,

, , ,

NSObj ect.

NSObj ect

NSObj ect,

NSObj ect. (
Xcode S ,
"Class 'MyClass' deflned without specifying bue class" ( MyClass

)).

11111

4.

111

Objectlve-C

87

@interface:

@interface MyClass : NSObject


@end
@implementation MyClass
- (NSString*) sayGoodnightGracie
return @"Good night, Gracie!";
@end

NSObject -

, r ,

NSProxy,

.
r pyroro

ero NSObj ect.

r
. , , r r
, .

r
() :

@interface MyClass : NSObject


- (NSString*) sayGoodnightGracie;
@end
@implementation MyClass
- (NSString*) sayGoodnightGracie
return @"Good night, Gracie!";
@end
( r
. , r .)
.

( , ),
.

Objective-C ,

, ,
r

S, 12.

; , .
r
:

@interface MyClass : NSObject {


11 l!'l' &

- (NSString*) sayGoodnightGracie;
@end
@implementation MyClass
- (NSString*) sayGoodnightGracie {
return @"Good night, Gracie!";
}

@end

LLVM 3.0 ( Xcode 4.2

) r
. r , ,

88

1. 1111

, r ,
, r
, .
:

@interface MyClass : NSObject


- (NSString*) sayGoodnightGracie;
@end
@implementation MyClass {
11

- (NSString*) sayGoodnightGracie {
return @"Good night, Gracie!";
@end
(, ,

, , .)

5.

rn n n n
,

, .

- ":
- .
(. #import 1),
,

, , .
, , MyClas s.
,

MyClass. h

MyClass .m.

.)

MyClas s h, .
MyClass .m, w.
. , Xcode,
, ,

. h-

. m-,

(Navigater::>Jump to Next Counterpart).

.
;

IOS UIKi t. h (. 1).


UIKi t . h, , , ,
. ,
, .

4.1 ;
MyOtherClass, MyClass.

4.1.

11 MyClass.h:

fimport <UIKit/UIKit.h>
@interface MyClass : NSObject

11

4. n Objectlve-C

89

- (NSStrinq*) sayGoodniqhtGracie;
@end

11 MyClass.m:
timport "MyClass.h"
timport "MyOtherClass.h"
@implementation MyClass {
//

- (NSString*) sayGoodniqhtGracie {
return @"Good night, Gracie!";
)

@end
, .

; , ,
, .

, .

4.1:
MyCla~s UIKi t. h,
MyClass
NSObject.
MyClass MyClass. h,

J1 .

MyClass NSString
UIKi t, UIKi t. h.

MyClass MyOtherClass. h,
MyClass MyOtherClass (,
, ).

u , ,
. , ,

MyClass

, MyOtherClass,

MyClass. h MyOtherClass*;
, MyClass. h MyOtherClass. h.
MyClass. h MyOtherClass,
. ,

@class.

@class

, .

MyClass. h

timport <UIKit/UIKit.h>
@class MyOtherClass;
, , .
: " ,

MyOtherClass, -

@class

': , ,

MyOtherClass*

90

1.

1,

, ,

NSString,

tdefine

@"mykey"

: ?

, (
). ,

; ,
, ,
.
( ,

. h- , " ':
. h- h- 6.)

3r
,

4.1:

( )
. .
;
,

. ,
, ( ).

, ,
(.

8).

n
.
1

- , . ,
UIFont fontWithName: size:.
UIFont UIFont,

. , -

1),

(.. ; .

13),


. ,

UIFont

familyNames.

4. n Objectlve-C

91

(..

NSArray

NSString),

, .
,

UIFont

ero .

, , ,
. , ,
, .

n

. ,

familyNames

UIFont,

NSArray* fams

[UIFont familyNames];

, , (

2),

.
.
, ,

. ( , ,

MyClass,

MyClass,

NSString,

.)

UIKi t. h

, .


. ""
( ).

[UIFont familyNames]

familyNames

UIFont.

NSString*

NSString,

, ,
. , m

class

. ,

[MyClass class]

.
,

Class.

, .
, , , .

isKindOfClass:

(OOL)isKindOfClass:

(Class)aClass

, :

if ([someObject isKindOfClass: [MyClass class]]) // ...

92

1.

,
. , ,
. ,

id classObject

id:

[MyClass class];

, ,
:

id classObject = [MyClass class];


[classObject someClassMethod];

Class,

Class classObject = [MyClass class];


[classObject someClassMethod];
,

someClassMethod

.
(

3).
id, Class

, .

, .


,
. Objective-C ;
, . ,
( ) ,
. :

(NSString

NSArray, CGFloat

CGRect

..).

Apple

; ,

Xcode,

Apple!

, ,

. , Apple
, " .

4. n Objectlve-C

93

Objective-C

Objective-C.

, .

.

, .

n
,
.
:

(.

4).

nib.

nn

, ,

. , , "
': ( , .)
:

NSString* s2

[s uppercaseString];

uppercaseString

NSString

",
". ,

uppercaseString
NSString , ,
NSString. s2
NSString, .

NSString, uppercaseString,

. ,

uppercaseString.

, -

, ;

NSString.

"-", ,

NSString.

. ,

NSString,

, .


. , ,

ding:error:

NSString

stringWi thContentsOfFile: enco

. .
, .

NSObject,

alloc.

alloc

, .

, ,
. (

12.)

, , 11

alloc

, ,
, ,

. . ,

, . ,

( )

alloc .
ini t. ,
5.1.

"alloc-init':

5.1.

SomeClass*

wn n
aVariae =

[[SomeClass alloc] init];

, , ,
.

n
.

alloc,

alloc

.
,

alloc,

5.1,
alloc!)

, (

. ,

- ,

nil;

96

1.

alloc!)

nil.

,
, ,

ini t.

ini t

. ,

ini tWi th, .


NSArray :

initWithArray:
initWithArray:copyitems:
initWithContentsOfFile:
initWithContentsOfURL:
initWithObjects:
initWithObjects:count:

3,

NSArray ,
arrayWithObjects :,

,
,

nil,

NSArray* =
[NSArray arrayWithObjects:@"Manny",

@"",

@"Jack", nil];

, , N S r r
ini tWi thObj ects:, , arrayWi thObj ects:.

, ,
, ,
,
,

3,

alloc.

NSArray* =
[[NSArray alloc]

initWithObjects:@"anny",

@"",

@"Jack", nil];

Objective-C, 3,
ini tWi thObj ects:,

arrayWi thObj ects:

,
:

NSArray*

@[@"anny",

@"",

@"Jack"];

. , , ,
, ,

@"Manny",

@""

@"Jack",

, . ,

NSArray*

//

NSArray

,
, (

3).

; , , , ,

. ,

NSArray*

2 =

arrayWi thArray:

[NSArray arrayWithArray:

];

2 , .
, . ,

5.

n11

Objectlve-C

97

initWithArray:.

, :

NSArray*

[[NSArray alloc] initWithArray:

];

,
, , ,

. , ;

, . (
,

12,

ARC , , .)

UIWebView
UIWebView UIView, UIView
ini tWi thFrame:. , ini t
NSObj ect, , ini t
. ,
,

. ,
,

...

ini t.

UIResponder
UIResponder

. ,

...

~
\~
'---~". .'

alloc

init .

ini t,
i ni t
new. , [MyClass new]
[ [MyClass alloc] init]. ,
, ini t;
alloc
11

n
,

. ( , ,
; ,
.) ,

UIView

initWithFrame:

. , ,
.

, ,

ini t.

, .


. , ,
, ,
: .

. ,

(
).
. .

98

1.

NSDate , in
i tWi thTimeintervalSinceReferenceDate: (,
ini tWi thTimeintervalSinceNow:) .

UIView ,
UIView ,
. UIWebView, UIView,
, ini tWi thFrame:
( ). UIImageView, UIView,
, ini tWi th!mage:, ;
, ini tWi thFrame:
, ini tWi thimage: ini tWi thFrame:.

ini tWi thFrame:.

, ,
, ,

NSDa te
,

ini t
initWithTimeintervalSinceReferenceDat

: , , , .

UIView

ini t
ini tWi thFrame:, CGRectZero.

nn n

nib

ni-. Ni-

. storyboard-aa

, "" .

Xcode . storyboard-

. i-, , ,

ni- .
ni-

. Ni-

.
ni- ,

. ,
,

. storyboard-

.
, , ,
,

"Howdy!': Xcode
. storyboard- . i-.
, . 5.1.
"Howdy!': . 5.2.
,

, ,

ni-,
. .
, ,

UIButton.

UIButton

, ,

5.

nn11

Objective-C

99

(
(

frame

), ,

), . ,

title

ni- ( ,

self. view

).

UIButton* =
[UIButton

11

buttonWithType:UIButtonTypeSytem];

[ etTitle:@"Howdy!"

forState:UIControlStateNormal];
[ etFrame:

CGRectake(l00,100,52,30)];

[elf.view addSuview:b];

11
11
11

5.1.

5.2.

UIButton

, .

ni- ni-
,

(outlet).

, ni-
ni-,
, .

7.

, . ,

UIControl,

UIView.

UIButton

UIButton* [UIButton buttonWithType:UIButtonTypeSystem] ;


UIView* v - ;

100

1.

UIButton, ,
UIView
( ) UIButton. ,
, UIButton UIView, r
- , UIButton UIView.

UIView.

,
, . r,

UIButton v, , v,
UIButton. , , v ,
UIButton, ,
UIButton, UIButton.

UIButton* = [UIButton buttonWithType:UIButtonTypeSystem];


UIView* v = ;
[v setTitle:@"Howdy!" forState:UIControlStateNormal];

UIView

setTi tle: forState:.

UIView, , ,
UIButton, setTitle: forState :.

r ,

v ,

ARC)

.
:

UIButton* = [UIButton buttonWithType:UIButtonTypeSystem];


UIView* v = ;
[(UIButton*)v setTitle:@"Howdy!" forState:UIControlStateNormal];
r ,
. ,

UIButton

}, ,

UIButton.

( ;

, r

; , r,

r , , r

setTitle: forState:

r ,

v, . r , v

UIView,

UIButton, r

180 r. UIButton

UIView UIButton.
UIButton UIButton,
UIView.

, ,

ero ,

r . ,
, r-

. :

UIButton* = [UIButton buttonWithType:UIButtonTypeSystem];


[ setFrame: CGRectake(l00,100,52,30)];
.

UIButton. , .

setFrame:
UIButton

11111

5. 11 Objective-C

101

UIControl, UIControl J1 UIView.


setFrarne:, UIView. (, ,
, setFrarne: . frarne, J1

"~ , .)

setFrarne: J1 UIButton, ,
UIView. , UIButton
S11m UIView.

".

'

".

CJI , .

...._"_"_--~ , UIButton,

UIButton:
UIControl, UIView ..

UIView, ( )
UIButton. UIButton
UIView.

UIButton

UIButton,

( )

, - ,
JI; , JI

, , JI .

J1 , , ,
, , J1.
, nJI , ,
. J1
, , .
JI , J1
.

, . ,
.

lllOIBOI

self

, , ,
, .
, . JI ;
? sel f. :

aimplementation MyCla11
- (NSStrinq*) qreetinq (
return a 11 Goodniqht, Gracie! 11 1
- (NSStrinq*) sayGoodniqhtGracie
return [selt qreetinq];
1
aend
r sayGoodnightGracie MyClass,
sayGoodnightGracie. greeting

self. greeting;
@"Goodnight, Gracie! ",
sayGoodnightGracie.

102

11

1. 111

, .

, .

self.

self

self.
-

" ': ,

? , ,

self.

, ,

MyClass

sayGoodnightGracie

MyClass thing [MyClass new];


NSString* [thing sayGoodnightGracie];

thing.

MyClass
sayGoodnightGracie thing, ..

, . , ,

- MyClass. , MyClass
sayGoodnightGracie, . ,
self. ",
': , thing.
greeting (. 5.3).

MyClass

- (NSString*) greet1ng {
return t"aoodnight. arac1el";
(NSString) sayGoodnightaracie {
return [self greeting]i

vClass: thlna
.

5.3. t self

11111

5. sn1111 Objectlvt-C

103

, ,

. , r
. , r r
.

Dog ark.
Dog speak,
ark. , Basenj i Dog,
ark. , !(r speak
Basenj i, 5.2?
,

5.2.

@implementation Dog
- (NSString*) bark (
return @"Woof!";
- (NSString*) speak {
return [self bark];
@end
@implementation Basenji
Dog
- (NSString*) bark {
return @""; 11 , Basenjis

@end
11 :
Basenji* = [Basenji new];
NSString* s = [ speak];
self " , r

~ r speak Basenj i,

speak Dog ( speak ),

r bark Dog. ,
; @"Woof ! ", Basenj i . ,
, self . , .
. speak
Basenj i, . Basenj i speak,
, speak Dog.
speak Dog; speak ,
self. ",
~ Basenj i.
ark Basenj i. Basenj i
ark, ,

(.

5.4).

, Basenj i ark, r ark


Basenj i, , ,
Dog, ero. ,
self , ero .
r k

r , , . ,
,
-r . (, r -

104

1. J

, - ,

2.

, , -

-.)
Dg

- (NSString*) bark {
return t"Woof 1;
}

- (NSString*} speak {
return [sel bark];

asenJI

5.4. , ,

self

n n SUPER
( )
, .

super.

self,

super

, m .

" " .

super

: " "

( " " ,

super

super).

, , ,

( ,

,
).

5.

1n11

Objectlve-C

105

, ,

Dog.

NoisyDog,
bark, :

@implementation NoisyDog : Dog


- (NSString*) bark {
return [NSString stringWithFormat: @"%@ %@",
[super bark], [super bark]];
}

@end

bark

super;
stringWi thFormat:)
bark @"Woof ! ",

(
.

Dog
NoisyDog bark @"Woof ! Woof ! ". ,
: bark NoisyDog .

, ,

super, ~;s r @"Woof ! "

bark NoisyDog

: - ,

bark NoisyDog . , bark


Dog @"Arf ! ", bark NoisyDog
@"Arf ! Arf ! ", .
r ~

ero

. ,

viewDidAppear:,

UIViewController,

- (void)viewDidAppear: (BOOL)animated
r,

UIViewController

, r

. r,

UIViewController

, ,

, "
"

super" -

super

r , "

super

r, ~
, viewDidAppear: UIViewController,

MyViewController.

- (void) viewDidAppear: (BOOL) animated


[super viewDidAppear: animated];
11

...

viewDidAppear:

MyViewController
UIViewController

viewDidAppear:, ,
MyViewController. ,
UIViewController, . r
super - super !

, ,

r.

106

111

1. 1

3, , ,

, , .

, ,

4,

, ,

Objective-C,

, , ;
,
.

" "

(instance variale)

ivar.

, . ,

Dog ,

int.

.)

Dog ,

( , ,

Objective-C , , numer

Dog:

@implementation Dog {
int numer;
}

11
@end

( , , , ?

NSString,

, ,
, . ,

, .

12.)

Dog

numer, . , ,
: : numer , ,

: elf->ivarName. "~
"" "'~

(K&R 6.2).

self-> _ivarName,

_ivarName. ,
_ivarName ,

.
,
, ,

11111

5.

n11

ObjtctlveC

107

, r
. ,
; . r

11.

r
r. awero
r r

( } r .
; ,
, r , r

r . ,
, r, r . r-

numer r

Objective-C;

Dog, r
Dog.

, , r

. r .
r:

setXxx: , r "" (
}. , r setNumer: numer.

Dog setNumer:,

numer:

- (void)

(int) n {
n;

setNumer:

self->numer

, r setNumer: r r
,

Dog. h Dog,

ero Dog:
@interface Dog : NSOject
- (void) setNumer: (int) n;
@end

Dog. h Dog -

Dog* fido [Dog newJ;


[fido setNumer: 42);
numer

ero

( r

Dog,
Dog}. r

, , numer,
numer:

- (int) numer {
return self->numer;

Dog. ,
Dog. h, ,
numer Dog:

Dog* fido [Dog new];


[fido setNumer: 42);
int n [fido numer];

108

111

1. J11111

// ,

42!

Objective-C

11 (

12).

, ll}'I

. (, , ,
, ;

2.0

Objective-C

, ?

.)

Dog

numer, ll}'I

numer. . ,

. , .

}'I .
:

-
_ numer, numer. ,

( )
:

@implementation Dog
int _nner;
- (void) setNner: (int) n {
self-> nner = n;
- (int) numer {
return self->_nner;
@end
,

alloc).

, , , ,

, , . :

@implementation Dog {
int _nner = 42; //

Objective-C!

, _numer ,
, , .

BOOL NO,
BOOL, , ,

nil.

, , .

nil).

n-

Objective-C

(key-value coding).

, , .

5. nn Objective-C

109

JI .
-

valueForKey:;


J1

setVal ue: forKey:.

, , , numer

fido

fido.

valueForKey:

@"numer". , , numer

int,

val ueForKey:,

J1

NSNumer, (.

10).

J1

int,

intValue

NSNumer, :

num = [fido valueForKey:


int n - [num intValue];

NSNner*

@"nner"];

, -
setNumer:

fido,

J1

num - [NSNner nnerWithint:42];


[fido setValue: num forKey: @"nner"];

NSNner*

42 setValue: forKey:
- NSNumer.
LLVM 4.0 (Xcode 4.4) ;
NSString, @" ... ",
NSNumer, @ ( ... );,
J1 , @.
"" ,

num = @42;
[fido setValue: num forKey:

NSNner*

@"numer"];

, ,

num

[fido setValue: @42 forKey:

@"numer"];

-
. , @"numer"

(, ).

something.

id result - [fido valueForKey: something];


, J1 .

Objective-C

, JI
.

valueForKey:

setValue: forKey:,

, JI. ,
@"numer", J1 numer setNumer: ( ).
, .
, , ,

, (

110

11t

1. s

)!

,
, r . (

r r

12.)

r r

Objective-C,

. r , r,
.
(
), r

( ).
.

Dog.

Dog

numer
setNumer:,

Dog

numer,

. ,

[fido
int n

42];

setNumer:

[fido

numer];

fido.numer =

int n

42;

= fido.numer;

.
;

. .

Dog

(numer setNumer:



self.numer =

self,

),

(numer).

JVIacce, ,

42;

.
self->numer

n,

numer

n,

(
,

).

fido. numer

self. numer

,
, , ,

12,

, . -

5.

nn11

Objectlve-C

111

,
.

,

[

setFrarne:

UIView

UIButton:

setFrarne: CGRectMake(l00,100,52,30)];

setFrarne: UIButton;
UIView. .
UIView .


frae

,
.

@property (nonatanic) CGRect frame

UIView

frarne.

UIView -

, , . (

nonatornic.) ,
UIView frarne setFrarne:;
f r arne , .
setFrarne:. setFrarne: ;
, frarne:
b.frarne

= CGRectake(l00,100,52,30);

Objective-C

; . , ,

frarne UIView ,
(CGRect); , rnyView. frarne. size. height, frarne
, , size
, height, , size.
; , , height
, UIView:
myView.frarne.size.height

36.0;

//

"Expression is not

assignae"

, , ,
,
, :

CGRect f = myView.frarne;
f.size.height = ;
myView.frame = f;

11
,

self

super

, . ,
, ,
, ,

112

1.

-
,

. ,

, Objective-C
. ,
.

, ,

contentView,

UIScrollView

, ,

setContentView:animated:.

. ,
.

(
).
,
. ,

numer

id,

Dog,

numer

,
, , ,
. ,

NSArray -

lastObject

; .

myArray. lastObj ect ,


[myArray lastObj ect J, ,

- .
,

. 11
, ,

Apple.

r r . , , ,

, r
. r ,

.

, ,

Dog

Dog

numer

r ;

Dog .
Dog

ero numer.
ero - .
, - .

11

5. :sn1111 Objective-C

113

, , .

Dog

, ,

setNumer: ,
numer
. numer

- (id)

initWithNumer:

(int) n;

id,

Dog,
Dog.

, . ;
,

ini t

, .

5.3).

, .

. ,

5.3.

- (id) initWithNumer: (int) n (


self z [super init] ; 8
if (self) (
self-> numer = n;e
return self;O
.

, .
, ,

super

self

,
.
,

ini t .
self.

( ) ,
-

self

self

( , " "

Objective-C), ,

, ,

self, .
nil,

self

. ,

; . ,
(
);
,
.

114

1.

( ,

, ,
. ,
. ,

.)

self.

. , ,

, (

init). , : , - [ [Dog
alloc] ini t] ( [Dog new]) - ,
.

ini t

numer

. , :
, :

- (id) init {
return [self

initWithNumer:

-9999];

, , ,

Dog:

Dog* fido = [[Dog alloc] initWithNumer:42];


int n = fido.numer; // n 42;

..

i d,

is

~----~.

NSString* s

[[Dog alloc]

initWithNumer:42];

//

LLVM, ,
ini t, , , id
instancetype, , , ,
, ( - Dog).

n
.

, ,

.
, ( ).

( ).
. ,

(NSArray):

id myThing

[myArray lastObject];

5. nn11 Objectlve-C

115

rnyArray NSArray , .
rnyArray r.

, r.

r r r . ,

UIApplication (
sharedApplication

r};

UIApplication:

UIApplication* theApp

[UIApplication sharedApplication];

r r ;
r .
,

ero,

r r r

ero

; ,

r .

13.

:
, (
, ) , r
.

iOS.

TQ, r

, .


, r

13.

. ,
. ,

ero r

. ,
, -. , r ,

, , , . ,
r,

r,
, r .

r, r ,
. r, r,

[UIApplication sharedApplication],

. ,

UIApplication ero , , r
ero . , ero ,
r [UIApplication sharedApplication], ,

, . r
, , ,

theApp

. r r .

(rnyArray)

[rnyArray lastObject].

ero

, . ,
r

myArray, r
myArray. r myArray.
myArray . ,
[myArray lastObject],

,
r r, r .

116

1.

[myArray
lastObj ect], myThing. , , ,
myThing .
myThing - ;

, (,
), .
? ,
; ,

Dog.
myThing,
Dog, .

Dog!

, ,

Dog,
myThing ! ,
.
,
.

n111

5. 11:1nn11 Objectlve-C

117

11

, ,

. , ,

IOS. Xcode -

Xcode,

Xcode.

Xcode.

Xcode.

, ..

, .

7 ni-.

Ni-

. ni-
,

.. ,

Xcode .

Xcode

9 ,

, ,

Store.

, , ,
, .

Xcode

Xcode - ,
IOS. Xcode - ;
. ,
, ,
. ,

Xcode

Xcode

Xcode
Xcode,

"Xcode" .

, .
, , .
,

Xcode.

Instruments

Simulator

Xcode - , .
Xcode , :
-, -
, - . Xcode

, .,

Xcode,

, .


Help~Xcode

User Guide);

Apple

, ,

, , - .

Xcode

Xcode 4.3.

Developer

Xcode 4.2

Xcode

r ,

Xcode
Xcode 4.3
Xcode. app/Contents/Developer.

Developer


, ,

Xcode

. r , , "" ;
, .

1.
2.

Xcode

Choose

FlleQNewQProject.

template.

. ,
, ; . ,
ayXcode.app/Contents/Developer/Platforms/iPhoneOS.platform/
Developer/Library/Xcode/Templates/ProjectTemplates/Application.

, ,
.

IOS

OS !)

Appllcatlon.

r Slngle Vlew Appllcatlon

3.

(Product Name).

Next.

Empty Window.

, n ,
. r Xcode ,
, ,
, . , ,
, . ,
. ,

. .

. ,
, , r Xcode

; , (,
, ),

4.

Product Name, .

Company ldentlfler. ,
, . ,
, .
com, ,
(, ),
. ,

com. neuburg. ma t t.

Store,

.
, ,

;
, ,
( ).

5.

Devlces

IPhone.

Class Preflx;

"XYZ"

. " ':)

122

11.

Next.

r11111 111

6.

Xcode,

. ,

Single View Application.xctemplate Project


Templates/Application, . , ~

Save.

Xcode

. .

7.

Xcode

- .

(.
.

8.

9),

Create.


),

Empty Wlndow (
Xcode Empty Wlndow.

Empty Window

IOS.

, ,


WlndowIPhone

Retlna (3.5-lnch).

Empty

, .)
ProductRun.

IOS Simulator

, , ,

(ProductBulld).

Xcode 5
[Filename]).

(ProductPerform ActionCompUe

Simulator

. ,

, (ProductRun),

Xcode

( ), .

storyboard

xib1,

, , ,
.

( , ..),
.

, .

n111

6. 111

n1

Xcode

123

Xcode,

,
. !

, .
, , .
(. .1 ):

1.1

(800L)epp\1cat1on: (UIApp\ica
d1d~in11hlunch1ngWithOption1:
\lnch0pt1on

11

Ovttde

i.unch.
rrtvrn YES J

point tor CU$toe1zat1on fter" epp11cat1o"


4.

1.

.,.}1;pp\lcetton
(NS01ct1onary )

6.1.

. ,

<Command+O>)

ViewQNavigatorsQShow/Hide Navigator (
View,

2.

( "").

.
.

3.

. ,

ViewQ UtilitiesQ Show/Hide Utilities (


<Command+Option+O>) View,

4.

.
,

0".

124

<Command+Shift+ >)

ViewQShow/Hide Debug Area (


View,

""

Xcode
Bindings Preferences.

, .

11. r11

11 r
r ,
. r, r,

r ( ).

Xcode r

: - r,

.
r ( Viewi:::>Navigatorsi:::>
Hide/Show Navigator <Command+O> ); ,
r r,
, r.
( ). r ,
.

r ;
, r. r

, r ;

(<Command+l>, <Command+2> ..).

r ,

. r .
r
r.

, , r
, r . ,

, r r
, r . ,
, ,

ero;

r, r r r.
r.

(<Command+l>)

, , . ,

AppDelegate .m

Empty Window

, r),
(.

( ,

ero

6.1).

r r r

Xcode r

Empty Window; , ,

. ,

! .
, r , r

; r,
. ,

"delegate"

. , r
.

r, ,
, !

: r, ,

n111 6. 11111

Xcode

125

(
, , )

: ", ?"

..

81n._.,.,d

001~.h

Vtewconaaler.m

......... -

Supponlng fflell

....

fmlllYa ....
...............
".....,..............
]

111u11

........
"_.,

.......,'lldDI

'8 8 pdt

6.2.

(<d+2>)

, . ,

,
, .

;
. ,

(.. ,
). ,

AppDelegate' s

applicationDidecomeActive:.

,
, .

, , ;
,

"active"

(<d+>)

(<Command+Shift+F>).

FindQFind in Project

, , ,

; ,

, .

"delegate"

(.

6.3).

, ,
.

126

11.

r1111

. ( ,
.)
And

>Text > Contalning

(. delegate

ln Projt

8 re1ults tn 3 f\le.s

Appl)'
l!!J Elllpty Wlndow pnijecl

... fji\

:;: // App01l1~.h

11.,_rtac.. AllllOal ..... : UtaeltlOfldet' <~......>

11 Olntlrface AppOe.legale : Ullluponder <...-....~>

... .!>1 .AppDeleg_..,


l!!!J Enlpty Wllr- pnijecl

11

0811g1-111

: .impon AppDelag.h"
11 mple!IWlolt AllllOll
...

~ : : -....... pnijla
i'!

llmp8lt"Au0:1 "h.
IClflc.-.. !11.t t ~

,...,. w:::aP'l
.

6.3.

(<d+4>)
, .

Xcode

, .
,
. , ( ,
)

AppDelegate .m
#import, howdy.
<Command+B>).

, ,

, . ,
. "",

, ; ,

lssues

EditorQlssuesQHide/Show All

<Command+Control+M> ).

howdy

; ,

. !
(<d+S>)

Xcode 5.

.
.

, ;

, , , .

111

6. 1111 Xcode

127

Xcode 5

9.

(<d+>)
,

Xcode

; .

9).

. AppDelegate. m, return

YES DebugQBreakpointsQAdd Breakpoint at Current Line.


, . .
, , ,

Debug.

(.

6.4),

Xcode

5 .

(CPU

Memory);

, .
,

lnstruments

(.

9).

,
( ).
,
, ; ,

. ,
.
.

Debug (ViewqDebug AreaQHide/Show


Debug Area <Command-Shift-Y> ). -

. , ,

. ,

ViewqDebug AreaQActivate Console.

()
,
.

()
,
, . ,

,
. ,
.
. ,
.

128

11. r11111

._,,
""' 111N 1

u
111&

11

{OOL)app\ication1

{UIApp\ication lapp\1cat1on
didfin1shLaunchinQW1thOptionst (NSDictionary I
taunchOptions

//

Overide

point for cuatomization after eppticetion

1.aunch.

.,....." appllallooi....... ;:::111111:.DS"i:==========:J~ii:ii--

" ' " Quouo: ...... . . , . . _ _ _

@1lllp1.-ntat1on App0e1.egate

12

17

11
1-l\Alllllk1on _11111111111 "
"i] 'iS'-ii~
._1f
_.__
- _<_v_
o_
id_l~
pp
_1.~
1c_a_t_
1onWi
_ _t_t_11e
_ s_1__11,,,
.,..c_
t=
iv,,..e_:_
(u_IAp
_p_l_
i_
ca_t_1_
on_
_
I_

....."......"..

018.-.

[%]

17 -

.""..,....4 . . .
.,. ,..... :r
=:.

"

1 1 1"

" . 1f (App()tloga ) Ox84f9f0


.,. ll 1111plat1on (UIAppRc.ot1on " 0841<10

" 111 lliunchOptlon -

IJ8!...!~!!!!!!!!~~;)!!!!!!!!!!!!!!!lt!!J 10

(NSDlcllolwy ') ""

i G~
e_

~,., ~~;:::-(\\d)

) [10

___ _ _ _ )

11 0urpu1:

8 / (][J

6.4.

(<d+7>)
J1 .
J1,

J1 . ,

(,
).
.

9.

(<Command+B>)

,
() . , (

) , .
,

. , ,

(" ?").
,

All All Messages , ,


6.5).
, Expand Transcript, (.
Editor).

J1 (.

, ,
, .

<Option>

(. ),

<Option+Shift>

, , ,
( ,

). , , -

Xcode.

'

11111

6. 111111 n Xcode

129

:::: 1 ~

.,... 1 lulld EmptyWlndow : 9:19:Sl

R.ecent

1 ( Alf Messages )

All lssues

Errors Only

BuHd target Ernpty Window


'
Project Empty Wlndow 1ConflguratJon Debug 1Destinatlon IPlne Retlna (3.S-indt) 1SDK Simulator - IOS 7.0
Precomptle Empty Window/Empty Wlndow-Preflx.pcn
Complle ViewController.m .. .Jn /Users/matt(Desktop/Empty Wlndow/Empty Wlndow
Compile AppDelegate.m .. Jn /Users/matt/Desktop/Empty Wlndow/EmptyWindow

Compi\e maJn.m . in fUsers/man/Deskto.p/Empty Wlndow/Empty Wlndow


Unk /Users/matt/Ubnuy/Developer/X<ode/DerlwdData/Empty_Window-abptgxyuuwsyphxlrhenonqo{B ...
Generate Empty Window.app.dSY .. Jn {Users/matt/UbraryfDewloper(Xcode/DerivedData/Empty_Window".
Empty Wlndow/en.1proJ/lnfoPlist.sttings
CompileStorylard Empty\ Wlndow{ase.tproj(Maln.storyld
CompileAssetCataJog /Users/matt{Ubrary/Developer{Xcode{DerivedDatafEmpty_Wlndow- abptgxyubtuwsyb ..

Process Empty Wlndow-tnfo.pllst .. .ln fUsers/matt/Desktop/Empty Wlndow/Empty Wlndow

A
V

luJld sua:d8cl
No issues

9 (10/U 9:19

6.5.

n n

. ,

;
, . ,
, .

(

7).

. storyboard . xib

, ,

,
( .

8).

Quick Help,

( . 9).
VlewQUtilitiesQHide/Show Utilities ( <Command+Option+O>).
, .

,
, :

. ,
, .

.
.

Quick Help.

<Command+Option+l> <Command+Option+2>. ,
Quick Help .

, , .

130

11. r1111

. s t oryboa rd . xib

Quick Help,
( <Command+Option+> ),
(<Command+Option+4>), (<Command+Option+S>)
( <Command+Option+> ).

, , .


Quick Help, (<Command+
+Option+4>) .

.
,

(<Command+Option+Control+ 1), (Command+Option+Control+2),


(Command+Option+Control+4).

(<Command+Option+Control+)

. storyboard .xib.

q~ , ,

<Spacebar>.

. ,
(.

9),

. ,

. xib

7).

. storyboard

, (
).

. ~<
, . ,
.
,
(

<Control+4>

Viewc:>Standard Editor).

.
,
; , .
, , .

Related Files,

(<Control+l>)

, .

, , ,

. ,
.

(. m . h),

~ (

Counterparts).
Superclasses,

6. Xcode

131

Subclasses SIlngs; (siblings) -

). ,
, , ; ,
, , .

. r
,

Back

, .

NavigateQGo Back (Command+Control+Left).

r,

r r
. : ,
r .

. r

Editor
ViewQAssistant EditorQShow Assistant Editor (

<Command+Option+Return>). r,
<Option> r; ,
<Option> r <Option>

r (
) . r ,

Editor , ViewQStandard
EditorQShow Standard Editor ( <Command+Return>),

r .

. r

FileQNeWQTab

<Command+> ),

( ),

. , r
,

Safari. r ,
<Command+Shift+}>.

r , r .

, ,

r . , r
. : r
, .


r , ,

ero FileQNewQWindow (
<Command+Shift+ > ).
, ero r .

132

11.

ViewQAssistant Editor. All

r11

Editors Stacked Vertically,

. ,

Plus

Navigatec::>Open in Primary Editor.

, .

, ,
.
, ;

,
, , .

(tracking).

Tracking.

Related Files,

(<Control+4> ).

. ,
Counterparts (.

6.6). AppDelega te . m;

AppDelegate. h.

AppDelegate. h;

AppDelegate .m.

,
, (
,

<Control+S> ).

,
. ,

Manual.

ckgound:(UIApplication )app\ic ~

'

legare

DSuperdus

Sucluses
Slbllngs

c.legor\e

'

111

ights

Ur lnterfaces

~ Responde
)

1S

eseved.

Potocols

16

<UIAppticationDe\egate>

UIW1ndow *Window1

11 Callers
Ca!J~s

6.6.

. ,

11111

6.

11111 n1

Xcode

133

ero

. , , ,
r ,
r , .

. ,
, ;


r . r (

Plus
Behaviors Preferences), :
Show tab named Console in active window ( Console )
Show debugger wlth Console View ( ). r,

r . , , r

Console ( ,

), r, r .
, r ,

<Command+Shift+}>.

"".
..

r ,

.".

, r

\~ :,.
.____.....,._

. r r ,
,

NavigateQReveal in
Project Navigator. r, Reveal in Symbol Navigator

Reveal in Debug Navigator Navigate.

ero

Empty Window,

(<Command+l>)

, Empty

Window.) , , .
r , , ,
.

Finder

Xcode.
(. 6.7).

r FileQShow Finder

Finder .

Empty Window. xcodeproj.

, ,

. ,

Finder,

Xcode

),

Xcode ( Finder, Dock


Xcode ;

, !
r, , ,

Finder. ,
ero. .

.
. !

134

11.

r11111 ~ 111

Xcode,

Xcode.

. !)
,

Finder,

, ,

. ,

Xcode

, .

.,.

1 Wlflllow
2 urveu. s 1.0
r: fmpty Wlndow

_,~~,~.,,r,

AppDelegate.m

!!) Appl)e1eg&1e.m

11 &.lproJ

1 lln.storyoard

Maln.storyboard

ffi1 vtewController.h

~ Empty Wlndow-lnfo.pllst

~ VlewController.m

ffi1

\iii lmagu.xcu"' 0 Supponlng Flles

Empty Wlndow-lnfo.pllst
lnfol'llst.StrlngJ

Empty Wlndow-Preflx.pch
en.lproj
lnfoPllst.strlngs
lmages.xcassets

111>

maln.m

!mJ 1"81n.m

ffi1 Empty Wlndow

[) VleWController.h

"8flx.pch

lmpeywtndaWr~ lmpey.WllldaWr8111.111

.,. Supponlng Flles

~ fmpty Wlndowuu-\nfo.pflst
) lnfollllst.strlngs

.,. 11

VleWController .m
Empty Wlndow.xcodeproj
Empty Wlndowe

Fr81W011cs

'1'
111>

- --

AppDelega1eJ1

AppDelegale.h

...

... ~ .r.

...J..""'"""..... .....-" ... - -

"' 11 Empty Wlndow

iii Foundallon.rr-11

"" ii'iiConc;nphia.fr-'t
"" ... IJIClt.rr.-ti
... "XIC1't.flwirtc
: '"8ductl
~ lmpCyWltldolw.lllP
~WllldaWests.-

6.7.

, , ,

Finder

(.

6.7).

(,

, ,

.) r

Finder, Flnder

Empty Window Empty Window .


EmptyWindow, AppDelegate.m,
Empty Window.

(
),
,

Empty Window

Empty Window

. (

11111

6. 11111

Xcode

135

; ,
.)

Empty Window Tests Empty Window Tests


Empty_ WindowTests. m Empty Window Tests
Empty Window Tests.
,

- . ,

. , ,

, :

Supporting Files

Empty Window

;
,
. , ;

Empty Window-Info.plist,
Empty Window-Prefix.pch -
, Supporting Files. ( rpynne EmptyWindowTests
Supporting Files.) InfoPlist. strings, main .m

EmptyWindow, InfoPlist. strings Main. storyboard,


Finder ,
: Main. storyboard Base. lproj,
InfoPlist. strings - en. lproj.
, 9.

lmages.xcassets
Images. xcassets, . (
Xcode 5); Xcode ,
.
,
, .

9.

, . ! ,

Finder.

, ,

.

.

;
.

FileQNewQGroup.

<Return>,

, - ,

136

Login. ,
Sounds. .

11. r1111

Frameworks Products

, .
Framworks

( ),
. ,

; ,

(iPhone, iPod touch

iPad).

, ..

. , ,
.

Xcode 5

Frameworks.

.)

Products

(target) -

. , .

Empty Window

: . (

, .

6.8,

,
- .)

WindowTests.

Empty Window

Empty Window

( )

Empty

, ,

iPhone,

iPad, -

. ,
.

,
.

, .
.

Empty Window.

Xcode, ; - . (
Empty WindowTests , -
. 9.)

n111

6.

Xcode

137

Empty Wlndow

Capatles

Ceneral

ul ld

lnfo

Build Rulu

Bulld l't!ases

Settlngs

PltOJ EC

8 Empty Wlndow

11> .rget

Dependencwa ( ltems)

TARGES

Empry \Vindow

Compll Sou:u

L:.'J Empty WJndowTests

ltem)

Name

(~) Add Target".

---~-----~-
1!!1 VlewContro/ler.m
.. ln Empty Wlndow

[\ A;.pDel;~;;,m " .1~ ~~ty wi~dow

---- - - - -

maln.m " .ln EmptyWlndow

-----------

Unk linuy Wldl Ubrarta1 (3 ltems)

Name

_______ _____
______________________
Status

CoreCraphlcs.framework

R.equlred ~

UII0t.fr1mework

Requlred :

..:;:;:;:._
Found1tlon.framework

..,

Requlred :

Drag to reorder frameworks

lundle Resourus (3 ltem1)

li tm<1ges.xcusets
)

.. .ln Empty Wlndow

lnfoPllst.strlngs ... ln fmpty Window/(localizatlonJ ...

J alrtoryoard
-------------------------------

6.8.

6.8).

(.

Empty Window

Libraries

Build Phases

, .

Bundle Resources, -

- Compile Sources, Link Binary With

Xcode

. ,

. , ,

.
.

Compile Sources

( ),
.

138

11. r1111

. m;

, .

AppDelegate .m main .m.

, ,

ViewController.m,

. m

Compile Sources.

Link Binary With Libraries

( ) (
). ,
.
.
.
dl Rsourcs

,
. , ,

,
.

;
, .
InfoPlist. strings . storyboard.
.

. , ,
;

. storyboard ,

. storyboardc,

, ni-.
. ,

Bundle Resources ,

CDpy Bundle Resources ( )


Plus Bundle Resources,

, . , -

Bundle Resources

, ; , ,

Finder, -

Run Script,

Editorc>Add
Build Phasec>Add Run Script Build Phase. Run
Script .
echo "Running the Run Script build phase"

Show environment variaes in build log

Run Script.
Run Script;

, .

6.

1111

Xcode

139

. . ,

(.

Build Settings

6.9).

Xcode

, ,

.
.

:::: 1 ...

"

!8

Empty WJndow

'Jilt Empty W1ndow;

l1J

---..--;k--@ 1 Combld

Cenaral

Capallltles

lnfo

l11d

S.ttJngs

luHd l'h&S

lullcl Rulu

------~----------=---------------------------------------

(Lewts)

"Archlttc:111res

1 Empty Wln...

S<!ltlllg
Addltlonal

!8

Empty Wln".

SDs

Arcfllf8Ctllres

Stancl&rcl

; SWlarcl : :

lueSD

Lltest IOS 00.. ;

<ultlple

"lllHcl Adlw8 An:hlr.cture Only

val." :

Yes ~ -.

De~

Slartclard

Latest JOS

<Muf

". ;
18 va." :

lteluse
Supporttd
V&lld An:hllluNs

l'i..ttor,;,,

IOS;
ann64 armv7 L "

IOS 7.0 :

No-:
,_N_" _: _ _~
(No:
""_)
['05 ~ ___ J
iam;64 armv7 L "]

6.9.

, ,

Basic

All.

, .
- , , ,

, .

Comblned Levels; . 6.9 ,


Levels, . ,

, ; ,

Xcode

, , .

Levels

, .
, . ,

Only

iOS default, , Debug Build Active Architecture


No. ( )

Yes.

( ) ,

( )

Resolved Yes.

,
, , . .
, , .

Qulck Help , .

Apple, Xcode Build Setting Reference.

140

11.

r1111111 116

r
,
. .

,
,
, .
.

Debug

,
.

Re/ease

,
.

, . ,
,

lnfo
-

(.

6.10).

. ,

. ,
.
, .

lnfo

llulld Settings

Deployment Target
105 Deployrnt Target ~
f 7_.o
___\~)

TARGES

~ Empty Window
Empty WindowTuts

Contlg11ratlons

(fJ Add Target" .

Name

----.-- --------.----- -------.- ........_.__...... ...... ... _____________......


Deug
...

"

"

"

!1Joltelse

6.1 .

, (. .

6.9) "Optim"
Optimization Level (. 6.11).
Optimization Level Debug None:
, Debug,
. Optimization Level Release
Fas test, Smallest. ,
Release,
.

, ,

, ,
.

11

6. 111111 n Xcode

141

Empty WJndow

[[]

. :

lask

't' Apple

Capalltles

Ceneral

1 (Comned)

U.V

S.O - Code Ceneratlon

lulld Settlngs

lnro

(~

L.evels

Phases

optjm

1.f'J Empty Window

Setting
Enforce Strtct Allasing

Yes:

Unk-tme

No:

Optlmizatlon

<Multlple values> :

Optlmlzatlon U!vel
Debug

~one [-):

Rllease
Rllax IEEE Compllance
Vectorlze loops
.

uild

Fastest, SmaHest [..Os) :

No:
No:

6.11 . z

Xcode

. .
( )

. ,
. ,

Window.

Empty Window Empty


ProductQSchemeQEdit Scheme.

Product.

- Build -

, .

Build

, .
, , ,
, ,

- Run -

(.

Debug.

ProductQTest.

6.12).

Build Configuration

, (

Run

, :

ProduCtQRun

),

Debug , .

, , .
. ,
, ,

Release

( ,

).

Run.

Xcode

142

ProductQ Run

11. r11

Run).

Option,

\ ,

Run.

11 , ,

Run.

lnfo

Argumenu

Optlons

Olagnosllcs

Bulld Conl\guration [io.ugD;


;;;-----:;::::;:~;;=-=:--;;;l)
Execut.able ( fj Empty Wlndow.app

" / ' Tlt


Debug

" -

Profll Empty Wln."

O.ug~r ( UOI

11 Rtluse

"8 Amllyz

Oebug Process As

De ug

; )

; )

.. (lnatt)

Q root

"nAlllve
~Rtla

Ust rhls opdon to


~unch

Walt

Dupllcate Scheme

anage

dt ug

root proas, ,

Alllomatk:ally

ror Empty Wlndow.app to launched manually

Schemes".
. 6.12.

Debug
Release, , ,
Release Run. : ,
Duplicate Scheme. ;
Empty Window Release. Build Configuration
Run Release .
: Empty Window ( Debug)
Empty Window Release ( Release).
Scheme
(. 6.13) .

1 IOS Devlce
NewS<heme."
~nage S<hemes."

IOS Slmulator
-1
IPhone Retlna (3.S -lnch)
IPhone Retlna (4-l nch}
IPhone Retlna (4-lnclt 64- t)

..

lPild
IPad Retlna

. 6.13. Scheme

6. 1111 Xcode

143

1111

Scheme

J1 . ,

Simulator.
Simulator, ,

Scheme.

Scheme , ,
.

Scheme.
6.13):

( .

Scheme.

Product.

,
,

Scheme

Simulator.
9) - 6. 1,
Scheme "iOS 7. "
"iOS 6 .1" . ,
, . 6.13,
, (.

J1. ,

Scheme.

; , ,

Simulator. ( ,

SD; .

SDK

SDK

Simulator SDK
Simulator':)

"

Schemes

Manage
Producti:::>Schemei=>Manage Schemes
Scheme). , Empty Window Release

, .


, ,
. , ,

. ! ,
,

<Return>,

<Return>.

Xcode

, ,

, ,

Info.plist - , .
Rename,

-.
JI . ,
, , ,

, . ,
, .

144

11.

r1111 ~ 11111

( )

. , ; Product~Manage

Schemes ,

( )

. , .
,
, .
, ( ) ,
. ,

"" .

Finder

,
.

n
,

(package).

(bundle).

Finder

, ,
Show Package
Contents. r .
Empty Window,
. Finder;
Library/Developer/Xcode/DerivedData, . 6.14. ( ,
,

Library.)

Products File~Show Finder,

, , .

m s ons
Contalners

.,.
.,.

Cookles
Dt!Yeloper

Shared

llJo

.,. Xcode
Archtves
".
conntl.apple.com 4.6.1.db
connectl.apple.com 4.6.2.db

~ c:onntl.app\e.com 4.6.d
DerlvedData

11 Empty_wtndow;ptgxyubluwsybphxlrhehonqo
. Ulld

lntennedlates

llJo

Products
Deug-lphoneslmulator

IJ
.

6.14.

Empty Wlndow.app.dSY

6.

Finder

1111

Xcode

145

Finder, <Control> Empty


Window, Show Package Contents.
(.

6.15).

Asseu.car
"

1
.

lue.lproJ
1! Maln.storyoardc
Empty Wlndow

en.tproJ
lnfoPllst.strlngs
lnfo.pllst
Launchlmage-700-S68hfl2x-lphone.png
Pkglnfo

6.15.

Empty Window
.

ViewController .m, AppDelegate .m main .m.


#import (
Empt Window- Pre f ix . pch).

,
. , .
,

main.

Main.storyboard
.

Main. storyboard

. storyboardc,

Main. storyboard (
ibtool)

ni-,

. ni-, ,

.
(

Base. lproj ),

Main. storyboardc
Main. storyboard

; , ( .

9).

InfoPlist.strings
(

en. lproj ).

Assets.car

Launchimage-700-568h@2x-iphone.png

Images. xcassets
actool.
. car,

146

11.

, , ,
( ).
, , ,
,
.

Info.plist
(, ).

Empty Window-Info .plist

, . ,
,

Inf . pl is t

.
, ,
.

Pkginfo
,
.

Pkginfo -

APPL????,

iOS

. .
,
, . ,

. storyboard . xib, ,

. . ,
, , ,

.
,

,
. ,
, .


: .

Xcode,

,
. ;
, .. ,
.

Info. plist . , ,
lnfo.plist File. ,
lnfo.plist File Empty Window/Empty Window-Info.plist.

( !!)

n11

6.

1111

Xcode

147

""
...

,.~.

"

~--".'

Info.plist,

ero

Info. plist.

-.
.

Info. plist.

n f . 1 i s t

. ( )
, ; ,

"Bundle name" , CFBundleName.


EditorQShow
Raw Keys &Values . , I nf . pl i s t
L: <Control>
Info .plist Open ASQSOurce Code

Target Properties

lnfo . Custom IOS


nf . pl i s t

, I

General

n f . 1 i s t.
Device Orientation,
"Supported interface orientations" Info. plist. (r
,

. ,

Deployment Target,

IOS Deployment

Target.)
I

n f . pl i s t
Info .plist .
. , "Executae file" Info.plist
$ { EXECUTALE _ N};
EXECUTABLE _ N ( Run Script).
, - I n f . pl i s t .
Information
Property List Reference Apple. Info. plist,
, 9.

Ni-n
Ni-

. nib.

, ,

ni-. Ni-
( itool),

. xib

ni-,

. storyboard -

. storyboardc,
. storyboard . xib

ni-. ,

148

Bundle Resources

11. r1111

. xib

. storyboard

Xcode;

,
ni- (.

5).

ni-

; ,
ni-,
, , ,

ni-, , ,
.

Empty Window, Single View Application,

. storyboard ain. storyboard.

, , - ,
,

Info.plist Main (
"Main storyboard file base narne" (UIMainStoryboardFile).
Info .plist !
ni-, . storyboard, r
. storyboard)

, .

Single View Application

, .. ,

. storyboard:

(Main_iPhone. storyboard).

iPad, iPhone,
iPad (Main _ iPad. storyboard). iPhone


, .

Info. plist:

"Main storyboard file base narne"

(UIMainStoryboardFile) "Main_iPhone~ "Main storyboard file base


narne (iPad)" (UIMainStoryboardFile-ipad) "ain_iPad".

.

. xib

. storyboard,
7.

nnn

i, ,

. , ,
, , , .

.
, ,

Bundle Resources.
( , ni-):

. ,

.
,
FileAdd

Files to [Project]

. (.

6.16),

Finder

11111

6. 11111

Xcode

149

ltems into destination group's folder (lf needed)

Create groups for added folders


Crul8 folder references for any added folders

Add to

rvets

Empty Wlndow
i Empty WindowTests

ltms

6.16.

lnto dstlnatlon group's foldr(lf dd)

r .
. ,

, ,
. .
Foldrs
1U , 1JJ1
; J<1J ,

t goups

for addd foldrs

;
1JJ1 , 1JJ1

Bundle Resources ,

t foldr rferences

for added folders

( 1JJ1
); ,

Bundle Resources

, ..
. ,

, .
, (
)
. 1JJ1 , ,

1JJ1 ,
, .

Add to Targets
,

Bundle Resources

. , , ,

. 1JJ1 ~
, ,
,

Bundle Resources

, , .

150

11. r1111

IOS :
-

,
:

listen_normal .png

listen_normal@2x.png,

@2 , ,

.
.

Xcode 5 -

listen_normal .png

, . ,

- Images . xcassets.

New lmage Set.

Plus

Image,

.
,

listen_normal .png listen_normal@2x.png,

. ,

( .

6.16);

), ,

, .
,

Listen

(.

Image, , listen_normal;

6.17).

--

---------------------- 1

::

1)(

Untwrul

t. ____________________________________________

6.17.

Jj

,
,

@"Listen",

( ) . ,
;

IOS 7

,
. , ,
ig .

png,

1 i t tle. png

@2, .

. ,
, ig.

png

little . png

(<Command+Option+4> ).

. , ,
, ,

1 i t tle. png ,

ig . png.

11111 6. 1111 n

Xcode

151

11
,
r , , r

Compile Sources. ( Empty Window

ViewController .m, AppDelegate .m

main .m.)

r,

r;
.

Compile Sources ;
Prefix Header. ( Empty

Window Empty Window-Prefix. pch.)


r

r ; (, ,
), (

DerivedData)

. , r,
r (, r ),

#defines,

#import;

, r

4. r
Foundation. h (r Core Foundation)

UIKi t. h

(r ). .

, r ,

Info.plist

"Executae

file"

(CFBundleExecutae),

r r ; r

EXECUTALE_NAE (

main. m.

"Empty Window").

Objective-C. , Objective-C

main.

main:

int main(int argc, char *argv[])


{

@autoreleasepool

return

main .

@autoreleasepool
r

argv, nil,
NSStringFromClass([AppDelegate class]));

UIApplicationain(argc,

UIApplicationMain,

ero.

r , .

12.

UIApplicationMain

r ?

? I ?

1.

UIApplicationMain.

UIApplicationMain

(shared application instance),

152

11.

[UIApplication sharedApplicationJ.

r1111111 11111

UIApplicationMain,

, ,

nil,

UIApplication. -
UIApplication, , (

, )

UIApplica tionMain.
NSStringFromClass([MyUIApplicationSuclass

2.

class])

UIApplicationMain -
- ,
11. , , ,
. UIApplicationMain
.

. :

NSStringFromClass([AppDelegate class])
UIApplica tionMain
.

AppDelegate

AppDelegate. h

AppDelegate. m,

; , (, , ) .

3.

Info.plist

cationMain

UIAppli-

;
, .

Empty Window,

Single View Application,


ViewController;
ViewController. h ViewController .m,

, ,

4.

, UIApplicationain
, Ji

UIWindow, -

window;

(
( .

rootViewController).

UIApplicationMain

window.
UIWindow.)

5.

UIApplicationMain
- , application:didFinis
hLaunchingWi thOptions:. r !
, application: didFinishLaunchingWi thOptions: -

, ,

,
.

( .

iOS 6,

gWi thOptions:,

application:willFinishLaunchin

.)

6. Xcode

153

6.

UIApplicationMain

.
makeKeyAndVisie

7.

UIWindow.

. , ,

, .

. storyboard

. xib,

ni

; ,
.
.

, , ,

. (

application: didFinishLaunchi
ngWi thOptions:) , UIApplicationMain
( UIApplicationMain ),

, .

, "
." " Xcode

Application,

5,

Single View

Empty Window,

. , .
, ,

window makeKeyAndVisie

, .

, , iPhone

Empty Application;

Truly Empty.

Delegate,

, .

application: didFinishLaunchingWithOptions:

AppDelegate .m
window.

self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];


// .
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisile];
return YES;
;

to have

"Application windows are expected


root view controller at the end of application launch" ("

").
,

rootViewController.

self.window
11

[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

self.window.rootViewController [UIVieWController new]; //


self.window.backgroundColor [UIColor whiteColor];
[self.window makeKeyAndVisile];
return YES;

:
. ,

154

11.

r1111

UIViewController. ,
. storyboard, . xib.
UIViewController . xib.

;
,

1.

FileQNewQFile. Choose template iOS


Touch , Objective-C Class

2.

Next.

ViewController ,

UIViewController.

With

XIB for user interface.

Next.

Save. , Truly
Group Truly Empty
Truly Empty, - ,
. Create.

3.

Empty,

Xcode : ViewController. h ViewController. rn,


ViewController UIViewController,
ViewController. xib, ViewController

4.

application:didFinishLaunchi
ngWi thOptions: AppDelega te. rn
ViewController; ,
#irnport "ViewController .h".
self.window

[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

// .

self.window.rootViewController = [ViewController new];


self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisile];
return YES;

//

, .
,

UIApplicationMain

window,

UIWindow,

rootViewController

. ,

ViewController,
ViewController. xib; ,
ViewController. xib .

ViewController

ni-

SDK

. ,

Apple.

IOS,

, ;

/Systern/Library/Frarneworks, ,
iPhone iPad ,

6. Xcode

155

. ,

System/Library/Frameworks IOS
Xcode. r , ,
SDK (software devdopment kit -
). , SD. ,

, , ,

System/
Library/Frameworks/ iPhone SD. Xcode. /
Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
iPhoneOS7. . sdk.

~

/System/

Library/Frameworks/.
,

Apple

. ,
; . .

.
, .
, .


, . (,

(,

uppercaseString),

NSString)

, ,

Objective-C:

( . h},

.,s . , ,

NSString

UIKi t. h,

NSString. h.

uppercaseString,

NSString. h.

Foundation. h,

timport <UIKit/UIKit.h>
(

4.1.)

, .

#import,

, ,
.

156

11. r11

,
,

, .
,

Link Binary With Libraries.

Link Binary With Libraries (


Frameworks,

).

UIKi t

"UI," UIKi t.

iOS,
UIKi t (<UIKi t/UIKi t. h>)


, ,

AppDelegate. h,

, .

Foundation

NSString

NSArray,

, "N S",

framework.

Foundation

, , ,

UIKi t. h, Foundation (<Foundation/


Foundation.h>). , Foundation.h
Core Foundation (<CoreFoundation/CoreFoundation. h>) Core
Foundation ; ,
Core Foundation ( ,
"CF~ CFStringRef) .

Core Graphics

Core Graphics

, "cG~

UIKi t,

iOS ,

. ,
, . ,
, :

, ,
. , ,
.

, ,

Address Book

.
ANewPersonViewController:ANewPersonViewController*
[ANewPersonViewController

new];

1111

6. 111

Xcode

157

, ,
,

ABNewPersonViewController -

, . ,

ABNewPersonViewController,

"NS': "ur"

"CG~

ANewPersonViewController ,

AddressBookUI.

( ),
:

#import <AddressBookUI/AddressBookUI.h>
, .
"Symol

not found':

_OBJC_CLASS_$_ABNewPersonViewController.

( s)

, :

AddressBookUI. frarnework.

, ,

General

Libraries.

( ,

Linked Frameworks and


Build Phases
Link Binary With Libraries.)

Plus,
,

.
,

SD.

AddressBookUI

AddressBookUI. frarnework Add.


Link BlnaryWith Libraries. (

.) ( ) .

Xcode 5

LLVM 5.0,

.
n

Modules ( and Objectlve-C). Yes

, .
,
Library/Developer/Xcode/DerivedData/ModuleCache.

, ,
, .
.


, ,
.

. m

30

UIIOt

. ,

30

. , ,
,

. .


.
, (
), .

#import <AddressBookUI/AddressBookUI.h>

158

11.

111

#import
import @, #),

@import

@import AddressBookUI;
,

#import

@imports,

, ,

# import,

-,

, . .

Link
Frameworks Automatically), . ,

, .

. ,

, ,

With Libraries

Link Binary

. , ,

; , .

, (

workspace and frameworks"

"within

(" ")).

, ,

6. 11 n Xcode

159

n nin

nib - "NeXTStep Interface Builder~


. nib. iOS
ni-. . xib, . s toryboard
Xcode (. 6). . xib . storyboard
Xcode, ; ,

, ,

Adobe Illustrator, OmniGraffle, Canvas


Xcode ni-.

"".
..

.".

....~. "
~-~.-".'

Xcode

3.2. ni-

Interface Builder.
Xcode 4 Interface Builder
Xcode. ni- Xcode
- Interface Builder.

ni-, .
, .

5 (.

" ni-),

ni-, ,
,

ni-,

"Howdy ! ~
UIButton

. ,

, ,
.

UIButton* =
[UIButton buttonWithType:UIButtonTypeSystem];
//
[ setTitle:@"Howdy!" forState:UIControlStateNormal]; //
[ setFrame: CGRectMake(l00,100,52,30)];
//
[self.view addSuview:b];
//
, , ni-, ni-
. , ,

, ni-. ,

ni-, , ni-
. , ni-,

ni- ,
. ,

,
, .

, ni- .

ni-

. xib

. storyboard

Xcode?

ni- ?

, ni-
?

.'
11

....~"

ni-?

ni- ,

~_.....,..""

: '' ?"
, , ni-?

: ", ': ,

. storyboard

. xib

( ).

.
ni-
; ,
,
ni-. , ,
, ni-.

ni-
ni-

Window

Window,

Xcode. 6 Empty
Single View Application;
. Xcode Empty
Main. storyboard ,
iPhone

7.1

Main. storyboard

. rr; ,

. .

1.

(document outline),

. ,
.

2.

(canvas),

, , .

(view) -

. ", ",
,

, ,

, ( ).

162

11.

:: ! ,.. " 1

[mptyWlnclow ,1

QI Empty".

... . . . . ._________

1 &Jn.st".) l

- ;-~;:::::.~;,:; --------------------

aVt.st

lll't

____it..1!1...1!...'!'..
.....

~--_! _____ _

fl opu_..,,..

lottom Layout Guide

....

Fif'lt Respond~r

~C.,,askt~"*ity

---- [
---- (

--~}.;)
.!~~

--kltl~S~~ ~~~~1:1)

__, ___11!1___________

----------~--

L\ ~~ ~ llud.ou

@.: ___ _
.

3.

7.1. i-

, .

4.

, ,
, ni-.


~ ni-
- storyboard

. xib.

(scenes).

, ( ) .
ni- ni-,

, ni-
. , .

7.1

, .

,
, .

(scene dock). ,
7.2:

, .

7. Ynpa1ne11e

nlb-aina11

163

7.2.

.
.

. ,
: , -,

Responder Exit.

First

, , .

Ni-
,

ni-

. , ni-,
ni - .
-
- (

First Responder

Exit)

, ni- .
, ni-

( ). -
, ni- .
, ,
, .

, .

7.1

, ). ,

164

11.

r11111 1s16

. ,
, ,
. .

( ),

( ).
,

. .

, ,

, .
( !).

. xib . ,
. storyboard, ni-.

, , ;
,

xib

. ,
. .
.

7.3

. xib

7.1.

7.3. .xib,

, .

7.3,

-,

Responder.

File's Owner First

. ,

ni- .

. xib

; , ni

, .
(.

7.4).

n111

7. Ynp1ue11e

ni-1n111

165

8
.

7.4. .xib

,
; .

7.1

7.3

. ,

,
( ),
, ni- ,
.
; ,
, , .

, ,
: ~

- <Control+6> -

, .

ni- ,
.

, ni- . ni-

<Return>,

Label

Document

(<Command+Option+3> ).

ni-

, .

. xib ni-

), (. 7.3) . ,
, ni- .

.
, ;

Edltorc>Canvasc>Zoom
(. .

7.1).

Main. storyboard EmptyWlndow ,

ni-

. ,

.
;

,
(.

6).

, ,
. ,
.

166

11.

r11

1.

, .

2.

7.1.

(<Command+Option+Control+> ).

,
, .

"button:

Button

3.


( .

Button
7.5) .

.........- 1

D {}

lullDrt ................... .
.... a8l,lilcl" ... . ..

j ~r llutt'!?~te~ - Reprents an
.

7.5.

. , ,

, ni-
, . .

. . (
,
.)

, ,

. .

. ,
.

, ,
.

<Option>

. ,

. (
,

<Option>,

. ,

<Option> .
<Delete>, .)

<Control+Shift>.

, , (
, ,

, ).

. .

"Howdy ! "

11111

7. n1111 nl-1111

167

, ,
.

1.

Debugc>Actlvate / Deactivate Breakpoints.


Deactivate Breakpoints, ;

2.
3.

Scheme
- 3,5 4 ).

Productc>Run

Run

iPhone Retina

).

(.

7.6) -

IOS Empty Window,

! ,

, .

Camer

. 7:153

Howdy

. 7.6.

168

11. r111111

Empty Widow

11

n
ni- ,
, , .

(<d+ti+>)
,

Custom Class.

. ,
ni-, .
(<d+ti+4>)
.
,

Background

backgroundColor

Title

setTitle:forState:.
,

. ,

UIButton Attributes :
Button Control ( UIButton
UIControl) View ( UIButton UIView).
(Coand+Optio+S)
, , Width

Height

, . ,

, .

Autolayout ( Use Autolayout


Autosizing,

},

autoresizingMask,

autoresizingMask.

Arrange

Autolayout ( . xib
storyboard}, Autolayout

r ,
, .

(d+ti+)
.
ni- .
(Command+Option+Control+)
, ni-.
(Coad+Optio+Cotrol+4)
, , ,

UI ImageView
UIImageView ).

1111 7. n111111 nib-1in111

169

r ni-
Ni-

, ni-

. , ni-
. ni-, ni-,
, .

. Ni-
,

- . Ni- ,

; , .
, .
,

. , ni- ,

..".

ni-,
.

..".

___".".

..___~~

ni- : "" ni-


. ni- ,
ni- .
,
. , , ,

.
Ni-

; ni-. ,
ni- ,
. , ni- ,
. Ni-, ,

, .

5,

( , ), (

alloc)

ni-.

.
, ni-
.

. ,
. , ni-,
.

.
, , ,

(. 6).
,

(segues);

.
,

. ,

170

11.

instantiateini tial ViewController, ,


- instantiateViewContr
ol lerWi thidentif ier:.

(,
. .

- , ,
ero ,
. r 6,

new].

Truly Empty

[ViewController

r ni-;

, ni-.)

z i-
r .
( ),

ero r -

. , rr

. r

ero

, r ,

ero

. r
;

ero ni-.

( )
(

Empty Window),

ni-: ni-, , ni-,

ero r

. , ni-, ,
r

ero

ero

; , r

r , r ni-,

, , .

- , ni-,
r

. xib,

r r

ero

r . r ni
r .

ero

r ni-.
.
,
r

Truly Empty.

ViewController. . xib, ni-,


ViewController (r ). r

r, r ni-, r ni-,
r .
, nibNae
r

ni-, r
r

ero

nibName:.

ini tWi thNibNarne: bundle:,

r ,
r

nibName

, ni-, r r
.

nibName

7. n1111 nl-n

171

z i-
, ni- .
, ni-

. xib,

loadNibNamed:owner:options:

NSBundle.

[NSBundle

mainBundle].
instantiateWithOwner:options:

UINib. ni- ,
UINib nibWi thNibName: bundle:.

"".
.,

ni- ,

. ,

nibName, nibBundle, , ni-,


ini tWi thNibName: bundle: nibWi thNibName: bundle:,
bundle:
name:.
:i (, , [NSBundle
mainBundle] ); ,

nn nib-ana
ni-, , :
. , (

5).

: ;
; , ,
.

(outlet) -

ni-,

ni- . :

"" "". (souce),

(destination)

. .


ni- , .

( st-),
( -,

5).

ni- .
ni-;

172

11.

r111111 ~

, .
- ( st

) , .
, , ni-,

Dog,

l.

Nib Object

Dog

Nib Obj ect


Person.

Person.

, ni- ,

Nib
Obj ect ( Dog) Nib Obj ect
( Person).- master.

ni-.

2.

, ni- (
).

3.

Nib Obj ect Nib Obj ect .


4.

Dog

Person.

ni- . ni-
Nib Object Nib Object master.
,

setValue: forKey : Dog,


@"master", - Person.
Dog Person - ,
master!

: ni-

. ni- ,

(.

7.7).

Person

Dog

Dog

master Person

Ni- '
n Dog
"master"
n Person

Dog

- :;={> Person

ni-

master

38l'J)Yll88Ctl
nl-eAn

V> 8

n Dog 1

n Person

master
n

Dog -

Person

7. 7. CCWIJ , i-
11N

7. n111

nib-+ana11

173

ni-

..

. , ,
( st-). ,
, :
ni-. . ,

Xcode

, .
, .

, ni-

ni-, ni
, .

. Ni- , .
, , ni-,
( , ); ,
, ni-, ,
ni-. ,
ni-, ,
, .

,
ni- > ,

. - . ,

. storyboard

. xib

-,

. ,
- ni-. -, , .

- ni-
. ,

, , .

. xib

- ni-

Placeholders

File's Owner.
- ni-

-,

ni- . ni-
; . , ,
-, .

, , ni- ni-
ni-

Dog.

Person,
Dog master. ni-

- ni-

, ,

Dog

ni- (

Dog)

ni-

Person.

ni-

- ni-

Person

Dog Dog
master.
ni- Dog,

- ni- ?
. ni-

.
ni-, (.

174

11.

r111

7.8).

Dog

Person

Dog

master Person*

Dog

ni-

Dog

...,>

._f_ _ _ _

Person

mas te r

Dog -

Person

7.8. i-

ni'-? .

ni-,

loadNibNamed:owner:options:
instantiateWi thOwner : options:, owner : .

ni- ,
,

ni-.
, ,

. . ,

UIViewController

view,

..

( r).
ni-, ,

ni-.
, , , ni-
, - (,
)

11

7.

nn ni-

175

ni-. .

Dog,

Dog,

7.8,

ni-, - ni-

Person, - ,
UIViewController, -
ni- UIViewController, view
UIView. ( " UIViewController UIView~ , ,
master

.)
, , ni- ,
.

- ni-, ni-,

UIViewController

, ni-.

ni-

view

- ni-

.
, .

, ni- ;
, ni-,

view

. .
, ni-, t (
..).

view

.
,
,

Window.

Main. storyboard.

, ni-

Empty

ni-

Controller

6,

View Controller.

View

. .

, - ni-

ViewController.
Outlet
View

. ,

View

( ,

, ).

Truly Empty.

- ni-

ViewController. xib.
File's Owner. .

. , - ni-

ViewController.
Outlet View.


.
, ,

Empty Window.

1.

button.

Main. storyboard

Empty Window

176

11.

r1111 11

ViewController. UIButton.
ViewController
UIButton* ( UIButton).

2.

ViewController . h.

@interface

@property IBOutlet UIButton* button;

3.

. (

12), .


.
, .

IBOutlet;

Xcode,

ViewController. IBOutlet ,
Xcode ,

4.

Main . storyboard

View Controller
-

! ,

IBOutlet

ViewController.

. , ,

Controller)

(View

, .

button

.
, ,

, , .

( .

7.9).

Referanc:i119 Outlets
New Rl!ferenclng Outlet

bferencJng OUtlet Colltions


!lil!W Rl!ferencing Outler C.OU.ctk

7.9. w

, . ,
. , .

7.

nn ni-n

177

? ,

button

ViewController

ni-

, ni-,

. , ,

button

. .

1.

2.

ViewController .m.

viewDidLoad.

, ni-,

. ni-,
, .

self .button

viewDidLoad method:

[self.button setTitle:@"Hi!" forState:UIControlStateNormal];

3. . , ,
"Howdy ! ", "Hi ! ':
!

n r
.
, .
; ! . ,

, .
~

Empty Window. .

UIViewController.

"UIViewController ... class is not key value coding-compliant for the


key button" ("UIViewController ... -
- button.")

,
:

ViewController
UIViewController. UIViewController,
ViewController, button (
button, st- setButton:). ni-,

button.

UIViewController -

, ,
, ,

ViewController.

, .

178

@property

ViewController. h

11. r

self .button

ViewController. m.

"ViewController ... class is not key value


coding-compliant for the key button." ("ViewController ... -
: :- : button:')

, , .

- ViewController.

button

ni-

ni-
. ni-
-

ViewController -

.
i-

, ,
,

ViewController. h

ViewController. m.

, , .
.
,

. . ,
"Howdy ! ~ ..
viewDidLoad ViewController .

"Hi ! "

.
, ni-
, .
ni-

button
self .button, nil.
setTitle: forState :, .
, nil, ,
(. 3).
nil.

Truly Empty,

.
-

File's Owner,

. xib

Truly Empty.

. .

the view outlet was not set"


") .

"loaded the 'ViewController' nib but


nib 'ViewController',

("

. Ni-,
. ,

(- ni-) .
,

UIViewController

outlet.

view

, !
, ,

ni-.

11111

7. n11111

nl-1111

179

n
, .. .
, ,
. .

1. ni-.

2.

J1 .

3.

.
, ,

button

Empty Window.

1. ni-. ,
( )

button

, .

2.

3.

ViewController. h

@property.

. ;

ViewController .m,

sel f . but ton

, , .

r
,
ni- .

Xcode

. .
EmptyWindow ( ).
ni-

1.

HUD (heads-up display),

ViewController. h

( ) J1 :

@property IBOutlet UIButton* button;

2.

<Control>

1 .

View Controller ,

. ,
.

3.

(.
1

7.10).

HUD,

" " ,

, . r

Control-drag,

. .

180

11. r1111

<Control>. -

7.10.

-
.

HUD, r

1.
2.

<Control>

ViewController. h.

View Controller ,

r .

HUD,

r .

3.

(.

7.11). .

7.11.

11111

7. n1111. nl-1111

181

HUD,

1.

ViewController. h.

<Contol> .

2.

HUD,

3.

New Referencing Outlet.

- , , .
, ,
.

4.

HUD,

. .

. ,
ni-.
: .

ViewController . h

. ,
.

1.

2.

3.

ni-
(.

7.12)
11

ViewController . h.

@interface ViewContro1.1.er : UIViewContro1.1.er


@prope rty IOut 1.et UIButton* button;
nd

Vlew )

Vlew Conttoller
Layout Gulde

8
8

lottom Layout" .

VI-

8 Flrst R8spondar
8Exlt

7.12.
i-

.
! .

1.

<Control>

ni-

@interface

View-

Controller . h.

2.

(.

182

HUD lnsert Outlet, Action Outlet Collection


7.13). .

11. r

3.

4.

ero , . 7.14.

Connect.

, ni- r.

ni-
, : . r

,
ni-,

of that class.

-
with the same name and coming from an instance

ni-,
.

Xcode ,

ni-.

1~::.:..::.:::.:..:.::::::::.....:.:.:::.::..:~~~

12

'"" J - ~ '

l n"rt 011tltI, , t , ur

011 t l<t Collt< tton 1

13
1.4

v... >C

: 1

"8

Vlew Controller Scene

" Vlew Cont1oller


8 Layout Culde
8 ottom Layout."
Q

7.13.

111 t> t>

i-

11
#1mport <UIKit/UIKit.h>

@inter1ace ViewContro\\er

UIViewContro\\er

tend
(

c.onn.ct )

C&ncel )

Xcode

...

- - -

"

,..

t.ec.- ~

7.14.

"

' -"

r, ,

ni-,
. ,
, ,

: ni-
, .

7. nn11 nl-n

183

NSArray

( }, ( ni

) .
, , :

@property IBOUtletCollection(UIButton) NSArray* buttons;


:

IBOutletCollection

, .

NSArray.

, ni-,
,

UIButton

ni-. ni-

NSArray,

UIButton

; ,

, .
,

, ni-, ( },
. ,
,
.


ni- . ,

, ni-

(action) -

UIControl

( ) ,

- , .

. ,

UIControl

"Control Events." ,

UIControlEventTouchUpinside.

, .

( }, ,
()?

()?

ni- ;
, , .
, , ,
, .

,
,

Empty Window

UIControlEventTouchUpinside

( ). ,
.

184

11.

r1111 11

, .

ViewController .m.

buttonPressed: (id) sender 1


UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"Howdy!"
message:@"You tapped me."
delegate:nil
cancelButtonTitle:@"Cool"
otherButtonTitles:nil];
[av show];
(IAction)

IBAction

IBOutlet -

, ,

Xcode

Xcode

Xcode,

void.

ni- ,

, , , .

, ni-, , :

View Controller , ,
Received Actions.

uttonPressed:

,
. : .

, ni- . ,
.

1.

View Controller

uttonPressed: .
.

2.

HUD

, .

Touch Up lnside.

. ,

Touch Up lnside, .. ,

uttonPressed: ,
. , :

. ! , ,
, . !
w, .
. ,

ViewController .m

<Control> .
HUD, . ,

Touch Up lnside

HUD,

HUD,

<Control>

buttonPressed:.

. ,

n111 7. n111 nib-1in111

185

r, ni-.
ViewController.m r. eoabuttonPressed:

ViewController .m .

r ni-.
,

ni- ,
ni- r.

buttonPressed:

, ni-

1.

<Control> ni-
@implementation ViewController .m.
HUD, lsert Actlo.

2.

,
, .
Evet

ero buttonPressed:, ,
Touch Up lside ( ), t.

Xcode ni-
r:

- (IBAction)buttonPressed: (id)sender { )

Xcode ,

),

.
,

Xcode

, , ( ).

nln
l
l- ( )
. , , ,
, l- ( ). :
l- l- ,
l
, , l-.
l-

l-, ,
, l-
( ).
, l-,
,

186

11.

13.

r1111111 ~ 11611

..

~~

Related Files ni- ,


, .

" r

~--~.

. ni-,
, Tracklng. , ,
, ni-,
, .

nn n n,
Ni-n
ni-
; ,
,
.
. ni-. ,
.

, ,
ni-,
( , ni- - ni-),
, ni-.

,
ni-.
viewDidLoad. , viewDidLoad
, "Howdy ! " "i ! ~
r

ni-

ni-. -

. ,
. , ni-

ni-. ~>. ,
,

,
ni-.
, awakeFromNib.

, ni-,

ni-

the object has been initialized and configured and its connections are

operational.
, , ,

ni-. ( , .)

EmptyWlndow

1.
2.

MyRedButton.

FlleQNeWQFlle. IOS
Touch Objectlve-C Next.
MyRedutton.

UIButton

Next.

1111

7. 1111111

nlb-ai11a11

187

3.

Empty Window
Empty Window. Create. Xcode

MyRedutton.h MyRedutton.m.

4.

MyRedBut ton. m

awakeFromNib:- (void) awakeFromNib {


[super awakeFromNib];
self.backgroundColor = [UIColor redColor];

UIButton,

ni-

. ni-

. . ,

MyRedButton.

. , !
r

OS

, , ,

OS

FromNib;

super

OS

super

iOS

awake

awakeFromNib.
awakeFromNib

ni-, ,

FromNib

awakeFromNib

iOS

awake

ni-.
- User Defined
Runtime Attributes ni-.
setValue: forKey: ni-. (
setValue: forKeyPath:; (key paths) 12.)
ni- ni-, ni-
. ,
, ni- .
, ni- ,

. , ni-
.

layer. cornerRadius. Ni- .


User Defined Runtime Attributes.
Path layer. cornerRadius, Numer,
Value , ; - 1 (. 7.15).

ni-

; , .
ni- ,

UIView

( )

),

initWithCoder:

ini tWi thCoder:.

ini tWi thFrame:. ,


ini tWi thFrame:.
ini tWi thFrame:
UIView

MyRedutton

188

UIViewController

11. r111

UIView

ni - ,

initWithCoder :.
ini tW i thFr ame : ,

, ni-. )

ini tWi thCoder:


-
, . ini tWi thCoder :
(. 5): super,
self.

- (id) initWithCoder: (NSCoder *)aDecoder {


self = [super initWithCoder : aDecoder];
i f (self) {
self->_myivar = 11 whatever
return self;

CustomOUs

C)j.)

l 1yRedButton
ldentity

Plth

l.a~r.cornerRadlus

1
Numr

1Value

: 10

+ 7.15. 11

7. nn

nl-n

189

. ,
, z .
,

iOS

. ,

, .

Apple,

Touch

Xcode,

, , .
; ,
,

Xcode

Apple.

; (. )

-,

Apple.

, t .

Xcode

Documentatlon);

Downloads

Preferences

Check and lnstall Now

. , ; ,

IOS

IOS 7 Xcode 5.

, (

) ,

OS

10.8

10.9.

,
.

Xcode 5
per/Shared/Documentation/DocSets.

Xcode,

Library/Develo-

Xcode 5

Dash (http://kapeli.com/das.h).':-


Xcode J1
(HelpQDocumentation and API Reference, <Command+Option+Shift+?>).
JI ; , <Command+Option+Shift+?> (
<Command+L>, ), NSString
<Return>, NSString Class Reference.
, ,
.

, J1

J1 .

<Return>.

JI ,

<Esc>.


<Return>, .

JI , :

API Reference, SDK Guides, Tools Guides Sample Code.


, . :
, J1 ( ,
, ..), .

<Option>

, JI
; (

<Option>)

JI ,

. (.

More

9)

( - )

HelpQSearch Documentation for Selected Text (<Command+Option+Control+/>).

-,

-. ,

Apple http: / /developer. apple. com.

- , ,

EditorQShareQQpen in Browser Share


Open in Safari. J1
. <Command>
- , <Command>
, <Command>
, Open Link in New .

192

11. r1111111

111

(WindowQSelect Next ),
NavigateQGo Back

Back

, ).


, .

lnfo

; , EditOQShow

lnfo;

lnfo
of Contents Details -

lnfo.

NSString Class Reference

,
,

Details

NSString,

.. .
,
. ,

String
Programming Guide , ,
of Contents String Programming Guide
.

- ,
: EditOQShareQAdd

Share

Bookmark,
Add Bookmark, ( )

.
; ,

EditorQShow Bookmarks

, :
, .

FindQFind (<Command+F>)

Find.

Safari.

Xcode, Xcode 5

.
" " ,
. , ,

IOS 7
Library/Developer/Shared/Documentation/DocSets,
Finder Show Package Contents,
Contents/Resources/Documents/navigation/ index. html,

. ,
, (.

lnfo,
Details

8.1).
Details

( -

).

8.

193

Tasks

lnherlta From

UIControl

Creatlng Buttons
+

UIVlew
Uillesponder

utt:onVit:h'f'ypet

NSOJ1ct

Conflgurlng the utton Title

ConfonnTo
UIAppurance

t.itlLahe1 P/'OPf!rtr
rvrTitle8hadCNWheni9hli9hted

NSCoding
Fr-rk
U!it

AvallAltillty

at:t.riut:ad.Titlettorstate

ad.juatI-9ffhani9hli9ht.ed

property

propefty

howa'1'ouohtfhani9li9ht.ad. p~pefty

- ack9roundl8898!'or8tat
- i18a9For8tat:1
- ae1:&aoktround111ut9etforSt:at.e1

2.0 and later


lrt

Dlarecl

Conflguring Button Presentatlon

UIAppearanceContAlner
U!Dynamldtem

t:it:lshado...ColorForBt..a t:a t

ad.juatI111a9aWanDiaalad.

property

NSOJect

1:Tit.lesfor8t.at.es
tAt:t.ributedTit.l1for8t.at;er
t.Tit;leColortforBt;at.e .1
at;Tit;leShad.ow<:olorsforSt.atet
tit:leColor?orSt.ate
t:itle?orBt.at:er

Ullutton.h

S8mple .1
avToud!
Popoyers
l

UICatalog
AddMusk

8.1. "' UIButton

lnherits From

.
, ,
, r .

UIButton
addTarget: action: forControlEvents: ,
UIControl. frame
UIButton UIButtone, -
UIView.

Conforms

, .

10.

Framwork
, .
, (.

6).

Availaility
,

. ,

194

UIDynamicAnimator

11. r11111

( UIit

Dynamics)

iOS 7.

iOS 7

Declard

ln

( ), . , ;
. ,

,
.

, .

Sample

. (. .)
Relatd
,

. ,

View Programming Guide for iOS.

UIView

( )
.

of Contents

lnfo.

Overview

Overview,

. (

, .

UIView .)

Tasks

.
.

Properties, Class Methods, lnstance Methods

. (
, , ,

get-

st-,

, .)

Constants

, .

UIButton ,
buttonWi thType:; ,
Constants UIButtonType. (
, buttonWi thType: UIButtonType
Constants.) ,

11111

8. 11

195

(.

1,

). ,
.

,
.

. ,
.

Description

Forma/ Declaration

. (

12.)

Parameters and Return Value

Discussion

.
!

Availaility
;
,
,

S Also
.
.

Related Samp/e Code

, ,
.

Dec/ared ln

.
, (

10),

, .
,

awakeFromNib
UIButton,

(.

7)

Apple.

AppiDo

196

11.

(http: / / appkido. com).

r1111

Apple

;
,

, .
;

Open Project

http: / /developer. apple. com,

Download Sample Code.

, , , ,
, .

, ,
. ,

Apple

, .

. (, ,
,

MoveMe.)

UITouch,

, , , (,

). ,
, , .
.

-, ,

Apple,

, . ,

,
.
, .

r
, ~ .

Quick Help

Quick Help -

( ).

( <Command+Option+2>),

Quick Help

. ,

CGPointMake,
CGPointMake.

Quick Help

Quick Help Quick Help

, ni-,
..

Quick Help ,
Quick Help. Helpi:>Quick Help for Selected ltem
( <Command+Control+Shift+?> ). <Option>

, (

), ,

<Option>,

8.

197

Reference,

Quick Help

. ,

, .

Xcode 5
Quick Help.
doxygen (. http://www.stack.nl/-dimitri/doxygen/) HeaderDoc (
"HeaderDoc" - http: / /developer. apple. ).
doxygen, : .

( ) . :

/*!

.n

people would like to dog their t. So it is


to supply convenience method to do so.

perfectly

reasonae

\param cats string containing cats


\return string containing dogs /
- (NSString*) dogyCats: (NSString*) cats {
return @"Dogs";
&1 ,

doxygen,

dogMyCa t : , .
, \, \param \return, doxygen. ,
- dogMyCats :,

(.

Qulck Help

8.2).

\brief)

doxygen

( ,

9).

..

Dldlradafl - (NSStrinfl )dotf'YC8t11 (lllStrinfl )cats;

Dlla...,

~ 1

wau6d fllce to clot dlelr . So lt 11


aupply COIlfllellC8 rnedlod

~ f'UIOflllble

lln-1sm cata

"

'

A ..... llD8il'llllllC8

8.2. ,

Quick Help

, ,

. :

Xcode,

NavigateQJump to Definition (<Command+Control+J>).


<Command> ,

( );

<Command>

, .

,
. ,

198

111

11.

r1111111 11 11161111

; ,
.

"" ,

Xcode.

<Command>

Navigation

<Command>

, <Command+Option+eo>

, <mmnd+ >

<Command+Option+Control+J>

, ,
(.

6).

, ,
, , ,

Fllec> Open Qulckly (<Command+Shift+O>).

, , ,

applicationDidFinishLaunching:

"appdid~

. .

3rn n
.

, .
. ,
.

Xcode.

Navigatec>Jump to Next Counterpart (<Command+Control+Up>).

Related Files '

(<Control+l>).

,
( , ),
..
,

<Option>.

Filec>Open Quickly (<Command+Shift+O>),

<Command>

Navigatec>Jump to Definition

Quick Help,

, ;
,

Filec>Open Quickly , SDK

, .

, , ,

n111

8. 11111

199

Xcode.

Terminal

-h

rr

r rr .

, ; ,

-h NSString NSString. h, NSStringDrawing. h

, r). , Xcode.

Google r r.
Google search. ,

- . ,
.

Apple ht tp:

/ / developer. apple. L

, , r

. , ,

Xcode .
iOS, iunes,
WWDC 2013 ( )
Apple (https: / /devforums. apple. com).
Apple PDF,
iPad. , Docsets, (Ole Zorn),
r iPad
iPhone. , r
(https: / /github. com/omz/DocSets-for-iOS),

Apple (h t t : / / 1 i s t s .
apple. com/mailman/listinfo). r Xcode-users
( Xcode) r Cocoa-dev (
r ).
,

Apple ;
Google si te: lists. apple.
http://www. cocoabuilder. , .
Apple , r iOS;

, ,

Google

, .

-,

iOS,

r ,

iOS .
Stack Overflow (http://www. stackoverflow. com); ,
r iOS, r

, ,
.

200

11. r11

Xcode:

Store.

Xcode.

, , (.

6),

ni- (.

(.

7)

8).

n
(File~New~Project), ,
, ,

iPad, iPhone

Devices,
Universal. (
Devices General

), , ,
, .

iPhone

iPad

iPad

iPhone,

iPhone,

iPad,

Devices

Targeted Device Family.


iPad

iPad.

iPhone

iPod touch; iPad,


iPad (
iPhone Emulator; Apple

iPhone

" ").

IPhon/IPad
~

iOS 7 ,

64- ,

Architectures
(including 64-t)~

, r

"Standard architectures

J ,
.

BseSDK
, . r r,

Xcode 5.0 : IOS 7.0

Latest IOS (IOS 7.0).

r11J1 , ( ,r

r ). Xcode ,
, ,
, Latest IOS,
SDK r Base SDK ,

Base SDK.

IOS Deploymnt rt
,

Xcode 5.0,

iOS,

IOS Deployment Target,

4.3.

lnfo, IOS Deployment Target.


IOS Deployment Target, ,
General Deployment

( r r

Target. , ,
uJ .)

Deployment Target

Base

SDK, . .
/J

.

Apple
Xcode Base

SDK,

Deployment Target.

, ,
, .

, Deployment Target iOS 6,


~ , IOS 6, ,
,

IOS 6,

202

11.

IOS 7,

r1111111 ~ 1111

Apple

. -.
,

, . r
-, .

, ,

. . , ni

, . (, ni-,
, r IOS 5.1 ,

NSLayoutConstraint, .)

, , ,
, ,

. , ,
, iPhone iPad, -
,
. , iPhone;
,
- - iPhone
, iPad
.

r -

, ; ,
,
.

UIDevice

(currentDevice),
(systemVersion) (userinterfaceidiom) .

Unlversal Master-Detall Appllcatlon

AppDelegate .m. application:didFinish


LaunchingWi thOptions:, -

, .

Info.plist

Info. plist ,
-iphone -ipad . ,

( ) .

Unlversal, Master-Detall Appllcatlon.

Info.plist "Supported lnterface orlentatlons":


(UISupportedinterfaceOrientations)
iPad, , iPad (UISup
portedinterfaceOrientations-ipad).

n11 9. 111 1111n

203

Universal, Master-Detail Application,

: ,

:

iPhone, iPad.

Info .plist "Main storyboard file base name~


(UIMainStoryboardFile) iPad

(UIMainStoryboardFile-ipad). ,

iPad.

.
, ,

Info. plist, ,
- iphone - ipad ,
. , @"linen.png", imageNamed:
UIImage linen-ipad.png,

iPad

Xcode 5 : ,

.
.

Device Specific Devices


.

iPhone

iPad.

!)

,
, .
,

Required
Linked Frameworks and Libraries Optional.

(weak-linking the framework).

( ,
6).

Xcode 5 (.

u,

ero Linked Frameworks and Libraries;

.)

, ,

respondsToSelector:

NSObj ect

if ([UIButton respondsToSelector: @selector(appearance)])


11 ok - 1 appearance} else {
11 appearance
1
t~

, ,

NSClassFromString,

Base SDK 5.0

nil,

. ,

, ,

204

11. r1111

( ) ,
, ,

iOS 5,

// , Core Image
if ([CIFilter class]) { // ok -

nil;

CIFilter


, ,
, . :

if (&UIApplicationWillEnterForegrounc!Notification) {
// - UIApplicationWillEnterForegrounc!Notification

n
,
.

-
(cornmits)) .

,
" ':

; ,

, ,
. ~u ,
( ), - ;
, .

, ,
, .

, .

Xcode ,
Git (http: / /git-sc. ) Subversion (http: //subversion. apache. org,
SVN). ,

! ,

Xcode.

, ,

Xcode
Terminal
, svnX for
Suversion (http://www. lachoseinteracti ve. net/en/products) SourceTree for git
(http://www. sourcetreeapp. ).
Git

Subversion

9. 11i

1111 n

205

Xcode,

( ). n

Source Control Source Control, Check Out


Source Control, .
n Source Control,
. n Source Control Refresh local
status automatically, Xcode ;
, .
(

Xcode 4

Add and remove files automatically Xcode 5

Git

.)

Save ,

Git

, .

, !
,

Subversion Git,

Xcode


. ,

Xcode

Accounts, Xcode 5

Accounts.
Refresh local status automatically,

. ,
(),

Git,

(?)

, ().
, ,

Control

Xcode 5)

Source

. ,

Source Controlc::>Check Out. Source Control


Commit, Push, Pull ( Update), Refresh Status Discard Changes.
Source Control ( Xcode 5),

;
.

Source Control<=>Commit,

. ,
, .

Source Control<=>History. (, Xcode


gi tk.)

, .

;

Vlew<=>Verslon Editor<=>Show Version Editor Editor


. :

(Comparison view),

(Blame view)

(Log

View<=>Verslon Editor
, Editor

view).

).

206

11.

r11111 111

, .

9.1,

11 ()

NSStringDrawing
context:. EditorQCopy
Source Changes, diff .
, : "eliminated
NSStringDrawingContext':
Context:

.
NSAtt r1utedStr1ng

s (se\ f
ottr1buted5tr1ngForindexPoth1 INSindexPoth
1ndaxPethFor1\ow11 1nSection11) l 1
CGAect r (t ound1ngllectwithSize1Ceili-loo
(321,1-) options:
NSStr1ngD,...,ingUsetL1ne'r.....,tOrigin
~

(heights

11

addOject ( r. s ire. height) 1;

: J")'/

9.1.

, , Xcode 5, ( )

For Line.

EditOrQShow Blame

, ,

. ,

Xcode

FileQCreate Snapshot ( r

, ).
,

Git

, .

Projects Organizer; ,

Xcode

Source Editor Fonts & Colors. .


!

(13, 14 16)
Monaco, Menlo Consolas (

Inconsolata).
Xcode ,
Objective-C.

Editlng lndentation Text Editing.


Edltlng
, Line Numbers;
. lndentation ; ,
, .

Objective-C Xcode .

Xcode
, ,

11111

t. 111t11111 111111

207

EditorQStructureQRe-lndent (<Control+I> ),

. (
, .)

calls.

Editing.

Automatically balance brackets in Objective-C method

, ,

Xcode

.
, ,

. , ,

UIAlertView* av

[UIAlertView alloc

.
( ).
,

.
,

ini t:.

UIAlertView* av = [[UIAlertView alloc] ]


11
n

type-over completions

Xcode

UIAlertView* av

[U

Xcode

UIAlertView* av

[U]

. ,
:

UIAlertView* av = [UIAlertView alloc]


11
, ,
.

<>

<Right>.

, , .

n
,

Xcode.

Objective-C

Suggest
completions while typing Editing; Use Escape
key to show completion suggestions
, , <Esc>.
, ,
.

<Esc>.

208

ini t,

11.

ini t,

(.

UIAlertView

9.2).

w , , . ,

<Down>

<Return>

{[UIAtetView a ~locJ __jnitWJ.t!JTitte:

cance1.Butto

in i t Wi th i t le : . . .

>

{NS5trin

111 id init
111 i d J.i~.Wi1:hCoder: (NSCoder

--~ss_age:

_(NSString

111 id AfJi~.WHhFrme: (CGRect)

9.2.

<Esc>.

<Return>,

<Control+Period>

<Control+Period>

<>, ,
. , .

<>,
,

ini t,

9.2,

ini tWi th -

, .

,
;

More,
8).

( )

(.

doxygen

\brief,

8,

\brief,

,
( ) :

[[UIAlertView alloc] initWithTitle:<f(NSString


message:<#(NSString
delegate : <f(id)#>
cancelButtonTitle:<#(NSString
otherButtonTitles:<#(NSString

*)#>
), ... #>, nil]

<t ... #>

*)t>
*)#>

.
<> ( )

NavigateQJump to Next Placeholder ( <Control+/> ).

, ,
, ..
,

<# ... #>,

Xcode

,
.

<Return>

9.

209

, .
,

+ ( ),

. ,

- appli

tion: didChangeStatusBarFrame:;

<Esc>,

applica

( ,

11).

, .

- (void)application: (UIApplication *)application


didChangeStatusBarFrame: (CGRect)oldStatusBarFrame
,

return;

,
, .

- . Code
Snippet (<Command+Option+Control+2>),
, , .
, .

if

if

lf Statement.

<Return> if,

<Esc>,

) ( ).
,
,

Code Snippet

Edit.

Code

Snippet .
,

snippets;

Code Snippet.

User

, , ;

<# .. #>.

fixit

Xcode

Fix-it,

, . .
, .
, .

9.3 @

NSString Objective-C,

( ,

). ,
, ,

210

111

11. r1111111

11 111

. : ( )

; @. :

Xcode

<Return>

Fix-it

, . ,

EditorQFix All in Scope (<Command+Option+Control+F>), Xcode

Fix-it, .

General.

Fix-it.

Show live issues

. , ,
; .
,
( ,
).

r

. ,

Xcode
Xcode

, .

Xcode.

(<Command+l>),

(EdltQFilterQFllter in Navigator, <Command+Option+J>). ,

story,

. storyboard.

, <>,

<Up>

<Down>

.
, .

(
,

),

. . ,
, , .

11111

9. 1

11 n

211

~
.

( )
.
( ,

<Command> ).

#pragma mark. ,
ViewController .m EmptyWindow.

tpragma mark - View lifecycle


- (void)viewDidLoad
[super viewDidLoad];
11

...

viewDidload

View

lifecycle.
,

mark,

#pragma

( }, (

, ).
,

TODO:,

FIXE:, ???:!!!:.

, .

, .

Back

Forward,
NavigateQGo Back

NavigateQGo Forward,

<Command+Control+Left>

<Command+

+Control+Right>.

Related ltems,

, , ,
. ,
.

!
,

, .

212

11.

r1111 11

"" , ; ,

"adf", application: didFinishLaunchingWi th


Options: ( ).

.

<Option>

, .

Tracking

6).

(.

6).

NavigateQJump to Definition (<Command+Control+J>)

, .
1

FileQOpen Quickly (<Command+Shift+O>)

, .

Xcode

. .

Edit,
(FindQFind
in Project/Workspace, <Command+Shift+F>), ~ ,
(FindQFind, <Command+F>); .

Xcode 5 Find

. Xcode

.
,

. ( .

9.3
ln project),

: ,
.
. .

Find

Replace.
(Replace All)
(Replace). Xcode 5 ,

Replace All.

Preview

9. n n

213

<Option>

Replace All,

ln Scope,

Edltorc>Edlt All

J1 r

( ) r .
n J1
, r .

"'."'

r , , -

11,

.__~_~__...,.~. u r Objective-C,
Refactoring Xcode
Xcode).

(. "

nn nn n
r ,

IOS Slmulator appllcatlon.

r s

SDK, Deployment Target Targeted


Devlce Famlly ,

(. r

6).

Devlce, J1 .
,

ero Xcode

Hardwarec>

Xcode

, ,

Xcode.

r,
u .

: , u (
WlndowScale).

, s r
. ,

Retina

, ,
n .

, .
, ;

<Option>,

r r ,

<Option+Shift>.

Home,

Home, Hardwarec>Home (<Command+Shift+H>). (


Home n

Xcode r Xcode,

. r J1 ,

214

Hardware

Xcode Productc>Stop.)

, ,

11. r1111

. r, ,
, , .

Debug r ,
. r
, ero. Toggle Slow Anlmatlons ,
, . (
Color) ,

Instruments Core Animation,

Debug

Console
Core Location).

r (

: r
.

61 OTRIKI
~

(caveman debuging)

, ,

, .

Debug ( r 6
).
NSLog.
, r

NSString, ,

r .

NSString),

, , (r
) .
(%),

(%%). (), , ,

' r.
%@ ( ),

%d

( ) %f

( doue). :

NSLoq(@"the window: '11@", self.window);


self. window - ( ) r ,
ero ( ) %@, r

. ,
r ( ero r ):

the window: <UIWindow: 8680;


frame (0 ; 320 480);
hidden YES;
qestureRecoqnizers <NSArray: Ox8a69fd0>;
layer <UIWindowLayer: 8970>>
,

ero

( ,

),
.

11111

9. 1l

11

215

UIWindow: ,

%@. , ,

NSLog.

,
,

Apple String Format Specifiers (


String Prograrnming Guide).

printf ;
sprintf

IEEE.

K&R Bl.2

printf,

NSLog ( )

, .
,

, NSLog;
,

%d,

float. NSNumer,

; NSNumer -

(%@). , ,
. , ,
.

, ,
NSLog, - .
. :

NSLog(@"%@", NSStringFromCGRect(self.window.frame)); // ((0, 0), (320, 480))


, : ,

. .
, NSLog (Debug Release)
, ( ).

, (- , ).
, ,
. ,
, : ,
,

Organizer Xcode

iPhone Configuration Utility.

NSLog
, , , ,
.

(Jens Alfke)) -

MyLog

NSLog MyLog (
,

1):

tdefine MyLog if(O); else NSLog


,

_ cmd

, , :

NSLog(@"Logging %@ in %@", NSStringFromSelector(_cmd), self);

216

11. r1111

( NSLog (@"%s", _FUNCTION_)


.)

assert. - , ,
(assert) , - ,
.

, ,

.

},

, ()

( ). ,
, ,

. , ,

NO,

, :

Assertion failed: (NO) ,


function -[AppDelegate application:didFinishLaunchingWithOptions:],
file /Users/mattleopard/Desktop/testing/testing/AppDelegate.m, line 20.
:
, , , ,
.

NSAssert (

Objective-C)

NSCAssert ( ).

,
.
,
,

NSLog.

,
, .

NSAssert NSCAssert
n

Release -
Foundation Asser-tions, No

Release .
Release,

Yes.

Xcode

Xcode,

Xcode 5 LLDB.

- http: / /lld.

Xcode

llvm. org.

; ,

. .

9. 11i n

217


, .

,
.

.
,

. .
, .

r,
.

,
r

Debug

, r

Run).
Release,

, , ,
r r .

(.

9.4)

, Debug~Breakpolntsc>Add Breakpoint at Current Line

(<Command+\>).

, ,

. ,
; r , .

9.4.

9.5.

,
. r .
, , r,
.

r, .

<Control>,

Edit Breakpoint

<Command+Option+eo >. :

. r,

, . , r ,
, .

,
.
: NSLog,
rr ,

218

11.

r1111111 t1 11611

.
. , ,
.
,
.

Plus

.
.



, ,

.
,

( , ). ,
, , , ,

. ,

Move Breakpolnt ToQUser,

.
, , ,

Apple,

. ,

, .

, ,
m .

(-

+).

, (.

Shorthand). ,
ReceivingRemoteControlEvents

Useful

begin

-[UIApplication

eginReceivingRemoteControlEvents]

Xcode 5

, ,

, .

, . , r

Events, Xcode
RemoteControlEvents].

beginRecei vingRemoteControl

- [UIApplication beginReceiving

Breakpoints
Debug, DebugQActivate/

Deactivate Breakpoints (<Command+>).

, ,

n111

9. 111t1111i

11n n1

219

. , , ,
, , .


( . .),

. ,
, , .
; , (.

RunningQPauses
Debug.

Behaviors

9.6).

9.6.

t11

,
.

, t11

, .
, ,

User

; , ,

. ,

, ,

, .
, , , .
,
,

Debug.

Debug

(
). ,
, ,
. ,
;
.

Xcode

Auto,

(, ).

Local.

, (,

220

11. r

debugDescription)

Print Description of [Variae]


lnfo .

Xcode 5

Ouick Look

( )

<Spacebar>.

CGRect

Xcode 5

(data tips)

. ,
.
: ,

lnfo,
Quick Look

(.

9.7).

26
"

28

19

(0,0)
")/

31

480 0

CGRect f~y~~-tj setf.view. frame 1

helght

9.7.

11,

'~~

" <Return>, ,

'------~"'. .'

; (,

float int, ). expr


, .
( ).

,
:

, .
.

Watch

<Control>,

[Variale].


. ,

9.

221

. Add

Expression

. ,


, .

Xcode -

LLDB,
Xcode, .

LLDB;

"print object"- " "),

, .
(, ,

debugDescription).

- expr,
Objective-C , .. ,

!
-

Command,

http: / /

LLDB

lld.

llvrn. org/lldb-gd. html.


Debugger

, , , ,

. , ,
, ,
.

, .
,
, , .

! ,
, ,

; . ,
,
; , ,
.


,
,

(Debugi::>Continue),

. ,

Debugi::>Continue to Current Line

Continue to

),
, .

222

11.

r11 1

Debug.

Stp v
.

Stp

lnto

, , ;
.

StpOut
r .

Debug.

Debug

, , ,

r.

Step Over r -
Continue
r, - Step
Out - .

, ,

Start over abort


r ,

Stop
(ProductQStop, <Command+Period>). Home
Simulator (HardwareQHome)

iOS 4

. r

<Control>

ero

Run (ProductQ Perform

ActionQRun Without Building, <Command+Control+R>).


, .

r, ,

Objective-C

Xcode

. r

ero

).

, r .

r r . ,

- r ,

ero

, r , ..

, .

r ,
r r. r, ,

ero,

, .

.n111

!1. 111

11n

223

."..

\~'

"

~-.....,.".:

. ,
. ,

,
,

JavaScript,

Automation Instrument

, .

-, .

Xcode 5

: , ,

(test target),
(<Command+S> ), .
Xcode 5 XCTestCase (
XCTest). -
, (void) .
test. , ..

~
. ;
, .
;

XCTAssert.
XCTestAssertions. h.)

Xcode 5

( r ,

XCTAssert,

. ,
. , , @,

.
, ,

. .
,

XCTestCase.

setUp

, .

setUp

tearDown

tearDown

, .

224

11.

r11111

."...

tll,

....~.

(bundle),

"

, , .

~-~""

setUp;

[NSBundle bundleForClass: [MyTestClass class]]


()

dogMyCats:,

Empty Window. ViewController

- (NSString*) dogMyCats: (NSString*) cats {


return nil;
,

@"dogs".

dogMyCats:

, ,

nil.

. , .

Empty Window

Empty_WindowTests

Empty_WindowTests.

Empty_WindowTests .m - (. h),
@interface @implementation .m-. ( 4,
.)

Empty_WindowTests .m testExample.
dogMyCats:
. dogMyCats: -
Viewcontroller, ViewController.
ViewController ,
,

ltimport "ViewController.h"

dogMyCats:,

, , dogMyCats:. ,

dogMyCats:

ViewController. h.
Empty_WindowTests
@interface.

ViewController.

@interface Empty_WindowTests : XCTestCase


@property ViewController* viewController;
@end

- (void)setUp {
[super setUp];
self.viewController

setUp.

[ViewController new];

testDogMyCats.
self. viewController, because setUp

- (void)testDogMyCats {
NSString* input = @"cats";
XCTAssertEqualObjects([self.viewController dogyCats:input], @"dogs",
@"ViewController dogMyCats: fails to produce dogs from \"%@\"",
input);

11111

9. i

111 n1

225

r . .
, .

, .
, ,

Empty_WindowTests testDogMyCats. -!
Empty_WindowTests .m,
, @interface, r .

,
. , ,

ProductQTest.
,

testDogMyCats.

Simulator,

. ( ,
, .)
r

Simulator

! (, , , ?)

Simulator .

, ,
; , , , (

More, ). ,
- testDogMyCats,
, Empty_WindowTests .m
@implementation testDogMyCats.

! ,

. (

ProductQ Perform

ActionQTest [TestMethod] Again.)


, , .

nil.

ViewController.

dogMyCats,

@"dogs ",

. !

, , ,

, .

Failure

Plus, , Add Test


Exception,

Br~akpoint.

, .
, , - ,
.
,
, : ,

Related Files Test Callers.


Tracking .

,
. , ,

[UIApplication sharedApplication]. , ,
ViewController self. viewController
Empty_WindowTests
ViewController.

226

11.

r1111111

self.viewController =
( ViewController*) [[[[UIApplication sharedApplication]
delegate] window] rootViewController];
( )

:
, . ,

setUp .. ,

Plus .

, (

Renaming Parts of Project), :


- ,
.
,
, ,

( ) .

11
1JU

(<Command+Shift+B> ),

ProductQAnalyze

, .

Xcode 5
ProductQPerform ActionQAnalyze [Filename]).

,
, .

, .
, . ,
,

Xcode 5 . r,

ARC.

Objective-C, -

ARC CFTypeRef

12),

.

,
, .

, :

-(void) newGameWithimage: (id)imageSource song: (NSString*)song


CGimageSourceRef src;
if ([imageSource isKindOfClass: [NSURL class]])
src = CGimageSourceCreateWithURL(
(~bridge CFURLRef)imageSource, nil);
if ([imageSource isKindOfClass:[NSData class]])
src = CGimageSourceCreateWithData(

1111

9. 11i

1u

227

~bridge

CFDataRef)imageSource, nil);

11
if (nil ! = src)

CFRelease(src);
-, ,

src .
src
isKindOfClass:. ,
, . , imageSource,
NSURL NSData; , -
? , src
. nil:
;

CGirnageSourceRef src

= nil;

, ,

src

CFTypeRef
CGimageSourceRef,
CGimageSourceCreateWithData,

CGimageSourceCreateWithURL
CFRelease .

. ,
, ,

. , ,

isKindOfClass: (. 9.8). ,
src : -

!
"

-(voJ.d 1

n~Wi thI111age: ( i d) 1...9"Source

song: {NSString) song {

,...CGit11119eSourceRef
= nil;
"" .._.if
((~u isK1nd0fCtoss:
INSURL ctoss1 I)

c::._.s rc CGiugeSourceCreoteWithURL(
l!H, Co1110fl!!'ajon~Gl~<!~mm~~o!IJ!O'-/
(_br1dge CfURLRef ) 1ma51"Source, nil);
{iJNveSource isKindOfCtoss : INSData ctass] J1
src CGI8851"SourceCreateW1thDato(
~.
l_b idge CFDatallef)iugeSource, nil );

LQ1; __ _

11 ni\ ! s)
- - - - :CFRe\.ea&e s);

9.8.

NSData

11

1--

imageSource

isKindOfClass:
NSURL

( ) .

. ,

, . ,

if

else if:

if ([irnageSource isKindOfClass: [NSURL class]])


src = CGirnageSourceCr e ateWi thURL{
<~bridge CFURLRe f)irnageSource, nil);
else if {[irnageSource isKindOfClass: [NSData class]])
src = CGirnageSourceCreateWithData(
<~bridge CFDataRef)irnageSource, nil);

228

11. r11

! ,

.
, ,
.

for 'Build'

Yes,

Shallow;

Analyze During 'Build'.


Mode of Analysis

(Deep}

http://clang-analyzer.llvm.org.

Debug

Release

, ) . ,
,
.
, .

, . ,
, - , ,
.

Bundle Resources

}, , .
r . ,
ni-,
, .

.
.

ProductqCJean,

<Option>,

ProductqCJean Build Folder,

Organizer

WindowqQrganizer},
Projects,

Delete,

Developer/Xcode/DerivedData.

Library /
ero

, ,

. ,
.

9. i n

229

Xcode. Library/Developer/
Xcode/DerivedData .
, ( ,

, ).
.

, .
, :
, , ( ),

Content and Settlngs.


Finder. ,
. Library/Application Support/iPhone
Simulator , SDK (
, 7. ); Applications
IOS

Simulator~ Reset

nn nn
,
.

, ,
, , .

: ,
,

<Option>, ,

iOS,

, , ,
, .


. ,
, .
-

Store ,

, .
, ,

IOS Developer Program

. (,

. .)

Xcode . - IOS
Developer Program (http: / /developer. apple. com/programs/ ios),
. Individual.
Company , ,
. (

230

111

11.

IOS Developer Program

1r1111111 11 1116

Company .)

Apple ID

Apple

).

Developer Program Apple ID

, ,

- ,

Apple,
WWDC

Apple ID .

, .
,

Matt Neuburg.

, ,

.. : ,
, -

Store

. TidITS,
TidITS

News; , ..
Store

iThnes Connect -

- .

Developer Program Apple ID, ero


Xcode S.) Plus,
, Add Apple ID.
Apple ID . Xcode
, ; Xcode

Accounts Xcode.

,
. (
). , .

Apple,

, .

.
,
.

Apple.

, (

Apple , ).
, , , r
,
.

r11111 ' llNIHH"I llCll n1111

231

11

Apple.

(provisioning profile) -

, .

iCloud.

, ,
.

,
. ,
, .
, ,

: (
).

, ; .

Apple:

, ,
. ,

Apple.

Center

Member Center

-.

Developer Program.
Member Center (https: / /developer. apple. com/memercenter)
- IOS Dev Center (https: / /developer .apple. com/devcenter/ios/)
Certificates, ldentifiers, & Profiles.
-

,
. -

Portal;

2013

Apple

Xcode
, , Member
Center, Xcode. ,
Xcode ! ,
Member Center.

11
(
; , ,

Developer Program).

- . ,

232

11.

Apple

Apple

. ,

1.

Keychain Access.

2.

Center,

Member

( )

Apple ID, , -

3.

Apple ,

4.

,
.
.

5.

Xcode

, .

Xcode 5

!
.

1.

2.

3.

Accounts

Apple ID, .

Apple ID. .

View

Details.

4.

,
, ,

Request.

Plus iOS Development


Signing ldentities).

: -

, , , ,

Slgning ldentities View Details.

( ,
, .

9.10. , ,

!)
, . ,

Il -
. , ,

Member Center ( - Certlficates

Plus ).

Keychain Access

AssistantRequest Certificate from

Certificate Authority.

Keychain AccessCertificate

, 2048-

n111

9. 111i

11n n1

233

RSA. r

: nJ; :, ,
J. (,

ero :.)
Member Center : :,
:. ero, r;
:r Member Center, Download, .

, r, ; r eyc:hain
Ac:c:ess ero . .
r ; .
. ,
: , , ,
(.

9.9). r,
Xcode : Accounts
Apple ID, , ,
:,

Vlew Detalls. ,

tl'llone Dewloper:

.t .Uburg

IOS Development Valid.


D

OISVQCA972)

9, 2010 10.

f ............"
" " ' - D8wtoper:
ll1ued .

. .uurv

<JESVQCA9n>

Worlclwkle Dawloper J.tlons Cenllkatlon

Authortty

Exptru: Thimday, Decemer 9, 2010


Thls ~rtlflate ls .alkl

10: 49: 101'

9.9. 111 Kychain Accss

Member Center,
- WWDR lntermediate Certificate.
, , , WWDR
(Apple Worldwide Developer Relations Certification Authority), .. ( . .) Xcode

; r ,

,
-

Member Center,

11 11
r, ,

. ,

234

Xcode

11.

r1111111 1J1611

, r . 11
11 ,
.

, ,
11

(development identlty). ,

! , .

1.

2.

3.

4.

5.

Organlzer Xcode

(WlndowOrganlzer).

Devlces.

Add to Member Center Use for Development

Apple

, r
.
r , Memer

Center,

Devlces.

,
,

Vlew Details

Accounts (ll

) . . 11

"IOS Team Provlsioning Profile"


9.10).

, (.

9/19/14

IOS Ttam Provt11ontng Prollle:

9.10.


, (
,

iCloud).
Xcode

Development,

Add to Member Center Use for


Member Center

11 .

Xcode

Xcode.

,
.

Accounts

Member Center
View Details,

11111 9. 1111I 111

235

"iOS Team Provisioning Profile"

.
.
11J1

1.

Member Center .

Devices

Member Center. , Plus r


ero UDID.
UDID r Devices Organizer.
2.

, r

ldentifierSQApp IDs.

ero.

Member Cente,

Plus

r . ,

Member Center

r ;

ID, ero

Team ID. Explicit


Bundle ldentifier General Xcode,

r . ( ,
r ,

ero

Bundle ldentifier.)

3.

Development.

Plus, Provisioning Profiles. iOS


ID.

.
( ). .

Generate.
Download. r ,

ero Xcode. r , Xcode


ero .

n n
( r

r ),

ero

Scheme,

.
;

ero.

Xcode

.
, , r . r

Xcode,

, :

Xcode,

.. , r
(
). .

Xcode

.
(

Xcode),

. . ,

Xcode,

, .

236

11.

r1111111 111611

NSLog

Xcode 5

Accounts.

Apple ID

View

Details.

Accounts

. ,
.
,

Apple ID Gear
Export Accounts. ,

, ;
.
, ,
;

Xcode

Xcode

, , ,

Xcode,

, ,
. ,

View Details Accounts.


View Details

Accounts, Member Center,


Refresh . , Xcode Finder
Library/MoileDevice/Provisioning Profiles,
. Xcode. Accounts
! Refresh. Xcode
,

Member Center .

Devices

Organizer.

. . ,
, ,

, ,

Console,

, .
( -

Store).

Xcode

, .

(gauges),

Xcode 5

Instruments

, ,
,
. ,

Instruments

).

rnaa

9. i

237

r
. ,
. ,
. ,
, ,
. , , ,

, ,

lnstruments.
. 9.11 ,
, .

Memory

, ,
. ,
, ,

, .
emory

.mory Utzed

Utlllutlon Compar1son

L'!i<a

3.
_;:_ -:.:\ . 6 5%

'

---------------------------------------------------------------------------------_!
.mory
D.ndotr..42c:

tip.:1.JI

Low. 2.fiNI

"
.

9.11. "'

Instruments

,,"

, .

,
(

Core Animation) .
Instruments,

Scheme

Product~Profile . ,

Profile;

Release.

, .
;

on Launch

lnstrument

( },

11

lnstruments

Profile Ask

Instruments ,

238

11. r

Profile ln lnstruments

lnstrwnents

.
:

Restart

Instruments, Transfer
lnstruments.

, 11

Restart:

lnstrwnents.
Instruments ,
; lnstruments .
Instrurnents , ,

lnstruments

Instruments ,

. ( ) .

Apple,
Instruments User Reference and lnstruments User Guide. ,
WWDC; ,
"Instruments" "Performance':
.

TidBIS

News

Profile.

lnstrwnents

ProductQProfile.
Allocations

, -

,
(.

9.12).

Instrwnents,

, :

RSS-;

5,40 ,

2 .

'l

, , ,
.

9.12.

lstruets

:
.

12,

Instruments -

ARC.

, , : MyClassl
MyClass2; MyClassl ,
MyClass2, MyClass2 ,
MyClassl . :

111

9.

111i 111111

239

MyClassl* ml = [MyClassl new];


MyClass2* m2 = [MyClass2 new];
ml.ivar = m2;
m2.ivar = ml;
r

12,

; r, .

ProductQProfile;
Leaks Profile.
, 10 (
Instruments) .
Instruments.

, ,
(.

9.13)!

Cycles & Roots ~

Leak Cydes

lvar

! yC1ass2

(Strong}

1 vc1ass1

/Strorl

<yClns2 61220>

lv&r
<'1Q&ssl 61180>

.".
..
11,

9.13.

'

yC1us2"

ivar

Istrets

Instruments, , , ,
Profile Debug.
Release,

\~
~--~".'
.

Albumen

rr .

,
,

Instruments,

ProductQProfile.
Time Profiler Profile.

r ; ,
.

9.14,

Instruments

, , r
:

:Layer: :layout_and_display_if_needed.

; r . , ,
, ,

, ( .

240

11. r1111

9.15).

......,.

eo.;;;;-

0 a.n"!-.~-ttnes

93. 1

93."1

js..par.;(Irud

. :

maln AIumt"

O.Oj

UIAppliatfonaln

. :

Q iivtn.CI'

2481 .0ms 93." ;


24&1.0m1 9J.mc; :

o -i.....,,s,m11o1s

21 .0ms " I

. :

O ide~Ul'aritl

2481.0ms 93 . I :

. :

Q SowOj-COn~

222s.0ms

."" ~

. :

Q Topf~

2225.0ms 83.4" :
2222.0mt. .. :

. :

Q fl&ttat Rirsion

~iv~
~;Cj~-~~I:-~-:=-~:~
i!~W.~
~---~ ""

1925.0ms

72.~ :

7.0ms

0.2" f

CA::Conttxt:comrNt_transtton(Ck:Tnnsxtion)

QwrtzC,,ofe
.._CA:~ IAytr, : Commt\..lf_@deckCA: :Transxdon'" , voJ ( : ~. unsiOned
CA&fkS.t:lstk Ql;arttCore
CA.: :T~wctton::fot'uch._rookt f"')(CA;.:U.ver-, YOid-'), wt) QuutzCor
llioCA: : LaYf:r.: pnp.att:_commlt(CA: :T~-J Qu&rtteotc-

i.o:

. )

. :
0.0 1

"_dts.patch_quu._wakwp_gCoaJ_stow

11.1.JI: :

.:

3.0ms

O.l" i

. :

223.0ms

&.1" J

. ! ~

24.0rns
1.0ms
LOms

o.n:J

0.9'5 :

. :

..,_aRul'tLDOp()oirr

. :

- O"RunLoopOoSource 1 C.ot'efO&INfIOon

297.0ms

l .Oms

~: :Autore l euel'ool ::...,,\Utoreifa.sePooJ()


J>_utc.e.s~Recogni.t.etUpdi&tt'

. ;

Jt-_CFAutort4uftooWop

.* ~

. :

int. UNignt:d

lidi~.cr,fib

().wtzCort"

UOOt

li'-_ditttch_mai~_queue_caltNck_.OJVAIUANfmp

0-"J

9.14.

~rtl:Cou

~Layer:; layouL._Oti.pl~-lf_ndIO(CA::rAnction*)

. :

0.< :

Cfoo.ndlti

Y _CfRuntoopOo()setYtrs Gord"ou~
..._CFRUNlOOP_tS_CAU.ltlC_ou_o~"OISERVER_CAU.IACK_fUNClON_ CorU<ndat!on
.cA:.:Trancdon::oSttWt_ltackLCFRunLoopC)tvt", unslgd long, vokt"'} Qu&rUConl!:
~ ~Tran.uctlon ::comrmtO Qu.1ruCora

. ;

O.C* f

Cor-~ound.ation

'Y_ O:IWnl..oopRun COl'lf:foundanon

. :

0.()1: :

Cr&pbl~ce.

..CFRunLoopR.unSptfk

. :

.! :

lll

YCRl.un ~untnodt

. :

l92.S.Om1 72 .2'11 :
1914.0ms 71.8'1i ;

l .Oms
1.0nu
l .Oms
1.0ms

'SE.V'tnl:RunOdil

. :

lldladl..dvJ\

COJ'~

C~f.0\111don

_CfltunloopYice.hPort

Cotef~f.iOf't

Istrets

1 1~. CA:.'tzftr,:~_1cn~~~
18. -ICAl..lyt(~bl,.wsI

1330.-(UN"~"~J
1112.0-turr.t.V'Jl!w~J

J40t,O -fUIatllir\18~
1404..0(f.Jlfablt~ll~

,i______________

~A!ffahWil~~..ik~J

1404.0

~=~Clli'i~,..~~:i!~~~~~E=~~::::::~~~==-~~=:::=~I:IU
1.
-l~~ syst~d'irt~:'
5df
i ~~
11'61. ~wil:tw/tO(N.tk.Ol'tlrn/UUonDfa.td:I

~
11il<t.Oms 100.os ,

! ~:::::: :::i
1 1ao.0ms 9 s.~:

~~=: ~~::i

1404.0ms 73 . :
1404.0mJ 7J . : :
1404.0ms 7J.: :
2.0nu .~ 1
1.0nu
)9J.Oms 20.JS :
20.0rns L" :

o.o.J

.n

. r

1.-0rm
1.0rn1
26.0ms

.. :

Sl.Onu

. !

. !
t.:j

-~:: ,;
0 .0 ,1

.;

::~;
. :

o.Oj
0.0 '
. ;

LO !

;~~.rnt_dlsplaV"Jt:--M~:~1~--f

'f'Ck;Ll~:layout,Jf_rw.edrd(CA."': Tranct:n~

QuNUC1t

,..-===e)=-.n.~J

UOOt

;urrable'VkwftowOaUI nwne.tOfltowsJ ~
- (U&ctianaOltlllDa r-.fn: 1 hWidlSed1on:W.View:.t...V~:
.-(U!ubl&lnhttt s~cte..~idon:fortl'ldVtP'ath:I

...(NSA.1.otdf'Ool N'l1taJ

. :
. ;

. :

..-lUtwOilt:nrdr/) ta~J

JJ.f.0

61.0~t~.J.reptacaVlr\ahft~~

Uit

' 47.0 --(NS6&.I&zbpm.ort tlhnef<ttt:~fficifntr.)

UW..ft

.--(~onstralntt.atdt.yout) W;oucSua~r:i

1
.

..(.fCSISf"51!Mmt.WmittCmn..~~J

104.0-(/1C51Sfnigi:.ws~r..wi:h!~\cln:=j

~fUew(c.AL..ty.~egah) _wanOW...mingforlu ~~~


.cA::y.1r.: dlsp~_lf_pe.~CA":Traacdon ")

SS4..0 .(f!ISUyoiJtColltUlf"'.,;ad<fO{~:J
5-4.J.D ~~ut.COl'lflnint"addfof.Jllgfne.:intttn~..wnt.ow.~
)71. -{NSIIOtgltr(odConJrr~i!l';Upre.ISiOl!."iAtegraauUOOAQjtnl:

118.0: "fNSISEngn.piliro(ToNtlodWv.~~

Fctd&tion

.._{U"al:Vi-Ceil layouul;JNws)

~oiutfltlutdli}'OOO~ttfn~~~t

.191.D ..fNSISE~t~WbleT~~lflltldr:ld

Ulk.k

~-reiu ~..,4\
~abltY\N(..Ufa,~td _updatt:VisibleeeR$ow:J

0.0 1

SS9.0

T-{L.Mil/iew~ngt;dJ Ue<Lt

. ;

_'3..fi.W~t11tWalntlutdta~te~S1u:Fintng'Slze:l.Jlkk.Jn"

1036. -tti~mlntltdl,a'fOWJ!OPtfiltt~llhC~tr;a~

::::: ~-;::::~~~'~*~~

~~==-~::=~:\

. ~

11421'

~._

UC\f

}l,O_ll8..(.~~~~~~.JV
14. _aafC_r~

.. -.-...-

~JJ_Cf~INCI!~

9.15.

11

9. 11i1 1111

241

: taleView:heightForRowAtindexP

th:. ,
. ,

(.

(CCif1.08t)t.teView: (U.\eVill'W )t.\eVt heJfhtForftotlndexPath1 (SlndexPth


inltl'th {

"

11

O\f ,t it\e1)

( l\f.he1Ql!t) {

11 41tef'8.ine \ \ tteights onc.e ror 1\\


sitvt:t\Urra.y. rr {NSutaMrrey ] 1
0ject1 ( [UIN1 niWi'tt'fti.tlNl:~r.ckCe\\6

_NSArray.

"

bund\e:niU

UI.\eVi...C.\ I \ r~1:}~~f~lll~l .\8UotoJ.\I;

cr\\..ckgroundVJw n11.J // r\ .nes


cet.\ . \ectecl8ecqroundV!ew n11; // ditto
SJnteger' u (te\f . tittn COUfrt.);

for (NSint.,.r 1 11 1

".\1.

~"

""
""
"

return UtJ

""
"
""

""

9.16).

\ 1\\

no difference

ur 1+.J {

forl,......th1

};

se\f .heights rr1


}

return (1e\f .ht19ht1 (1ndt'Jt'8th, "*') f\oetV\ueJ 1


}

9.16.

systemLayoutSizeFi ttingSize: .

Autolayout.

, ,
, .

n
. , ,


. .
,
.

. .

,
, . ,
.

InfoPlist. strings
InfoPlist. strings

, ,

242

11.

InfoPlist. strings

, .

InfoPlist. strings. ,
- ,
Empty Window, - 6 , , ,
, ,

. , ,

. strings, .
InfoPlist. strings
I n f . 1 i s t. ,
CFundleDisplayNarne, Info.plist ,
. strings

. ,

Empty Window

Fenetre Vide.

1.

InfoPlist. strings.

lnfo

Localizations

2.

3.

Plus

Localizations.

French.

, ,
(
) .

InfoPlist. strings,

InfoPlist. strings

Finish.

InfoPlist. strings

. , ,

InfoPlist. strings -

(.

9.17). ~.

-.

Ernpty Window en. lproj fr. lproj.


InfoPlist. strings ;
InfoPlist . strings

. , .

9.17.
. string Xcode

. strings -

InfoPlist. strings.

- :

/* Optional comments are c-style comments /


"key = "value";

rna1a 9.

111 n

243

n f . 1 i s t -

InfoPlist. strings

, . ,

InfoPlist. strings

"CFundleDisplayName"

"Empty Window";

InfoPlist. strings

"CFundleDisplayName"

"Fenetre Vide";

1. Empty Window iPhone Simulator.

2.
3.

, .

Empty Window

4.

Xcode.

(, ).

Settings (Gene
rali=>lnternationali=>Languagei=>Francais).
Fenetre Vide.

? ,

i-.

iOS 6

Xcode 4.5

ni-. ,

ni-, ni
. ni-,

, ni- ,

. , ?

internationalization).

(base

ni-

Base. lproj

. str ings

. , ni
. , ,

. strings,

ni-.

Main. storyboard

Empty Window

Base. lproj.

1.

Main. storyboard .
Localization rr Base. , French.

2.

Main. storyboard

3.

Main. storyboard

Main. strings

Main. strings .

, ,

244

Main. storyboard.

11. r11

, .

Main. storyboard,

. :

/* Class

= "IBUIButton";

"Df5-YJ-JE.norma1Title"

4.

normalTitle

= "Howdy!";

= "Howdy!";

ObjectID

"Df5-YJ-JE";

, -,

*/

"Bon j our ! ~

! ,
.

self .button

ViewController.m!

ni-,
ni- .
. ,

"Howdy ! ",

- "Bonj our ! "

ni-,

Main. storyboard,
. strings , .

, ni-,

. , .

1.

Main. storyboard

2.

Filer::)Show

Finder.

Terminal. itool
--export-strings-file output. strings, ,
, Main. storyboard Finder Terminal.
<Return>.

. strings

output. strings.

Main. storyboard

Main. storyboard

, . ruly

Empty, Empty Application


ViewController. xib. .
1.

ViewController. xib

ni-.

Localize .
, ,
. ,

2.

. lproj

Locallze.

Use Base lnternationalizatlon

Locallzation.

3.

, ni-,
.

ViewController. xib,

. !

Finish.

rn111 9. 11l

n n1

245

: r r 11, J , 110
.

: , OJIB1JJIIOTCJI 110, .1111J1: , :r f 11 Empty Window


: : , : : 11
. : J1: - : strings, u. : -
, :r :11 : NSLocalizedString (
localizedStringForKey:tae: 11J1 ::

NSBundle).

, ,

buttonPressed:.

UIAlertView* av [[UIAlertView alloc]


initWithTitle:NSLocalizedStrinq(@"AlertGreetinq", nil)
meaqe:NSLocalizedStrinq(@"YouTappecle", nil)
deleqate:nil
cancelButtonTitle:NSLocalizedStrinq(@"Cool", nil)
otherButtonTitles:nil];
, :11J11.11 : r

nil,

strings.

NSLocalizedString,

( r, :

11, J1,

JI .)
, r

. strings!
strings.

r: Localizae.

r . , ,

1 , , r .

. strings.

1.

2.

r , r .

Fllec>Newc>File.

Resource,

Strings File.

iOS

Next.

3.

Localizae. strings.
Group , r Empty Window.
Create.

4.

11 . Localizae.

r .

Localize

strings
Localization

. r ,
r ;
.

5.

. ,

French.

, Localizae.

strings

, .

itool, r

strings ni-, genstrings


. strings . ,

Terminal
$

246

genstrings /Users/matt/Desktop/Empty\ Window/Empty\ Window/ViewController.m

11. r111

r Localizae,

strings,

/* No corranent provided

enqineer. */
"AlertGreetinq" "AlertGreetinq";

/* No corranent provided
"Cool" 11 Cool"1

enqineer. */

/* No corranent provided

enqineer. */

"YouTappede"

"YouTappede";

r
Localizae.

strings

, ,

. , r
Localizae.

strings -:

"AlertGreetinq" "Howdy!";
Localizae.

strings -

"AlertGreeting" "Bonjour!";
.


(disibution) ,

,
.

ero

, . ..

Store

Store,

(, ) .

- 100

( ),
. , ,
.

r ,
.

Store.

. .

Store.

n111

9. 11t

11n n

247


,
. ;
, ,

. :
,
, , .

. dSYM,

Xcode

, .
.

1.

Productc>Archive

iOS Device.

Scheme

( ,

. ;

,
, - .)

2.

, , ,

Archive Release. (
, .)

3.

Productc> Archive. .

Xcode/Archives.

Library/Developer/

Organizer

Archives,

, , .

; , (
).

,
, ,

! ;
, ,
.

(
) ,
.

Store,

.
,

Xcode,

: Accounts Vlew Detalls ,


Plus iOS Distribution. ,
, .

248

11.

r1111 ~ 1111

Xcode ;
Member Center .

1.

,
, ,

Devices Member Center. (


Store, .)

2.

Member Center,

3.

Plus,

Member Center

Provisioning Profiles,
Add iOS Provisioning Profile

Ad

Store.

.
.
, .

.
,

Xcode!

, ,

4.

"AdHoc" "AppStore':

Generate, .
Download,
Xcode, View
Details Accounts Xcode Refresh

(Ad

Apple , ,
distribution). ,
iTunes, , .

PNG

JPEG

512512

iTunesArtwork .
Bundle Resources.

, ,
.

1.
2.

, .

Organizer Archives Distribute

.
;

3.

Save for Enterprise

Ad-Hoc Deployment.

Next.

Ad

9.

11il 11n

249

4.

Save.

. .

. ipa

("iPhone ").
5.

Finder .

. ipa ,
Desktop, iThnes
Finder iTunes, Dock.

. ipa

,
, ,

r , ,
. ( ,
, , ,

.)

,
, , , u
, .

(,
) ,

Settings

GeneralQProflles).
iThnes, .

Settings).

,
, .

nr n
,
-

Store,

Apple

; , , r
, . .
. "App-Related Resources"
Programming Guide Apple, .

iOS

, ,

- . ,

Release Validate Build Product


Yes. , Empty Window,
, Release, Xcode

, .

-
,

Store, .
Xcode 5 ( ) ,

. ,

250

111

11. 1r1111111

11 111611

General (. 9.18).
PNG

, .
"

kOfll

" Launch 1""'1


Sourc1

L U=A&=t::..==L..J

9.18. 111

JIJ1 ,

Use Asset Catalog

(.

9.18).

Use Asset Catalog

,
, .

,
.

Expected Slze

. ( , "2" ,

, , .) ,
,
(.

9.19). ,

Flnder

-----------------------------------------------------1

Applcon

-~!'!~------~]

i"'"8

fil I0S 7.0 and Laltr SlltS


0

IOS 6.1 and Prior Sll8S

w..i IOS 7. and Later 51-

S 6.1 and l'rlor Sis

$~~~~~-~:~ -;;.;~~~;g~;- . --;~~:~~--- 1 -------~-~-~~~~----------0 15 ,_, " _"ndeted


'41

S.ttlngs 105 5 7

2.!lpl

61

L-----------------------------------------------------------.1
.

9.19.

----~--------------.J

Info .plist .

n111

9. 1111l

251

r nn

PNG

; .

iOS 7

Apple,

-, ,

.
.

(CFBundleicons)

Info . plist

"Icon files"

, . ,

"Icon files"

Info . plist

,
. ,

: ( ,

, , )

@2 .

, (

General,

) .
,

Xcode

Xc0de

Info.plist,

: ,

iPhone,

120120

iOS 7

iOS 7.

iPhone
Finder

. ,

, .

--- ----- ---------- ------1

LPhone

il'lione Spotlight

IPhoneApp

Spotllght - 5 S,6
Settings - IOS S- 7

57

57

40pt

60pt

9.20.

Applcon

me [~i;i~~---------=::o:J
S S 7 . and Later Slzes

IP!n

iOS 6.1 and Prlor Slzs


IPad 5 7 . and Later Slzes
5 6.1 and Prlor Slzes
Q AllSlzes
5 lcon ls pre- rendered

29pt

9.20.

, ,

Xcode
Appicon60x60@2x . png ( "Appicon"

),

Info . plist, ,

.
< key>CFundleicons-iphone </ ke y>

<dict >
< key>CFundlePrimaryicon </ ke y>

<dict>
<key>CFBundleiconFiles </ key>

252

11.

<array>
<string>Applcon60x60</string>
</array>
</dict>
</dict>

,

Xcode 5.

.
iPhoe

IOS 7

120120 .

iPhone ,

iOS 7

iPhoe

IOS 6

5757 114114 .

iPad IOS 7

7676 152152 .

iPad IOS 6

7272 144144 .
, (

), , .
!
,
, (

Settings,

).

iOS 7
Settings 4040

2929 (5858 )

(8080 ) .
.

r nr
-
10241024

PNG, JPEG

Store,
TIFF,

- .
.

Apple

, ,
,
( ).

The

Store

; , .

, ( ),
. ,
, .

iTunesArtwork

, ,

Bundle Resources.

9.

11 n

253

, .
,

PNG.

,
, .

.
,
. ,

,
; .
.

iOS 7 . ,
iPhone, ,

(
, ). ,

iPad, ~ :

( , ).

IOS 6 iPad

,
. ,

20

(..

40 .

GraphicConverter, http://www. lemkesoft. .)


iPhone 5 ( iPod touch),

,
: ,
" '~ , ,

iPhone 4,

("letterboxed")

. "R4~
( ,

6,
Launchimage-700-568h@2x-iphone.png:

, ,
.)

Defaul t,
Info. plist. ,
: -568h iPhone, @2
, -iphone -ipad .
, iOS 7 UILaunchimagesinfo .plist
(. Information Property List Reference Apple).
,

In f . pli st

254

11.

r111

iPhone 4S

640960 ( ;

IOS 7

iPhone

).

iPhone 5

640 1136 ( ;

iPhone 5

.)

iPad
1024768 20481536

Store,

,
. .

iTh.nes Connect Developer Guide


Apple 'J\dding New Apps"; "Upload file sizes and format
descriptions". .

,
, ,

, , ,

iOS 6 ,

,
(
).

IOS 7

iPad

, ,
.

, (,
,
.

Hardware),
Choose File~Save Screen Shot.

Xcode Devices
Screenshots. New Screenshot,
. Organizer.

Organizer

Export,

Store.

<Home>. Camera Roll


Photos, ero (

, ).

11111 9. 11 11

255

Organizer,

(. ):

Save as Launch lmage.

Info. plist

Property List

Reference

Apple.

Information

, ,
. .

(CFBundleDisplayName)

, ;

, .

(UISupportedinterfaceOrientations)
.

General

Inf . pli s t ,

iPhone

, .

"' (UIRequiredDeviceCapaili ties)


, ,

. .
, ,
.

(CFBundleVersion)

General

. - :

Version Build. "Bundle versions string, short"


(CFBundleShortVersionString) Info.plist, - "Bundle
version" (CFBundleVersion). ,
, .
-

Apple Store

. ,
- -

"1.0:
Store.

(UIStatusBarStyle)

Apple

, . " ~ "
~ "

iPad"

..

256

11. r

iOS 7 ,

iPad,

iOS 7

iPhone,

, , .

UIStatusBarStyleDefault, ..
UIStatusBarStyleLightContent, ..
iOS 7,

,
. ,

. ,
: ,

UIStatusBarStyleDefault,
preferredStatusBarStyle.

,
,

Inf . pl ist.

Inf . pl i s t

iOS 6

, -

iOS 7.

Info .plist;

iOS 7 .

iOS 7 .
Info. plist "View controller-based status bar
appearance" (UIViewControllerBasedStatusBarAppearance)paNO.o

, ,

preferredStatusBarStyle ;
statusBarStyle UIApplication,
IOS 6 . UIStatusBarStyle
Info. plist IOS 7; Black
Translucent ("Transparent k style': UIStatusBarStyleBlackTranslucen
t) Black Opaque ("Opaque k style': UIStatusBarStyleBlackOpaque)
UIStatusBarStyleLightContent.

General

Status Bar Style

(UIStatusBarHidden)

iOS 7

prefersStatusBarHidden. , Info. plist


IOS 7 , "View controller-based status
bar appearance" (UIViewControllerBasedStatusBarAppearance)
NO. UIStatusBarHidden , ,
"Hide during application launch" General .

"".
..

."

,.~,'
._____~".:

, .
, ,

- ipod

- ipad.

ero

-iphone,

, .

n111

9. 11"i 11n n

257

111 n -r
-

Store

Store,
Ad .

, ,

Organizer

Ad Store. Store ,
Ad . Store,
; ,
.

, , -

Store

- i1\es

Connect.
IOS - Apple. ,
- http: / / i tunesconnect. apple. ,

IOS.
-

Contracts

iTunes Connect

, ,

, - iunes

Connect,

iunes

Connect Developer Guide Apple,

. ,
.

, -

Store;

"undle

display name': Info. plist.


255 , Apple 70 ,
35. , ,
- iunes Connect, ,

- . ,
.

Apple 580 ).

4000

, ,

Store. , L-

258

11.

1r1111111 :s

, ,

100

Search

Store.

URL-apec -,
; - .

Store.


, .
, . ,
- . ;
.

.
.

. .

Apple

- iunes

Connect

r ,
-

iThnes. Connect

iThnes Connect.

Ready to Upload Binary

, , ,
.

,
:

Validate.

Organizer,

(, .)

, ,

, - iunes

Connect

"Wai ting for


Xcode.
Distribute.

Upload~

Organizer
"Submit to the IOS Store':

n111 9. 111i 11n

259

Application

. ipa,

Loader.

Store. Application Loader,


Developer Tooli::>Application Loader ipa.
Apple,
: "Wai ting For Review"
"In Review" , , , "Ready For Sale" (
Xcodei::>Open

). -

Store.

260

11.

r111

111

iOS
Apple. ,
Touch
iOS. ,
iOS.
. Touch
,

iOS.

, ,

, , .
,
. ,

, ,
, .
.

10, 5,
Objective-C, , ,

11

. ,
. -,
, .
, ,

m.

12 ,

,
.

13

, .

10

Touch

r . r

Objective-C, r.

r,

,
.

11
, , -

, . ,

UIBut ton

, r ,
,

UITextField

, r

, .
, ,
, .
, !
, , ,

, .

r . r , r
, , r
. ,

UIButton , ,

, r r
, r .
r

.
,

, r

ero , r
4). r r

(. r

, , ,

, r .

, , r -
,

r . , r

r , - . , ,

m , .

Touch,

UIViewController,

. ,

Touch,

UIView. Touch
UIView (UIButton, UITextField


..),

.
,

UIView,

drawRect:

UIView.

UIView,

-,

UIView

drawRect:

. : " ,

': ""
: , .. . ,

UIView ,

- .
, , .
,
,

UIView,

1.

Ernpty Window, FileQNeWQFile


Touch Objective-C, ,
UIView. MyHorizLine.
Xcode MyHorizLine .rn MyHorizLine. h.

2.

MyHorizLine .rn

- (id)initWithCoder: (NSCoder *)decoder


self = [super initWithCoder:decoder];
i f (self) {
self.backgroundColor = [UIColor clearColor];
return self;
- (void)drawRect: (CGRect)rect {
CGContextRef = UIGraphicsGetCurrentContext();
CGContextoveToPoint(c, , 0);
CGContextAddLineToPoint(c, self.bounds.size.width, 0);
CGContextStrokePath(c);

3.

View,

UIView Object,
View, .

, .

4.

UIView,

, ,

264

111.

MyHorizLine.

. r
, r

MyHorizLine

ni-. , r ,
r
r

ero UIView.
UIView, r

.
.

drawRect:

UIView

, r

ero

UIView,

. ,

UILabel , ,
drawTextinRect: textRectForBounds: limi tedToNumerOfLines:,

, .

, .
,

UILabel,

.
r , r

UILabel

drawTextinRect :,

r . : "
[r]

r []~ ,
.

1.

UILabel

2.

Empty Window,
MyBoundedLabel.

MyBoundedLabel .m:

- (void)drawTextinRect: (CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextStrokeRect(context, CGRectinset(self.bounds, 1.0, 1.0));
[super drawTextinRect:CGRectinset(rect, 5.0, 5.0)];

3.

. UILael ,

MyBoundedLabel

ero

~.

. r
r . ( -

UILabel.)

, r
r (. r

11)

UIApplication

(.. r r )

r, , r
(

nchingWi thOptions: ).

application: didFinishLau
AppDelegate,
UIApplication. r

,
,

UIApplication,

sendEvent:.

, , .

n111 1. n

265

UIApplication nil
UIApplicationMain ()
main.m NSString r r .
JI , r UIApplication, r

(. r

6).

r
m

Objective-C,

r .
, , , .

self,

, , ,

. , r
. ,
. r ,

(. r

4). r

, ,

. h . m.

, ,

' , ,

ero -

. ,

r , r, , r

r ( r , ).

r r
, r .

, ,

. h.

. h . m,
. m

r pyroro

- , r,

. m

. h

r, r

.h

r.

Fllec:>Newc:>Flle,

. h . m, r

r .

Xcode,

Objectlve-C category

Touch IOS r Choose template.

r , .
r , , r,

r , r
r r

. h.

, ,
r, r

. m.

, ,

. r ,

NSString,

,
.

2'6

111.

NSString

NSString.

r r r

(
r ):

11 StringCategories.h:
tirnport <Foundation/Foundation.h>
@interface NSString (MyStringCategories)
- (NSString*) asePictureNarne;
@end

11 StringCategories.rn:
ltirnport "StringCategories.h"
@irnplernentation NSString (MyStringCategories)
- (NSString*) asePictureNarne (
return [self stringByAppendingString:@"IO"];}
@end

basePictureName

r , , r

NSString.

r . r

basePictureName

.m, r

NSString,

ero . , r
StringCategories. h,

basePictureName
, .

NSString* aNarne [sorneString

NSString, :

asePictureNarne];

r r ,

NSString,

, r .
,

NSString

t llfUco, ,

NSString

r . r r
, .

, r,

. , :
.
r, , :, , r
(. r 13).
,

(UIColor).

r r

, r , :

. , .

@irnplernentation UIColor (MyColors)


+ (UIColor*) rnyGolden {
return [self colorwithRed:l.000 green:0.894
@end

myGolden

pch

u:.541

alpha:.900]; 1

r r

r r r

( r).

r ,
r

[UIColor myGolden]

r.

1111 1. n1 1

267

11

m.

.h

, ,
,

NSString. Foundation,
NSString. h. NSString
length characterAtindex:,

, , .
, ,

. '
NSString. h.
, NSString
NSPathUtili ties. h,
. NSURL. h
NSString,
URL.
'
NSStringDrawing. h
(UIIOt)
.

NSString,

NSString

. ,

NSURL. h,

NSString, NSString. h, NSPathUtili ties. h


NSString,
, NSStringDrawing. h.

"NSString UIIOt Additions Reference" ( NSString


UIIOt). -
, , NSString
. .
AppiDo.

, -

, , :

@interface MyClass ()
11
end

. m,

11 MyClass.m:

@interface MyClass ()
11

268

111.

@end
@implementation MyClass
11
11
@end
,

Empty Window

Xcode.

ViewController .m.

!
"" ,
, ? ,
,
.

(Xcode 4.3)

LLVM

Objective-C

3.1

, .
- ,

,
.
, , , ,

. ,
, , ?

. ,
, ,

, .
, , (
) rr
.

Objective-C

, , ,

12.

, ,
.
,
, . ,
.
.

IBOutlet

, , ,

.
. .

11
-
,
. ,

Bird

, .

1. n

269

Insect,

.
r,

Bird?

Flier

- r
. ,

Ruby

Bird.

ero
Objective-C

Flier,

, r , .
.

. ,

ero, .

'

. ,

myCoolMethod,

MyClass -

, MyClas s u

myCoolMethod,

, , r
. .

, ,
, .

r , . (
, . ,

Ji r , r
, r

3.)

. , r

, r

.
, r r .

NSCopying, (
copyWi thZone:. , NSCopying,
copyWi thZone:. , NSCopying
NSObj ect . h, r ero .
)

@protocol NSCopying
- (id)copyNithZone: (NSZone *)zone;
@end
, .

@protocol,

, r ,

@end.

ero

, ,

ero

. r r

, r , , , .

@optional.

r . r

r ,

270

UIAlertView. h,

111.

Apple.

@protocol UIAlertViewDelegate <NSObject>


@optional
- (void)alertView: (UIAlertView *)alertView
clickeduttonAtindex: (NSinteger)buttonindex;
11 .

..

@end

NSObj ect. h .
NSObject NSCopying.
NSObj ect NSCopying! .
, copyWi thZone: ,
NSObj ect, .
NSCopying

MyClass* rnc = [MyClass new];


MyClass* rnc2 = [rnc copyWithZone: nil];

ARC ,

copyWi thZone:

. .

, .
( , )
.
, .. ( ,

).
, .
, ,

NSCopying.

@interface MyClass : NSObject <NSCopying>


, ,

copyWi thZone:

copyWi thZone:,

. ,

. .

NSCopying.

. .

id, , , .

. . ,
, .

(UITaleView). UITaleView

dataSource,

. :

@property (nonatornic, assign)

id<UITaleViewDataSource>

dataSource

id <UITaleViewDataSource>.

, UITaleView

DataSource,

. .

'l' . .

leView: numerOfRowsinSection:

taleView:

cellForRowAtindexPath:,

tab

, ,
.

dataSource

, UITaleViewDataSource,
,

11111

10. 11

271

MyClass* mc

[MyClass new];
tv = [UITaleView new];
tv.dataSource =; 11
=

UITaleView*

type 'MyClass *_strong'


'MyClass *_strong').

ARC
"Assigning to 'id<UIaleViewDataSource>' from in compatile

( 'id<UIaleViewDataSource>'

MyClass

UITaleViewDataSource.

MyClass

id

<UITaleViewDataSource>,
. ,

MyClass

taleView: numerOfRows InSection: taleView:

cellForRowAtindexPath:,

.
,
,

self.

. m)

, .

11 MyClass.m:
@interface MyClass ()
@end

<UITaleViewDataSource>

@implementation MyClass
- (void) someMethod {
UITaleView* tv = [UITaleView new];
tv.dataSource = self; 1
@end
, ,

, .
( ,
, , ,

).

11,
delegate
id <SomeProtocol>. ,
Empty Window AppDelegate,
,

@interface AppDelegate : UIResponder <UIApplicationDelegate>


,

AppDelegate -

UIApplication,
delegate id <UIApplicationDelegate>. ,
AppDelegate
UIApplicationDelegate.

,
, , ,

. ,

, .

272

111.

, ,

. ,
: ,
, ,
, .. , .

@protocol MyProtocol;
@interface MyClass : NSObject
@property (nonatomic, weak)id<MyProtocol> delegate;
@end
@protocol MyProtocol
- (void) doSomething: (MyClass*) m;
@end

.


, ,

id <SomeProtocol>,
SomeProtocol (


).


, ,

delegate

id <UIApplicationDelegate>,

, ,

UIApplication,
UIApplicationDelegate.

, ,

, ,
. ,

, 8,
, ,
( ) .



. . r
, m
.

. .
,

NSObj ect.

, .
, ,
. , ,
, ,

id,

10. n

273

,
,
. ( - , . ,

iOS 7

.) ,

, ,
.

n

. ? ,
, ,
, , .

, ,
. , ,
, ?
,

Objective-C -

.
, .

respondsToSelector:

NSObj ect,

8001.

, , .

MyClass* mc = [MyClass new];


if ([mc respondsToSelector:@selector(woohoo)])
[mc woohoo];
,
,
. .

respondsToSelector:

- . ,

respondsToSelector:

AppDelegate

Empty Window,

, .

- (BOOL) respondsToSelector: (SEL) sel (


NSLog(@"%@", NSStringFromSelector(sel));
return [super respondsToSelector: (sel)];

Empty Window -

( ).

application:handleOpenURL:
application:openURL:sourceApplication:annotation:
applicationDidReceiveMemoryWarning: applicationWillTerminate:
applicationSignificantTimeChange:
application:willChangeStatusBarOrientation:duration:
application:didChangeStatusBarOrientation:
application:willChangeStatusBarFrame:
application:didChangeStatusBarFrame:
application:deviceAccelerated:
application:deviceChangedOrientation:

274

111.

applicationDidecomeActive: applicationWillResignActive:
applicationDiclEnterBackground: applicationWillEnterForeground:
applicationWillSuspend: application:didResumeWithOptions:
application:shouldSaveApplicationState:
application:supportedinterfaceOrientationsForWindow:
application:performFetchWithCompletionHandler:
application:didReceiveRemoteNotification:fetchCompletionHandler:
application:willFinishLaunchingWithOptions:
application:didFinishLaunchingWithOptions:

, , (
)

UIApplicationDelegate
AppDelegate,
, UIApplication, ,
UIApplicationDelegate.
(. 11). ,

. ,
, ,
. ""

respondsToSelector:

, , ,
.

11

Foundation

Foundation

, ,
. , , ,
.
, ,

.
,

Foundation,

Foundation Famework Reference,

Apple.

NSRange
(NSUinteger) :
location length. , ,
1 location, -
.

, . ,

length,

2,

NSMakeRange
CGRectMake.)

NSMakeRange.

( ,

NSNotFound

CGPointMake

. ,
,

NSArray,
NSNotFound. (

, ,

nil, nil =

111 1. 111

275

, .

-1, r .)

NSNotFound r ,
NSNotFound, ,

. ,

NSRange

location

NSNotFound.

Knacc NSString

NSString

r.
.

NSString

r r @" ",

stringWi thFormat:,

. . r

NSLog.

9,

int = 5;
NSString* s = @"widgets";
NSString* s2 = [NSString stringWithFormat:@"You have %d %@.",

NSString

s];

. ,

length,

,
.
( ),

, , .
,

NSRange,

r ,

String Programming Gide,


rangeOf ... ,

"Characters and Grapheme Clusters"


Apple.

1.

NSString r
NSRange. r, NSScanner

. ,

NSScanner

NSCharacterSet)

, , .

rangeOfString:
NSRegularExpressionSearch

r , r

. r r

NSRegularExpression,

NSTextCheckingResult

, r r , r

4 3.

. , r

, .

276

NSScanner.

111.

NSString* s = 11 , , @"4 3"


NSScanner* sc = [NSScanner scannerwithString:s];
int rows, cols;
[sc scan!nt:&rows];
[sc scanUpToCharactersFromSet: [decimalDigitCharacterSet]
intoString:nil];
[sc scanint:&cols];

cols.

rows

, .

NSString* s = 11 , , @"4 3"


int rowcol[2];
int* prowcol = rowcol;
NSError* err = nil;
NSRegularExpression* r
[NSRegularExpression regularExpressionwithPattern:@"\\d"
options:O
error: &err];
11
for (NSTextCheckingResult* match in
[r matchesinString:s options:O range:NSakeRange(O, [s length])])
*prowcol++ = [[s sustringWithRange: [match range]] intValue];

rowcol

[]

rowcol [ 1].

NSTextCheckingResul t

, , .

NSDataDetector,

NSRegularExpression
URL

, ,

NSLinguisticTagger,

, .

NSString, .


, , , , ,

. NSMutaeString,

NSString.
NSString ,
. NSURL - ,
Foundation. NSString

, , -

NSString URL NSURL.


NSString .
, (, UILabel},
font, UIFont,

, .

iOS 6

(, , ..}, .

NSAttributedString,
Core Text ,

10. n

277

ero ,
IOS 6, NSAttributedString
. Objective-C. r . r ,
.

. r
, , . . ,

. .

r
, . r

NSStringDrawing NSString (.
NSString UIit Additions Reference}, NSAttributedString
(. NSAttributedString UIit Additions Reference).

. NSDa te

NSDate . .
NSTimeinterval), .
[NSDate new] [NSDate date] . .
(

. . . r r .

NSDateComponents

NSCalendar, . -

r (.

Date and 1ime Programming Guide).

. ~ ..

NSCalendar* greg
[[NSCalendar alloc] initWithCalendaridentifier:NSGregorianCalendar];
NSDateComponents* comp [NSDateComponents new];
comp.year 2013;
comp.month 8;
comp.day 10;
comp.hour 15;
NSDate* d [greg dateFromComponents:comp];
r, . .

NSDateComponents.

, :

NSDate* d 11 J\
NSDateComponents* [NSDateComponents new];
comp.day 1;
NSCalendar* greg
[[NSCalendar alloc] initWithCalendaridentifier:NSGregorianCalendar];
NSDate* d2 [greg dateByAddingComponents:comp toDate:d options:O];
. . .
r

NSDateFormatter,
stringWithFormat:

, r

NSString.

.. , .

r ,

., . ( r

NSString.)

, . r , r.

UILabel,

. r .

. r . ,

11

11

() ...

rr ., .
. . . r . .
r .

278

111.

NSDateFormatter *df = [NSDateFormatter new];


if ( [ [NSLocale availaleLocaleidentifiers] indexOfObject:@"en_US"]
!- NSNotFound) {
NSLocale* loc = [[NSLocale alloc] initWithLocale!dentifier:@"en US"];
[df setLocale:loc]; // , ,
11

1
[df setDateFormat:@'"Updated' d 'at' h:n z"];
NSString* updatedString = [df stringFromDate: [NSDate date]];

//

, ,

NSDateFormatter

dateFormatFromTemplate: options: locale:

. ""

, :,
,

, .

NSDateFormatter *df - [NSDateFormatter new];


NSString* format =
[NSDateFormatter dateFormatFromTemplate:@"dyyyyhnaz"
options:O locale:[NSLocale currentLocale]];
[df setDateFormat:format];
NSString* updatedString = [df stringFromDate: [NSDate date]];

//

, : ,
,

Settingsc:>Generalc:>lnternationalc:>Region Format,
20 juillet 2013 5: 14 UTC-7. ,

, ..

,
.

Components for Unicode

iOS

ICU (International

).

, ,

http://demo.icu-project.org/icu-bin/locexp.

IOS ~ , ,
NSDa te

. ,

NSLog

( ) ,

J:.

descriptionWi thLocale:,

( )

, .

Knacc NSNaer
NSNumer ,

BOOL.

, ,

. NSNumer

, . , :

int,

numerWi thint:

[[NSUserDefaults standardUserDefaults] registerDefaults:


[NSDictionary dictionaryWithObjectsAndeys:
[NSNumer numerWith!nt: 4],
@"cardatrixRows",

11111 1. 111111

279

3],
nil]];

[NSNumer numerWithint:
@"cardatrixColumns",

5,

LLVM

4.0

Xcode 4.4)

NSNumer.

BOOL)

@.

( ),

L ( ), LL

( ). ,

3 .1415],
numerWi thBool: YES].

[NSNumer numerWithDoue:
[NSNumer

( )

@3 .1415

@YES -

, ,
@. ,
, @

numerWithFloat:

(height/width)

[NSNumer

height/width].

, :

[[NSUserDefaults standardUserDefaults] registerDefaults:


[NSDictionary dictionaryWithObjectsAnd.eys:
@4,
@"cardatrixRows",

@3,
@"cardatrixColumns",

nil]];
(

NSDictionary.

, .)
NSNumer ,
, .

NSNumer, ,

, .
. , NSNumer

int,

intValue,

, .

NSUserDefaults* ud
int therows = [[ud
int thecols = [[ud

[NSUserDefaults standardUserDefaults];
intValue];
objectForKey:@"cardatrixColumns"] intValue];

objectForKey:@"cardatrixRows"]

NSUserDefaul ts,

, :

NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];


int therows = [ud integerForKey:@"cardatrixRows"];
int thecols = [ud integerForKey:@"cardatrixColumns"];
, NSDecimalNumer, NSNumer,


( , ).
,
.

280

111.

Knacc NSValue

NSValue NSNumer.

,
, , NSArray
.

, NSValueUIGeometryExtensions
NSValue,

CGPoint, CGSize, CGRect, CGAffineTransform, UIEdgeinsets UIOffset (.


NSValue UIit

Additions Reference).

NSRange, CATransformD, CMTime,

CMTimeMapping, CMTimeRange,

Coordinate CoordinateSpan.

NSValue,
, .

n NSDa ta
NSData , ,

, . ,
NSMutaleData.

NSData

. , NSURLConnection
NSURLSession , ,
NSData. , ,

, .

. ,

UIColor

. , ,
UIColor NSData (
NSKeyedArchiver) , .

[[NSUserDefaults standardUserDefaults] registerDefaults:


[NSDictionary dictionaryWithObjectsAndI<eys:
[NSKeyedArchiver archivedDataWithRootObject:
[UIColor ueColor]],
@"myColor",
nil] 1;

, , (.

3).

, ,

, . ,
, , ,

, .

NSString* sl = [NSString stringWithFormat: @"%@, %@", @"Hello", @"world"];


NSString* s2 = [NSString stringWithFormat:@"%@, %@", @"Hello", @"world"];
if (sl == s2) //
11 ".

.n 1. .n

281

(@"Hello, world"),

. ( ,

, ,

@"Hello, world",

. .)
. ,

isEqual:

NSObject

,
. ,
:

if ([sl isEqualToString:

2])

compare : ,
NSOrderedAscending ( ),
NSOrderedSame ( ) NSOrderedDescending (
); . 3.2.
:

NSindexSet

NSindexSet

NSArray.

NSindexSet.

NSindexSet

UITaleView, , .

3, 4, 8, 9 10

NSArray.

NSindexSet

1, 2,

.
, ,

{1, 4}

{8, 3}

NSindexSet

NSRange, NSindexSet
NSindexSet .

NSMutaeindexSet.

NSindexSet

indexSetWi thindexesinRange:,

NSRange

NSMutaleindexSet,
. () ,
NSindexSet, enumerateindexesUsingBlock:
enumerateRangesUsingBlock: .

NSArray NSutaleArray
NSArray

count

objectAtindex:.

4.0 (Xcode 4.5)

LLVM

count - 1.

obj ectAtindex:

, ,
, .

282

111.

, , ,
, .. .
,

@"Manny",

@""

@"Jack",

[ 2] [ obj ectAtindex: 2],


- [ objectAtindexedSubscript:2]. ,
, ,
,

obj ectAtindexedSubscript:.

, , , ,

obj ectAtindexedSubscript:

. , , , - ,

NSArray

-, , , r

, . r

3,

4.0 (Xcode 4.4)

LLVM,

@[ ]

NSArray, .
NSArray*

= @[@"anny",

@"",

@"Jack"];

NSArray , , ,
NSArray, . , , r,

, r ,
.
r r

NSMutaeArray,

NSArray.
addObject:

replaceObjectAtindex:withObject:

NSMutaleArray ,

NSArray. ,

:
[]

@"Zelda";

r NSMutaleArray setObj ect:


atindexedSubscript:. NSMutaeArray ,
[ 3] = @" Zelda" addObj ect:,

, .
,

replaceObjectAtindex:withObject :.

[ 3] = @" Zelda"

, ,
.

()

for ... in,

1.

NSMutaeArray ,

.)

indexOfObj ect:
indexOfObj ectidentical :. ,
isEqual :, .
, ,

, , ,

map () ,

r . (

makeObj ectsPerformSelector:

n1 1. n

283

enumerateObjectsUsingBlock: -

).
,

(.

10.1).

map ()

10.1.

12.

r pyroro

marr = [NSMutaeArray new];


for (id obj in myArray) {
id result = [obj doSomething];
[marr addObject: result];

NSMutaeArray*

,
.

NSArray* = @[@"Manny", @"", @"Jack"J;


NSArray* ems =
[ objectsAtindexes: [ indexesOfObjectsPassingTest:
BOOL(id obj, NSUinteger idx, BOOL *stop) {
return ([(NSString*)obj ra~geOfString:@"m"
options:NSCaseinsensitiveSearch] .location == 0);
}]];
.

,
,

3.1

3.2.

. ,
, ,

. .

NSSet

NSSet

"" , ,

YES.

isEqual:

, , ,

. , ,

; ()

for ... in,

. ,

, , ,
, - .
,
. (

NSOrderedSet)

. ,

284

objectAtindexedSubscript:,

111.

NSOrderedSet

. ,
. ,

NSSet,

, ,
. , ,
. ,

, - ,

NSOrderedSet,

NSArray.
.
, ,

NSSet

NSSet

, NSMutaleSet.

OrderedSet,

NSOrderedSet

- NSMutae
setObj ect: atindexedSubscript:.

, ,
, (
). , .

NSCountedSet

NSMutaleSet

,
. ,
. ,

NSDictionary NSMutaleDictionary

NSDictionary

"-

': .

, ,

NSString.

. NSDictionary ,
NSMutaeDictionary

isEqual:.

"-" NSMutaleDictionary,
, , .
, .

NSDictionary

obj ectForKey: ).
nil, ,

. ,

- .

.

options:

userinfo NSNotification,
application: didFinishLaunchingWi thOptions: ..
Objective-C,

1. n

285

dictionaryWi thObj ects: forKeys:)


nil ( dictionaryWi thObj ectsAndeys:).

"-~
, @{ }
,

NSU s r De f ul t s

[[NSUserDefaults standardUserDefaults] registerDefaults:


[NSDictionary dictionaryWithObjectsAndeys:
@4,
@"cardatrixRows",

@3,
@"cardatrixColUU1s",

nil]];
:

[[NSUserDefaults standardUserDefaults] registerDefaults:


@{@"cardatrixRows":@4,

@"cardatrixColUU1s":@3)];

obj ectForKey:

dict [key].

J;lr "-"

NSMutaleDictionary

setObj ect: forKey:


NSArray,
obj ectForKeyedSubscr ipt:

setObject:forKeyedSubscript:.

.
, , ..,

, .
:

chapterNumer
chapterNumer

[tah] pictureName [return]


[tah] pictureName [return]


, .
:

key: (chapterNumer, as an
value: [Mutae Array]
(pictureName)
(pictureName)

NSNumer)

.
,
.

,
.
, ,

. ,
, ,

286

111.

. ,

Foundation, .

NSString* f = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"txt"];


NSError* err = nil;
NSString* s = [NSString stringWithContentsOfFile:f
encoding:NSUTF8StringEncoding
error: &err] ;
11

d = [NSMutaleDictionary new];
for (NSString* line in [s componentsSeparatedyString:@"\n"])
NSArray* items = [line componentsSeparatedyString:@"\t"];
NSinteger chnum = [items[O] integerValue];
NSNumer* key = @(chnum);
NSMutaleArray* marr d[key];
if (!marr) { // n , ":-"
marr = [NSMutaeArray new];
d[key] = marr;

NSMutaleDictionary*

// marr
NSString* picname = items[l];
[marr addObject: picname];

NSDictionary

N,

. ()

for ... in,

r,

for ... in

ero ,

, , .

obj ectEnumerator,

"-~ ,

NSDictionary,

Objective-C

,
, NSNumer,

NSDictionary

Objective-C,

NSArray

, r .

EditQRefactorQConvert to Modern Objective-C Syntax.

llacc NSNull
NSNull ,
[NSNull null].

nil
nil .
, , ( NSArray, NSSet
NSDictionary), [NSNull null].
, [NSNull null]
, ,

,
. , .

IOS

Foundation,
n111 1. 111111 1

287

. .,
, ,

. ,

[NSArray array] ,
array] - .

[NSMutaleArray

"array",

NSMutaeArray

:
, ?

arrayWithArray:

. accyNSArray,

, ,
. ,
, .
, mutaeCopy- .

.
, ( , )

, .
, , . , ,
(; .

5).

.
, .. ,

.
, , -
, ,

. ,
. ,
.

if ([NSStringFromClass([n class]) isEqualToString: @"NSCFArray"])

//!

, , , ,

if ([n respondsToSelector:@selector(addObject:)])

//!

( , . . , ,
,

NSString

NSMutaeString.)

, ,

....~.

"

""

~-~...

, , .
-
, .

( L) .

NSString, NSData, NSArray

NSDictionary

. ,

Foundation
NSArray NSDictionary

rr ,
,

288

111.

NSDate

NSNumer. (

UIColor

NSData,

.)
. NSArray
NSDictionary wri teToFile: atomically:
wr i teTo URL: tomi cal 1 :
URL .
NSArray NSDictionary

. , ,
, . (

writeToFile: ...

writeToURL:

...

NSStringNSDt

, .)

NSArray

NSDictionary

, ,
.

,

NSPropertyListSerialization

(.

Property List Programming Guide).

11

NSObject

NSObj ect,
NSObj ect

, , .

. .

,
m

(.

NSObject Class Reference).

NSObj ect.

, ,

NSObject

, . (.

NSObject Class Reference).

NSProxy

NSObject.

NSCopying, NSMutae
Copying NSCoding, .
NSObj ect ,
, .
,
. ,

NSObj ect

, .

NSCopying

copyWi thZone:,

,
,

NSObj ect .
awakeFromNib, 7,
UINibLoadingAddi tions NSObj ect,
UINibLoading. h. performSelector: wi thObj ect: afterDelay:,
,

1.

289

11, NSDelayedPerforming
NSObj ect, NSRunLoop. h.

. J1 rnae

4,

, ,

NSObject.

Class,

, , 1

NSObject,

1 l ' ! ,

respondsToSelector: NSObject ,
ero

,
.

, ,

Apple, .

, ,
, .
.

NSObj ect

NSObject Class Reference

NSObject Protocol Reference,


NSCopying, NSMutaeCopying

NSCoding, , ,
NSObj ect.
NSObj ect!
, , NSObject .
NSObject.
, cancelPreviousPerformRequestsWi thTarget:
, NSRunLoop. h. (
) NSObj ect,

, , , , ,

.
, (

J )
. ,

animationDidStart: (
CAAnimation,
, CAAnimation.
awakeFromNib , ,
)

Additions Reference, r

NSObj ect

NSObject

UIit

! (

12),
13).
, , , NSObj ect, ,

) (.

(.

,
,

"

Apple (. "The Root Class"


Objects" Fnd4mentals Gide).

NSObj ect.

290

111.

,
, ,

alloc

, , -
,

ini tialize

(.

(.

11)

dealloc

(.

12);

12).

,
,

class, superclass, isKindOfClass:

isMemerOfClass:.

( ) ,

isKindOfClass:

isMemerOfClass:. , ,
, :

[someObject class]

==

[otherObject class]

, ,
.
, .
.
, , ,
(,

; .

9);

respondsToSelector: );
description,
(isEqual: ).

z
, , ,

(,

doesNotRecogni zeSelector: ).

Objective-C

Rutie Prograig

Gide.

,
. ,

performSelector:

, , ,
. , , ,

, ?

performSelector:,

(performSelector: wi thObj ect: afterDelay:

).

111

10.

291

11

,
.

iOS

, , ,
. , , ,

, ,
.

, ,

.
, ,
.

- (void) buttonPressed: (id) sender {


11 ...
.

, .
, , ,

, . ,

.
,
, .
. , ,
.

iOS

, . ,

. . -
, , ,

,
, . , ,

, - .
, . ,

, ,
.

111 I, ,
. , ,

r r r
r.

n nn
r, r.

, r. ,
r . r,

r. r ,
r , .

, I r.
comUR
11 - r ,

. I, ,
r 01I .

Co6111mUR eikmt1UR
,
, , r , r
r

UIViewController)

ero (,

co6111mUR

, r

,
, r . r ,

UILabel

UIView

drawRect:
drawTextinRect :,

10.

co6111mUR

,
. r .

, ( UITaleView) , ,

r , r .

n
,

( ) .
, r .

10 , UIView

drawRect:. r r .
drawRect: , UIView,

. , r

294

1C11

lll. 1

, , ,
. , ,

. (

drawRect: .
setNeedsDisplay
drawRect: .)
UIView

, . ,
, ,
.

UILabel

10

drawTextinRect:.
UISlider, r.
, thumRectForBounds: trackRect: value:.
UIViewController .
, UIViewController,

, .

Xcode ,

UIViewController,

,
. ,

viewDidLoad

, ,

, , .

UIViewController, supportedinterfaceOrientations,

.
, ,

, .
,

,
,

, ,
. , ,

, ,
,

UILabel,
UILabel.

UIView. UIView , didoveToSuperview


, .
, , ,

ini tialize

NSObj ect.

, ,
,

initialize

initialize.

Empty Window
AppDelegate ,
initialize

. ,

, , m
.

se 1 f

ini t i 1 i ze,

ini tiali ze ,

, , ,

11111

11. 61111111 1

295

. , r r
, .

self, , ,

initialize

initialize.
11 MyClass.m:
+ (void)initialize
if (self == [MyClass class])
11 -

NSNotificationCenter,
[NSNotificationCenter defaultCenter].
, .

NSNotification

( ). ,

r
.

( '). r
( ) , r:

ero .

, . ,
, :

. r
,
r r, r ,

13.

r r r, r

NSNotification r ,

: r : .

NSString,

object
, ( , ,

ero).

userinfo
r .

NSDictionary
user!nfo NSDictionary,

. ,

, r ,

r ,
. , ,

UIApplicationDidCha
ngeStatusBarFrameNotification UIApplication
user!nfo UIApplicationStatusBarFrameUserinfoKey,

296

ilCTb

111. (OCOil

.
,

userinfo

. ,
, , .

. ,

obj ect:

addObserver: selector: name:

observer:
, . , ,

self.

selector:
, , .

void

) ,

NSNotification.
NSNotification* id.

,
!

, ,

selector:,

, , ,

(.

3).

NSString.

nil,

, ,

obj ect:. ,
1,

, ,
.

NSString,

, .
.

object:
, , , .

, ,

nil,
name:.

name:

obj ect:

nil,

, !)

, ,

API

n111

11. 611111

217

r r

MPMusicPlayerController,

, .

MPMusicPlayerController MPMusicPlaye
rControllerNowPlayingitemDidChangeNotification .
, ,

MPMusicPlayerController.

beginGeneratingPlaybackNotifications

, ,

MPMusicPlayerController

mp [MPMusicPlayerController
[mp beginGeneratingPlaybackNotifications];

PusicPlayerController*

iPodusicPlayer];

,
.

[[NSNotificationCenter defaultCenter] addObserver:self


selector:@selector(nowPlayingitemChanged:)
name:PusicPlayerControllerNowPlayingitemDidChangeNotification

object:nil];
, '

PlayingitemDidChangeNotification,
nowPlayingitemChanged:.

MPMusicPlayerControllerNow

- (void) nowPlayingitemchanged: (NSNotification*) n {


PusicPlayerController* mp - [MPusicPlayerController
self-> nowPlayingitem mp.nowPlayingitem;
11 - ...

iPodusicPlayer];

ForName: obj ect: queue: us ingBlock:.

nil,

addObserver

queue :

name: obj ect:


ddObserver: selector: name: obj ect:.

, ,
.

NSNotification.

.
,

name: obj ect:

addObserver: selector:

. ,
, .

mp = [MPMusicPlayerController iPodusicPlayer];
[mp beginGeneratingPlaybackNotifications];
id [[NSNotificationCenter defaultCenter]
addObserverForName:MPMusicPlayerControllerNowPlayingitemDidChangeNotification
object:nil queue:nil usingBlock:A(NSNotification *n) {
self-> nowPlayingitem = mp.nowPlayingitem;
11 - ...

PusicPlayerController*

}
}] ;

298

111

111. 1

, .

addObserver: selector: name: obj ect:

, I
. , ,
, . ,
,

.
,

nowPlayingitemChanged:.

mp,

, .
!

r
, ,
, .

, ,
, m
, .
,

removeObserver:.

( ,

removeObserver: name: obj ect: .)

observer:

, .
, , , .

addObserver:

, ,
, .

addObserverForName:

addObserverForName: ...
id (

). , , .

dealloc

. , ,
. ,

ARC

addObserverForName: .. ,

12.
addObserverForName: ..

,
, , r.
,
. ,

n111

11. 6111111 1

2tt

_observers

NSMutaeSet,

, .

self->_observers

[NSMutaeSet

set];

, ,

id

[[NSNotificationCenter defaultCenter]
addObserverForName:@"whatever" object:nil queue:nil
usingBlock:(NSNotification *note) {
11 ... , ...

}];

[self->_observers addObject:ob];
,
, .

for (id in self-> observers)


[[NSNotificationCenter defaultCenter] removeObserver:ob];
,
, .

NSNotificationCenter

. ,

NSNotificationCenter

, ,
. ,

.
, ,
,
. .

,
.

: .

u
, , ,

. ,
.

. , , ,
,
, . , ,

.
.

postNotificationName: obj ect: userinfo:.

, .
.

, , , .

300

111.

- (void) singleTap: (id) g {


[[NSNotificationCenter defaultCenter]
postNotificationName:@"cardTapped" object:self];

@"cardTapped",

, . ,
, .

,,,,",

..

\~ ".
'-----"l'"~'

Notification

Prograing

Topics for .

Knacc NSTimer
, , .

NSTimer,

()

. ,
. , ,

. ,
.

, . ,
, . .
, .
, ,

.
, , ,
.

. ,
.

arget: selector: userinfo: repeats:

scheduledTimerWi thTimeinterval: t
NSTimer.

, .
.

target:

selector:

, ,

userinfo:

, .

, .
, ,
. ,

, , ,
, , .
, , .

iOS 7

NSTimer

tolerance,

, .. ,

(timeinterval),

1 %

NSTimer,

. .

12

11.

301

nr

- ,

,
. .
. . ,

.
.
,

delegate

).
. .


, .

respondsToSelector:

(nil) (.
10),

10,

. .
,
(

NSObj ect).

, .

nr

, ,
. , .

delegate

( )

. .

, ni-,

delegate

) , .

,
. , , ,
.

, .

UIAlertView.

Cancel,

. . -
, ,

idDismissWi thButtonindex: ),

(alertView: d

UIAlertView,

. ,

(self),

, .

- (void) gameWon {
UIAlertView* av =
[[UIAlertView alloc] initWithTitle:@"Congratulations!"

302

111.

message:@"You won the game. Another game?"


delegate:self
cancelButtonTitle:@"No, thanks."
otherButtonTitles:@"Sure!", nil];
[av show];
- (void) alertView: (UIAlertView*) av
didDismissWithButtonindex: (NSinteger) ix
if (ix == 1) { //
[self newGame];

{ [UIApplication sharedApplication])

, ,

, Xcode.

6,

UIApplicationain,

int main(int argc, char *argv[])


{

@autoreleasepool {
return UIApplicationain(argc, argv, nil,
NSStringFromClass([AppDelegate class]));

UIApplicationMain

AppDelegate.

AppDelegate
10, AppDelegate
UIApplicationDelegate, ,
. , respondsToSelector:
, .

, , . ,

application: didFinishLaunchingWi thOptions:,

,
.

UIApplication

. r ,

, ,
, .

.
, taeView:

didSelectRowAtindexPath:

UITaleView UITaeViewSelectionDidCha

ngeNotification.

should {), will

{)

did

{). ,

, - ;
.

BOOL,

should

did -

will

-,

NO,

YES,

-.

11. 61111

303

, . ,

should

, .

,

. ,

scrollsToTop

, . ,

YES,

NO

scrol l ViewShouldScroll :.

,
. , ,

UITextField,

, -,

UITextField.

textFieldDideginEdi ting:

UITextFieldDelegate.

UITabBarControllerDelegate.

...

n nr
, ,
.
,
,

.
, , ,
, .
,

SorneProtocol

delegate,

id <SorneProtocol>.

, ,
. ,

. ,

SorneProtocol,

. ,
. , , :

SorneProtocol

, ,

.
, .

Done

Cancel,

ColorPickerController.

, , ,
.

ColorPickerController

, .
.

304

111.

- (void) colorPicker: (ColorPickerController*)picker


didSetColorNamed: (NSString*)theName
toColor: (UIColor*)theColor;
: ?

, , ,

Controller,

SettingsController.

ColorPicker

SettingsController Color
PickerController. .

SettingsController
ColorPickerController.


SettingsController,
ColorPickerController, . ,
ColorPickerController SettingsController,
,

, , ,

SettingsController.

ColorPickerController.

, .
, ,

ColorPickerController

,
- .

ColorPickerController

! ,

ColorPickerController

, ,

ColorPickerController, -
ColorPickerContoroller ,

. ,

delegate

. r

, , .

ColorPickerController.
10.

@protocol ColorPickerDelegate;
@interface ColorPickerController : UIViewController
@property (nonatomic, weak) id <ColorPickerDelegate> delegate;
@end
@protocol ColorPickerDelegate
11 color == nil
- (void) colorPicker: (ColorPickerController *)picker
didSetColorNamed: (NSString *)theName
toColor: (UIColor*)theColor;
@end

SettingsController
ColorPickerController,
ColorPickerController. ,

11.

305

ColorPickerController ,
colorPicker: didSetColorNamed: toColor:, : ero .
, ColorPickerDelegate,

- (void) dismissColorPicker: (id) sender


11 Done
[self.delegate colorPicker:self
didSetColorNamed:self.colorName
toColor:self.color];

Xcode

Utility Application,

, .

MainViewController, FlipsideViewController.
FlipsideViewController r ,
flipsideViewControllerDidFinish: ,
ero . , FlipsideViewController
FlipsideViewControllerDelegate, flipsideVie
wControllerDidFinish: delegate, id <Flipsi
deViewControllerDelegate>.
MainViewController Flipside
ViewController,
FlipsideViewController. ,
MainViewController FlipsideViewControllerDelegate!
, .
,

Utility Application


, ,
.
UITaleView,

UICollectionView, UIPickerView
UIPageViewController.

iOS

.
? ,
.

, , , ,

(. "--"

13).

,
, ,

.
, .

, .
,

, . ,

306

111.

,
.

UIPickerView,

(
).

UIPickerView,

UIPickerView.

, ,
.

- (NSinteger)
return 1;

nnerOfComponentsinPickerView:

(UIPickerView*) pickerView {

- (NSinteger) pickerView: (UIPickerView*) pickerView


nnerOfRowsinComponent: (NSinteger) component {
return 7;
- (NSString*) pickerView: (UIPickerView*)pickerView
titleForRow: (NSinteger)row
forComponent: (NSinteger)component
NSArray* arr = @[@"Sunday",
@"Monday",
@"Tuesday",
@"Wednesday",
@"Thursday",
@"Friday",
@"Saturday"];
return arr[row];

UIControl.

, ,

(.

7) ..

UIControl,

,
.

(UIButton),
(UISwitch), (UISegrnentedControl),
(UISlider) (UITextField).
( ) ,

UIControl.

. ,

Val ue Changed

, ,

Touch Up Inside

.
(, ),
. , ,

, ,
.

.
,

11111

11. 61111

307

"-~
), t>

, .

, ,
"-~ ,
(.

11.1 ).

TouchOown~

' myOject ....~~~

Toudl Up lnside
Touch Up Outside

myOject

11.1.

"-"


: ni-,

7,

addTarget: action: forControlEvents : , target:


action: - , ControlEvents: -
( , , . 1). ,
,

but tonPressed:,

7.

. .

- (void) buttonPressed: (id) sender {


UIAlertView* av = [ [UIAlertView alloc] initWithTitle:@"Howdy!"
message:@"You tapped me . "
delegate:nil

308

111.

cancelButtonTitle:@"Cool"
otherButtonTitles:nil];
[av show];
,

7 ni
Touch Up Inside
buttonPressed: ViewController.
"-", ViewController,
ni- , - buttonPressed:,
Touch Up Inside.
, :

ni-
. ,
,

button.

7.)

ni-

[self.button addTarget:self action:@selector(buttonPressed:)


forControlEvents:UIControlEventTouchUpinside];
"-".
,
. "-" ,
"-': . ,

ni-
, ,

buttonPressed:

id.

UIEvent, .

buttonPressed:, sender.
buttonPressed: ,
sender .

, .

UIEvent

w~: , -
( , , ).

UIEvent

,
. ,
(

NSSet)

UIEvent ()
UITouch).

UIEvent,

, ,
! ,

11.

309

Touch Up Outside,

Touch Up Inside

"-"

.
, , .
f) ,u rU1 : OS

OS

, ,

OS

OS

IOS.

IOS


. r,

OS
IOS .

r1 11

UIEvent,

, ,

Qacca UIResponder

, , ,
, . ,

UIView, UIWindow, UIViewController


UIApplication. IOS 5

n
.

UIResponder,

UIEvent,
touchesBegan: wi thEvent:, touchesMoved: wi thEvent:,
touchesEnded: wi thEvent: touchesCancelled: wi thEvent:.

.
, ,

,
.

hi tTest: wi thEvent:
UIView ,

pointinside:withEvent:

, .

sendEvent: UIApplication, , , sendEvent:


UIWindow, - (..

).

, , , . ,

UIView

, ,

UIView,

UIWindow

(..

).

310

111. 1

UIView ( ).

UIViewController,

UIView,

UIViewController,

UIView,

, :

UIWindow.
UIApplication.
UIApplication.

n
rr ,

.

,
, .
.

.
.

UIView

. ""

UIView,

, .

UIViewController,

-,
,
.

Board, UIView. -
UIView
Board. .
-, Board,

-. ,

.
,

- ,

Board,

, -
, . , , .
-, .

"-~

(nil).

, .
: (.. ,
),

, .
, , .

n11111. 611111111 1

311

self.button addTarget:nil action:@selector(buttonPressed:)


forControlEvents:UIControlEventTouchUpinside];
. , ?
r ,

UIButton
buttonPressed:. ,
UIView r ,

. , ,

, ,
( ).

, , r

self

, , , r

buttonPressed:,

buttonPressed:!
r ni-,

- r pearpyloero .
!

, ,
, - r rr
.

1.

- r rr ni-
.

2.

(, )
r rr .

Plus

. , ,
.

3.

<Control> (
UIButton) - r rr ,

r.

. , r rr

r rr
,

becomeFirstResponder,

canBecomeFirstResponder.

YES

!
rr , r ,
r ,

( ),
r .

11
,
, r .

r ,

312

111.

, ,
. , ,

, , .. ,
,
. , ,
.

iOS.

, ,

, ,

.
, ,

, .
,

iPhone

, . , ,
, UITaleViewController,

UIViewController,

, UITaleViewController,

. , ,
. ,

, , .

ini tWi thCoder:

ini tWi thNibName: bundle : 1

UIViewController,

UIViewController,

viewDidLoad

, .

viewDidAppear:
111

UIViewController,

, . ,
, ,
, .

viewDidDisappear:

, ,

UIViewController,
viewDidAppear:. ,

, ,

viewDidAppear:.

supportedinterfaceOrientations

UIViewController,

, .

. .

11. 111

313

numerOfSectionsinTaleView:
taleView:numerOfRowsinSection:
taleView:cellForRowAtindexPath:

UITaleView, r

.
taleView:didSelectRowAtindexPath:

r r UITaleView, r r

r .

dealloc

NSObj ect,

r r

.
,

viewDidAppear:

, r

r . r

, , ,
, .

,
, . r

, . ,
,
.

r r !

,
. , , , r,
, , ,
r ,

, .

r rr , ,

, r

viewDidAppear:

. r

r, r , , .
(
, r , ,

8).

r ,

IOS

), r ,r ,

.
, , ,

UIViewController,

r r

. r , ,

, ( , )
, ,

iOS,

,
, .

314

111.

, .

, .

. , ,

"
~ , ,
,

viewDid.Appear:,

. , ,

viewWillAppear:.

" ,
~ ,

viewDidLoad,

, .

" ,

supported

InterfaceOrientations

". ,

supportedinterfaceOrientations
UINavigationController,

.
.

"

Value Changed,

, ,

~ , ;.
Editing Changed, Value Changed.
, , .
, , ,

, . .
,

, , .
, ,
, .

, .

,

NSLog ()

(.

9).

. , .
, ,
,

UIViewController,

viewDidLoad

, .
,
.

NSLog () ,
NSLog ( ) ,

viewDidLoad ,
awakeFrornNib, .
: view
awakeFrornNib, viewDidLoad.

, .

n11111. 611111111 1

315

n n
,
.

, ,

, .

, , , .
:

, .
.
- , ,
.

, .

, , . ,
, ,
, - ,
, . ,
,
, .

, , ,

. t ,

.
.

performSelector:withObject:afterDelay:

NSObj ect

10.

,
. , , .

dispatch_after

3.

, ,

dispatch_async
.
,

. ,
.

dispatch_async

, , : .

.
, . , ,

, ( ),
.

, ,

,
:

- (void) taeView: (UITaleView *)taeView


didSelectRowAtindexPath: (NSindexPath *)indexPath

316

111.

TracksViewController *t =
[[TracksViewController alloc]
initWithediaitemCollection: (self.albums) [indexPath.row]];
[self.navigationController pushViewController:t animated:YES];
, , ,

Collection:

TracksViewController

ini tWi thMediaitem

.
, .
- , ,

UITaleViewCell,
:

- (void)setSelected: (BOOL)selected animated: (BOOL)animated {


i f (selected) (
[self.activityindicator startAnimating]; //
else {
[self.activityindicator stopAnimating]; //

[super setSelected:selected animated:animated];


. , . ,

setSelected:animated:

UITaleViewCell ,

taleView:didSelectRowAtindexPath:
UITaleView. , ,
taleView: didSelectRowAtindexPath:. ,

.
! tab
leView: didSelectRowAtindexPath: , .
, setSelected: animated:
.

initWithMediaitemCollection:

- (void) taeView: (UITaleView *)taleView


didSelectRowAtindexPath: (NSindexPath *)indexPath
11 ,
doue delayinSeconds = 0.1;
dispatch_time_t popTime =
dispatch_time(DISPATCH_TIE_NOW, delayinSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), (void) (
TracksViewController *t =
[[TracksViewController alloc]
initWithediaitemCollection: (self.albums) [indexPath.row]];
[self.navigationController pushViewController:t animated:YES];
}) ;

11.

317

12

5:

Objective-C,

, .

.
:

Objective-C.


.
, , gt-,
, ,

st-.1

(.

5),


, ( ) .
:

, ,
- .

Objective-C

, :
,
, .. .
, ,
.

, .
.

, .

- . .

Gt-

set,

, ).
: ,

. ,

myVar

_myVar),

setyVar:.
St-

(
, ).
, ,
gt-

. ,

myVar

_myVar),

MyVar.

BOOL, gt
is (, gt-
_showing isShowing),

showing

Objective-C

. ,

.
.
, , ,
.
, ,
! ,

setMyVar:

myVar

myVar

(_myVar).

, , ,
, ,

Objective-C

. ,

,
.

, , V,

NSString ,

.
( , )

NSKeyVal ueCoding,

NSObj ect,

, . ,

Programmig Guide,

320

111.

Key-Value

Codig

Apple, .

setValue: forKey:.

valueForKey:

. , .
, .

~ ,

.
,

, :
" ". (
, , ,
, .) ,
:

[myObject setValue:@"Hello" forKey:@"greeting"];


setGreeting:

myObj ect.

, ,

@" 11 ".

@"Hello" greeting (
_greeting), myObject.
,


! ,

,
accessinstanceVariaesDirectly, -

YES

NO

valueForKey: setValue:forKey:,
- ,

. ,

, J; ,

.
, ,

BOOL, NSNumer,
CGRect CGPoint) - NSValue.
dictionaryWi thValuesForKeys: setValuesForKeysWi thDictionary:,
"-" NSDictionary .
(,

NSString, .
NSString ,

. ,
, .

val ueForKey:

, ,
. ,
.
, .

12.

11

n11 111

321


J .

flashcard

Term,

, .

. ,

,

. , .


. ,
, .

NSinteqer taq = q.view.taq;


11 taq
NSStrinq* key = nil;
switch (taq) {
case 1: key ~ @"lesson"; break;
case 2: key = @"lessonSection"; break;
case 3: key = @"lessonSectionPartFirstWord"; break;
1
11
NSStrinq* curValue - [[self currentCqrdController].term valueForKey: key];
11

. .

NSArray

valueForKey:,

, ( ) .

NSSet.

NSDictionary valueForKey:
objectForKey: (
NSArray). setValue: forKey:
NSMutaleDictionary setObj ect: forKey:,
, value: nil.
removeObj ect: forKey:.

NSSortDescriptor

valueForKey:.

NSArray

CALayer

CAAnimation

.
.

NSManagedObj ect,

Core Data,

,
. ,

322

111.

valueForKey:

setValue: forKey:.

(. r

7). ni-.

MyClass myVar ni-


myVar , ni
, ni- MyOtherClass. ni- myVar
setMyVar:, setMyVar: MyClass,
, MyOtherClass .
, myVar MyClass
MyOtherClass (. . 7.7).

- ni-
, r ni-


, , .
r , ,
(

).

, ni- .
, r, ,
, ( )
(. " " r

7).

r , ,
.

MyClass myVar,
setMyVar:, myVar.
, r ni-,

myVar

ni-. , MyOtherClass.
,

MyOtherClass
setMyVar: . r
myVar (nil).
setMyVar: r ,
myVar ni-. ,

myVar,

111
.
, ,

r ,
r , ,

valueForKeyPath: setValue: forKeyPath:.


, . ,
val ueForKeyPa th:@ "keyl key2 ", , ,
val ueForKey: @" keyl" ,
valueForKey: ,
, @"key2 ".

n111

12.

11 n11111 n11111

323

, , ,

myObject

theData, ,
name description. ,
theData NSLog ().

description = "The one with glasses.";


narne = anny;

1,
{

description
narne = ;

"Looks

little like Governor Dewey.";

1,
{

description = "The one without


narne = Jack;

mustache.";

[myObj ect val ueForKeyPath: @"theData. "]


@"Manny", @"" @"Jack".

valueForKey:

NSDictionary.

. , ni-
,
.

, ( ),
. ,

myObj ect.

- (NSUinteger) countOfPepBoys {
return [self.theData count];
(id) objectinPepBoysAtindex: (NSUinteger) ix
return (self.theData) [ix];

countOf ...

obj ectin ... Atindex:

,
(

- @"pepBoys") .
@"pepBoys"

, , ,
- (

NSKeyValueArray). ,
[myObj ect val ueForKey: @"pepBoys"], -
, [myObject valueForKeyPath: @"pepBoys.name"],

, .

324

111.

.
,

objectinPepBoysAtindex:

-, ,

NSArray,

NSMutaleArray.

-, V,
, ,
-, mutaleArrayValueForKey:.
; ,

theData -

- (void) insertObject: (id) val inPepBoysAtlndex: (NSUinteger) ix {


[self.theData insertObject:val atlndex:ix];
(void) removeObjectFromPepBoysAtlndex: (NSUinteger) ix
[self.theData removeObjectAtlndex: ix];

[myObject

mutaleArrayValueForKey:

@"pepBoys"],

. (
mutaleArrayValueForKey: ,

13.)

,
, ,

. , ,

removeObj ectFromPepBoysAtindex:.

@"pepBoys ",

.
, .
, , ,

,
. ,

, , .

11
,


,
. ,

ARC,


, , , , ,

,
, . ,
,

ARC

, ,

, ,

ARC

, .
,

12. n

ARC.

11 n11 111

325

qn nRI
,
. r

1,

( , -

111) , r
, , r
, , r
. ,

alloc.

r ?

, r ,

r. r
, r
r. . r r

, "'. r,
r r

. .
"

Objective-C

IOS , r

r r,
( , ). ,

IOS

- ,
, . , r

, r

.
(.. ) . ,

Jack

Manny Jack

Manny

, ,

"". , ,

ero

. ,

, ,
.

r ,

Objective-C r

r , r r
. r r
. , ,

. r
. ,

r , .
r ,

Jack, ero , r
ero . ,

r ,
r r, .

r , , r

326

Jack,
Jack, r ero .

111.

, ,

Jack, , ,
Jack ,
, , Jack

.
, ,
. (.. ,
) ,
.

ARC

ARC,

, ,

, ,

ARC.

n r nn n1

,

, .
, , ,

, ,

iOS.

, , .
, , .
, ,
. , ,
.

, . , ,

. ,
. ,

Manny, , Jack , .
Jack ,
Jack.

.
.

retain. .

, , , ,

retain

. ,

[myObject retain] ,
myObj ect, .

alloc

new),

. ( ) ,

alloc

new.

, (.. )

12. n 11 n11 ~

327

, .

, ( ) ,
.

release.

alloc ( new)
retain ,
release .

, .
, .


, . ,

Manny alloc,
Jack, .
Jack ,
Jack. ,
Jack, ,
retain

, , . , ,

Jack,

ARC,

, .

ARC , , retain
release . ,

.
, ,

, .
, ,
.

ARC

. ,

ARC,

, , ,
. !

,
,

(nil).

, .

, , .
,

ARC.

ARC

release,

3,

ARC

, ,

, .
:

ARC,

. , ,

ARC

, .

328

111.

n w n
,

. ,

ARC, , , ,
ARC, ,

.
.
(.

9).

(Debug)

,
.

, Productc::>Aalyze,

lnstruments

(),

Productc::>Profile,

, .

, . ,

dealloc NSLog (). , ,


.

, ,

lnstruments.

, ,
-.

lnstruments

Zomies. ,

Run , Diagnostics n
Zomble Objects. ,
-,
~
. -

. -

Leaks, .

, .
, ,

UIView,

, , ,

lnstruments

. .

,
. .

11

12.

11

n1111 n~

329

1111

11 +11111 ARC
Xcode 5
ARC. , , .

Objective-C Automatic Reference Counting (CLANG_ENABLE_OBJC_ARC)

LLVM

YES.

retain

release

.m.

Xcode, ,
<Control> ni
, , ARC.

ARC,

.
EditQRefactOQConvert

to Objective-C ARC,

Xcode

ARC . ,
ARC , , - ,
, ARC,

, ,

, .
,

ARC,

Build Phases ( ),

ARC,

Compile Sources -fno-obj c-arc ,


Compiler Flags.

",
..

~
\~.

..

'-----~

ARC

LLVM 3.0

http://clang.llvm.org/docs/AutomaticReferenceCounting.html.

retain

.m

release

ARC

, ,

release.

retain

.
, ,

1.

ARC retain

release

ARC ,

. ,
,
. , ,
, ..

,
. , , .
,

. ,

330

111.

retain

release

, , ,

, .

2.

release

ARC

retain

, ,

. ,
-

, .
:

- (void) myMethod {
NSArray* myArray = [NSArray array];
NSArray* myOtherArray = myArray;

, .

ARC,

retain

release

ARC

, ,

nil

, ,

, . .
, , ,

,

ARC

12.1.

12.1. n ARC

- (void) myMethod {
//
NSArray* myArray = nil;
// ,
id templ z myArray;
myArray = [NSArray array];
[myArray retain];
[templ release]; // {no effect, it's nil)
//
NSArray* myOtherArray = nil;
// ,
id temp2 = myOtherArray;
myOtherArray = myArray;
[myOtherArray retain];
[temp2 release]; // (no effect, it's nil)
// ,
// ,
11
[myArray release];
myArray = nil;
[myOtherArray release];
myOtherArray nil;

ARC, .
rnyArray rnyOtherArray

, ,

12. 11

ynpa1ne11e n11111

331

. ,
,

release

nil

ARC

ARC,

,
.
,

alloc

retain

release.

, ,

release.
ARC

.
, ,
,

ARC

( )

, . (

, , :
.)

new,

mutaleCopy,

ARC ,

alloc, ini t,

release.

[NSArray array]

[NSArray new]

ARC

,
, ,
anew.


,

),

new,

alloc, init

ARC.

mutaeCopy.

, , , ,

ARC

. (

, ,

.)

n n1
, ,
. , ,
. ,
,
.
( .

NSArray NSDictionary

10).

,
. , ,

,
. , ,
.
, . ( ,

332

111.

, ,
.)

ARC

. :

NSString* s

= myMutaeArray[O];

[myMutaleArray

//

removeObjectAtindex: 0];

ARC!

, ,

.
,
myMutaleArray.

, .

,
. ,

ARC

, ,

, ,

12.2.

12.2.

NSString* s
[s retain];

ARC

= myutaleArray[O];
//

[myMutaeArray

removeObjectAtindex:

ARC

];

, , ,

, .
,

NSString* s

= myMutaeArray[O];

[myMutaleArray

//

ARC,

removeObjectAtindex: 0];

ARC

, , ;,

12.1,

ARC
ARC

, , ,

12.3.

12..

ARC

NSString* s = nil;
// ,
id temp = s;
s = myMutaleArray[O];
[s retain];
[temp release]; // , ..
11
[myMutaleArray removeObjectAtindex: ];
/ / . . .
[s release];

s = nil;

n 12.

11 n11 n11

333

, , ! ,

removeObjectAtindex:,

. , ,

ARC

12.2.



, I

5?

, ,

NSArray* myArray

[NSArray array];

myArray, .
alloc, , ,
. ? NSArray

,
?
,
, ..

ARC,

~,

NSArray.

array,

? ,

NSArray,

NSArray,

, .

- (NSArray*) array {
NSArray* arr = [[NSArray alloc] init];
return arr; //, ...
-, .

alloc.

arr

,
?

arr,

arr.

"~ .

arr,

return

, - ,
,
,
.
,

alloc

. ,

ARC,
autorelease, .
- (NSArray*) array {
NSArray* arr = [[NSArray alloc] init];
[arr autorelease];

334

111.

return arr;

autorelease

, ,

- (NSArray*) array {
NSArray* arr = [[NSArray alloc] init];
return [arr autorelease];

autorelease .

. {

main. m,

.)

autorelease

,
. , ,

. ,

release

. ,
. ,

autorelease

release

, , , , .

, , , ,
, . ,
, , ,

array,

, ,

array,

. , ,
. , ,
.

[NSArray array],

, ,

.
, .
, , , .


, .


, , ,

[NSArray array].

, ,
, . - ,
. -
, , ,

NSMutaeArray .
, ,
, , . ,

, , , ,
,
, . ,
, .

12.

11 nn11 n11

335

ARC,

. ,

autorelease.

ARC

. , ,

array,

new, init, alloc,

mutaleCopy,

. , ,

autorelease
ARC , .
array

.
, ,

, ,
, .

ARC.

for (NSString* aWord in myArray) {


NSString* lowerAndShorter = [[aWord lowercaseString]
[myutaleArray addObject: lowerAndShorter];

sustringFromindex:l];


: ,

. (..
) ,

,
.
, .
,

.
, ,

, .
,
.

.

Objective-C

@autoreleasepool {},

for (NSString* aWord in myArray) {


@autoreleasepool {
NSString* lowerAndShorter =
[[aWord lowercaseString] sustringFromindex:l];
[myutaeArray addObject: lowerAndShorter];

336

111.

: ( )
,

alloc

init

(..

). , NSMutaleArray

array init.
alloc ini t

? ,

, .

, ,
.

1 n (

ARC ,

ARC)

, . ,
,
, ,

release.

retain, alloc

autorelease.

, :

. ,
, , ,
,
.


, ,
,
, . , ,
, ,
, ,
- .

. ,
- .
,

, ,

ARC

, ,

.
:

12.

n 11 nn11

337

d = [NSutaeDictionary dictionary];
11 .. d
self-> theData = d;
11 ARC . !

NSMutaleDictionary*

ARC

,
. ,
. ,

.
:

[d retain];
self-> theData

d;

, :

self->_theData = d;
[self->_theData retain];

retain

, ,

, .

self->_theData = [d retain];
.
, , , pyzozo

self->_theData.

, , ,

.
, , - ,

st-. ,

12.4 ,

.
12. st-

- (void) setTheData: (NSMutaeArray*) value


if (self->_theData != value) {
[self->_theData release];
self->_theData - [value retain];
}

12.4

(nil),

. ,

(nil),

, ,
, , , ,
, ( )

self->_theData.

,
, .

, ! ,

338

111.

[self setTheData: d];


,
r .
r r , ,
.

[self setTheData: nil];


.
, .

,
, r .
,
, .

dealloc NSObj ect

(. r

10), , r

- (void) dealloc {
[self->_theData release];
[super dealloc];

-~

dealloc ,
super dealloc.
ARC, dealloc ,
r, ARC r .
r

ARC

, ! r
,

dealloc

, coxpaJteo. r, ,
.
! , r

? . , ,
, , ,

dealloc.

(. r

, , , , r

5).

r .
r

ero

(.

Dog

5.3).

, , !
, _name,

NSString, ,
12.5 ,

.
.

11

12. n11 n11

339

12.5.

, r

- (id) initWithName: (NSString*) s {


self = [super init];
i f (self) (
self-> name = [s retain];
return self;

. ,

NSString ,
NSString

NSMutaleString, , -

ini tWi thName:

, , (
.

12.6 ,

Dog)

12.6.

, r

- (id) initWithName: (NSString*) s (


self = [super init];
i f (self) (
self-> name = [s ];
return self;

12.6

_ name

, - ,

. ,
.

, ,

ARC, : ,
dealloc. !

, , .
,

ARC

Objective-C ,

, ,
).

n n n

ARC)

ARC,

. ( ,

) . ,

ARC

, ,
.
.

ARC

. ,
, ,

340

111.

.
, .

self->_theData

d;

ARC,

, :

11 11
11
id temp = self->_theData;
self->_theData = d;
[self->_theData retain];
[temp release];

ARC.

12.4. ,

, , !
.

ARC.

, ,

ARC

- (void) setTheData: (NSMutaeArray*) value {


self->_theData = value;
, ,

ARC

, ,

dealloc!

ARC,

- . ,

dealloc

(.

11),

.rls ,
'sur. (

dealloc,

ARC

.)

. '
11,

.~

"

.___ __.~4.,'

release,
ARC ,

? :

(nil)

(,

). ,

ARC

.
,

ARC

, ,

12.5 12.6.
ARC , , ,
retain. , ARC
12.5 , 12.7.

12.

nn n1

341

12.7. n, ~r J
ARC

im~

- (id) initWithName: (NSString*) s {


self = [super init];
if (self) {
self-> name = s;
return self;


,

12.6
ARC, 12.8. -
ARC , ,

,
.

12.8.

n, ~r

m~

ARC

- (id) initWithName: (NSString*) s {


self - [super init];
if (self) {
self-> name - [s ];
return self;

11 11

ARC .

ARC

, - . ,
, .

. ,
,
.

: , ,
.

,
. ,
, , .
, ,

. . ,
,
_ thing

dealloc,

@implementation MyClass
id _thing;
- (void) setThing: (id) what {

342

111.

MyClass

setThing:,

self->_thing

= what;

- (void)dealloc
NSLog (@"%@", @"dealloc");
@end
:

MyClass* ml = [MyClass new];


MyClass* m2 = [MyClass new];
ml.thing = m2;
m2.thing = ml;
,

ml

ARC

MyClass -

dealloc

m2,

ml

m2,

, .

MyClass.

,
, .

_weak

, .

@implementation MyClass
_weak id _thing;
.
,

MyClass

ARC

release, , ml
m2, , ,
.

"".
',
11 ,

.__'<__.~~.

ARC

, ,

. , , -

ARC .

_strong,

,
. ,
:_unsafe _ unretained _autoreleasing.


(.

11).

. , ,

, . :
, .
. ,

. , ,

Utility Application,

Xcode

@property (weak, nonatomic) id <FlipsideVieWControllerDelegate> delegate;

11111

12.

n111 n111111 n111111

343

weak

_delegate

weak.

ARC
, , , ,
. .

ARC. ARC
, , , (-
, ) . ,
, "~

.
,

ARC.

, ARC ,
, ! (

, . ,

ARC .) ,
ARC.

, ,

, ,

, "': (

_ unsafe _ unretained,

.)

ARC .

,
, .
, ,

assign.

ARC,

ARC .

delegate

UINavigationController

@property(nonatomic, assign) id<UINavigationControllerDelegate> delegate


,

ARC,

, - .
,

UINavigationController

"~ , ,
. - ( )
, , ,
, ,
.
,

_ BAD_ ACCESS (.

obj _ retain
12.1). ,

Apple

- , .
.

- (,

UINavigationController}

ARC

, - ,

344

(nil)

- , .

111.

~ 1 _57~ oppllalion:...
2 _dJ_dl_coll_block_ond_rtleo
a 1i . iiiA;,;;i~~~I~

..............."

~12""""

11

8x1474ddf:
8x1474del:
llx1474de31

testt

'lleax,

je

8x1474dfe
('lleax), -

l!l!IVl

11

8xl474de8:

and\

u
"

81474d:

testb
je
addt

$-4, 'lledx
$64, l('lledx)
8x1474dfe
$8, 'llesp

'llebp

15

1
.

12.1.

8x1474def:
8x1474dfl:
8x1474df4:

movt

"'

obj c_retain + 42

J.6J_~)!}J ~.1\ ~~~~i.~i!ii!!~~~~~


; obj c_retein + 46

"

n n

NSNotificationCenter

. , , ,
(.

11).

addObserver: sele
ctor: name: object:, , (
self) .
ARC, , ,
,

, , , "':
, .
, .

ForName: obj ect: queue : usingBlock :, ,


ARC, .

,
:

object : queue: usingBlock : ,

addObserver

addObserverForNa

se 1 f)

, .
,
.

dealloc,

, .

, ,

self->_observer = [[NSNotificationCenter defaultCenter]


addObserverForName:@ "heyho"
object:nil queue:nil usingBlock: (NSNotification *n)
NSLog (@"%@", self);
}] ;

dealloc

- (void) dealloc (
[[NSNotificationCenter defaultCenter] removeObserver : self->_observer];

12. 11 n1111 n11~

345

dealloc
self,
self. ,

- . ,
, -

, .
.

_ observe r . ,
dealloc - . ,
dealloc, _ observer

.
,

viewDidDisappear:

UIViewController,

,
.

- (void) viewDidDisappear: (BOOL)animated {


[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self.observer];
self->_observer = nil; //
, .
, .

s 1 f,

dealloc . ,
_ observer _weak,

. ,
,
, ,

viewDidDisappear:

self.

, ,

viewWillAppear:.
self , ,
dealloc, , - .

, :

s 1 f.

self

, (

) . ,

dealloc,

self

? ,

, " " (.

12.9).

, .

self

, ,

self,

, .
, , .

346

111.

12.9. n

n cpontx , nn~ ~ 1 n

aelf

~weak

MyClass* wself self;


self-> observer ([NSNotificationCenter defaultCenter]
addObserverForName:@"heyho"
object:nil queue:nil usingBlock:(NSNotification *n)
MyClass* sself wself; 8
if (sself) {
11 sself,
11 self 8
1];
" ~

12.9.

self

, ,

. .

.
. , , (

self),

,
, .
, , ,
.
.

self

. ,

, . ,
, ,
.

NSTimer
NSTimer ,
, scheduledTimerWithTimeinterval: target:
selector : use r I n f : repea t s : - ,
(.

10).

. ,

, .

inval ida te.

. )
scheduledTimerWi thTimeinterval: target: selector: userI
nfo: repeats: target:, ,
self. , self

, .

dealloc,

invalidate. , -
invalidate .

, .

dispatch_source_t

GCD. ""

, ,

12. 11

n11111 n111

347

ARC,

"': ,
, , ,

(nil).

, ,
. ,
.

@implementation MyClass {
dispatch_source_t _timer; //

ARC

- (void)doStart: (id)sender
self-> timer = dispatch source create(
DISPATCH SOURCE TIER~O,O,dispatch get main queue());
dispatch source set- timer (
self=>_timer, ctispatch_walltime(nil, 0),
1 * NSEC_PER_SEC, 0.1 * NSEC_PER_SEC
);

id wself = self;
dispatch source set event handler(self-> timer, {
MyClass* sself ; wself;
i f (sself) {
[sself dnny:nil]; //

~weak

});

dispatch_resume(self-> timer);
- (void)doStop: (id)sender
self-> timer = nil;
- (void) dummy: (id) dummy
NSLog(@"timer fired");
- (void) dealloc {
[self doStop:nil];
@end
r , ,
. ,

UIWebView ,
UIWebView, ,
(nil) delegate. CAAnimation

. , ,
.

,
,

ARC

- .

ed: completion:

setViewControllers: direction: animat


UI PageViewControl ler. completion:
UIPageViewController,

, ,

348

111.

), ,

(pvc

"

pvc,

':

..

il ".

........".

~-

iOS 6,

NSPointerArray,

NSHashTale NSMapTale,

NSMutaleArray, NSMutaleSet

NSMutaleDictionary,
, , . ,
NSHashTale, weakObjectsHashTale,

ARC

.
.

r ni-n nn
ni-

IOS

ni- ,

, .
, .

.

ni-

loadNibNamed: owner: options:


instantiateWi thOwner: options: UINib (. 7),
NSArray, ,
ni-. ,

NSArray

, ni-

- .
instantiateWi thOwner: options:

.
. ,

UIApplicationMain ()

ni-

rootViewController

, .

ni-
, ( , ).
, (.

12.2).

ni-, ni-

UIViewController

UIView

ni-,

setView:

12.

11 nn11

n~

349

:.

12.2.

, ,
, . (

IBOutlet

, ,

_weak..

, , ,

_strong,

ni-

.) '

OS

ni-,

OS

OS

iOS.

ni-

, .
,

NSWindowController,
iOS ,

ni- , .

1 n rnn
, ,
.

K&R,

4.3),

Objective-C,
(. 1) ( .

K&R

z11 . ,

static.


.
,

. r . ,
- , rr

, , , ,
.

Objective-C

. r

, .

NSString* const

350

YSTRING

111.

@"my string";

, ,
, , :

? , ,

, ,
..

initialize

(.

11).

,
.
, ,

. -
, , ,
.

ARC,

, , . ,
, , ,
, .

ARC

. , , ,
, , , ..
, .

n n n CFypeRef

CFTypeRef
Ref (. 3).

. ,

Objective-C,

, .

ARC

. ,

Objective-C, CFTypeRef.
CFTypeRef, ,
ARC. CFTypeRef
Objective-C ,
ARC .
, Objective-C,
(alloc, retain),
CFTypeRef. :
CFTypeRef , Create ,
,

CFRelease (),

.
, .

Apple,

, .

- (void) addPattern: (CGContextRef) context color: (CGColorRef) incolor


CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(baseSpace);
CGContextSetFillColorSpace(context, patternSpace);
CGColorSpaceRelease(patternSpace);

n 12. 11 nn 11

351

CGColorSpaceRelease(baseSpace);
11 .
,
,

baseSpace patternSpace
CFTypeRef, - CGColorSpaceRef.
, Create, ,
CGColorSpaceRelease (), release,
.

CFRetain () CFTypeRef,

, ,

CFRelease ().

.

(nil)

Objective-C ,
CFRelease ()

. ,

CFTypeRef

, -

.
, CFTypeRef

Objective-C. 3,
Core Foundation
. ( "Toll-Free Bridged Types"
Core Foundation Design Concepts, Apple.)
, Core
Foundation . , CFStringRef
Create () () NSString,
release NSString
, CFRelease ().
ARC , , .
ARC

, , ,

ARC

ARC

Objective

CFTypeRef,
ARC. ARC

,
. ,

CFTypeRef

, , ,

ARC,

CFTypeRef

, ,

...

"Implicit conversion ... requires bridged cast" (

).


, ,

ARC,

, . ,

352

111.

Create ()
release

ARC

(),

CFStringRef

NSString,

NSString. ARC,
release, ARC
: CFStringRef
, CFBridgingRelease ().
id,
NSString. ,

Create ()

().

.
mny _bridge

_bridge,

. ,
.

NSURL

Objective-C

9),

CFTypeRef. imageSource
CFURL.

CGimageSourceRef src CGimageSourceCreateWithURL((~bridge

CFURLRef)imageSource, nil);

ARC .
, ,

imageSource

NSURL

Objective-C,
ARC, . imageSource

CGimageSourceCreateWi thURL () ,
CGimageSourceRef. ,
src CGimageSourceRef
CFTypeRef, ,
CFRelease () , .

CFBridgingRelease ()

CFTypeRef

Objective-C,

ARC ,

, , ..

CFTypeRef (,
Create () ()). ARC


. ,

_bridge_transfer.

, .

CFDictionaryRef resl = CGimageSourceCopyPropertiesAtindex(src,


NSDictionary* res CFridgingRelease(resl);

nil);

CFRelease () resl
CFTypeRef,
CGimageSourceCopyPropertiesAtindex (),

CFDictionaryRef.

n111

12. n1

n111 n11111111

353

). .

res Objective-C, ARC

, .

w~ CFridgingRetain

()

CFBridgingRelease

Objective-C

().

CFTypeRef. ARC

, .

Objective-C, CFRelease ()

CFTypeRef.

_ridge_retained

Objective-C

CFTypeRef,

, ,

, .

CFTypeRef

Objective-C.
Objective-C, I

, CFTypeRef "~

CFBridgingRetain () ,
CFTypeRef - CFRelease ().

CFBridgingRetain (),
CFBridgingRelease ().

Objective-C,

CFTypeRef id
setContents: CALayer id,
CGimageRef. ,
, 3, CFTypeRef
id. ,

. ,

id,

_ridge, .

CGimageRef moi = 11 - .
self.v.layer.contents = (~bridge id)moi;

CFTypeRef

_bridge

, .

self.v.layer.contents

(id) [UIImage imageNamed:@"moi"] .CGimage;

, (,

UIImage)

CGimage:

- (CGimageRef)CGimage NS_RETURNS_INNER_POINTER;

354

CGimage

111.

n n n
,

void*

context:.

id,

void*,

, .

,
. ,

void*

void* -

id

. ,

,
.
?

context:,
context:

, ,

-
. ,

context:
beginAnimations: context:,
animationDidStop:finished:context:
context:. , context: ,
animationDidStop: finished: context :.
context:
context: context:.
, ,

context:

static void* const

N =

(void*)&YCONTEXT;

MYCONTEXT ,
context:
. context:,
, self. ,
,

, , ,
.

context:

. - .
, ,

context:

void*,

ARC,

Objective-C

. " " (.. ).


.

Objective-C,

context:

(_bridge void*).
(_bridge id).

_bridge.

. ,

user!nfo:

postNotificationName: obj ect: userinfo:


NSDictionary

, . ,
, .

11

12.

11 n11111 n111~

355

(property) -

(.

5).

[self setTheData: d];


self.theData = d;
.

d = [self theData];
d = self.theData;

. ,

ero

, gt-

get- st-.

,
, , , .
r ,

Xcode.

, .

.
, .

,
. r

, ,
.

, . -
.


. !

@synthesize

,
.


. , ,

. , ,

, .
!


, ,

356

111.

Objective-C.

, ,
, "
: ,

@synthesize

" ':

4.0 (Xcode 4.4).

LLVM,
@synthesize,

!
.

, -

@synthesize

. , ,
,

.

( )

. ,
( ),
.

r n
, ,

ARC

strong, retain
.

ARC.

retain

ARC,

ARC

() , , ,

ARC

ARC

strong retain, ,

, ,

. ,

11

12.

11

1111 n11111

357

i (,

NSString NSMutaleString NSArray

NSMutaeArray) , r

, r i. (.
r

S)

, , , r

m1 , 1IJ1

ero .

1IJ1 r (. r

10),

ero amero .

weak

ARC m1 .
ARC , ero,

, , ,

. r, r
r ,

, ,
, .

ARC.

weak ARC ,

assign
r , r

ARC,

weak.

, .

ARC,

, ,

, .

ARC (_unsafe_unretained)

, ,
, 1IJ1 , .

, r "

~ . ,
, , , .

n i
, , ,

.h,

. .

@property

(,

... )

@property (nonatomic, strong)

NSMutaleArray*

theData;

,
( ),

358

111.

st-

(setTheData:)

gt-

(theData)

r st- r gt-.

ni-, r

IBOutlet. r

Xcode, r .

orna .
,

BOOL, CGFloat CGSize. , r

, , r
, .
, r ,
.

, rr.

r .
r .
r

strong;

ARC,

ARC r .

nonatomic
,
, , r

. r , r
.

nonatomic

r . ,
, r . r
,

nonatomic

lmpllclt Atomlc Objectlve-C Propertles.

readwri te wru readonly


,

readonly,

readwr i te.


. i ,
.

gettergname, settersname:

get- st-,

r . ,

gt-

myProp, st- -

myProp,
setMyProp:. r

, . ,
getterbeeebrox , gt-
r r. ,
gt- .
r ,

.
r ~,

(.

10).
n111

ero

12. ~ 11 ynp11neue n11t~

359

.m, .. , . . r
uacce, u: , ,r uaccax,
ux 12.10.


01I

ux

12.1 . 61t11111 llpllOl'O

11 yClass.m:
@interface MyClass ()
@property (nonatomic, strong)
@end

@implementation MyClass
11
@end

NSutaleArray*

theData; //

l'l'

II JJ.
r .

JCJJacCa . r
r

.h
ero u, JJ.

uacca

. _,

(readonly)

uacca,

(readwri te)

uacca.

r ,

readonly r , ,
readonly ,

, r, .

readonly

readwri te,

@synthesize.

.
, =

@synthesize,

, .

, . ,

..".

,
, . ,

11,
,.~.

:,.

JJ , . -

~---'"

, ,

360

111.

theData,

@synthesize theData;

(theData

setTheData:,

) .

theData ,

, , ,
, ,
(

dealloc,

ARC

),

Xcode 4.2

Apple

, ,
. ,

AppDelegate

@synthesize window

= _window;

,
:

self. window.
window,

, ,
, _window. ,

. ,
, . ,

window)

. ,

@synthesize,

) . ,

theDa ta

- ,

_ theDa ta.

@synthesize.

(,

, ,
, .. .)

12.11

name,

Dog

, ,

_ name. .

12.11.

11 Dog.h:
@interface Dog : NSObject
- (id) initWithName: (NSString*) s;
@property (nonatomic, ) NSString* name;
@end
11 Dog.m:
@implementation Dog

12.

11 nn nJ

361

- (id) initWithName: (NSStrinq*) s (


self [super init];
if (self) (
self->_name [s ];
return self;
- (id) init (
NSAssert(NO,
return nil;

@"aking

nameless dog is

fordden.");

@end
,

@synthesize

,
. ,

.
(

@synthesize)

,
. :
, , .

r =
=

@synthesize,

, . ,
,

_myivar,

. , ,

myivar
12.10), , ,
myivarAlias, myivarAlias
_mivr. myivar,
myivarAlias
_myivar. ,
3 (. 12.12).
, myivar.
(.

11

12.12.

nt11111 111

@interface MyClass : NSObject


@property (nonatomic, strong)
@end

11

NSNumer*

myivar;

NSNumer*

myivarAlias;

@interface MyClass ()
@property (nonatomic, strong)
@end

@implementation MyClass
@synthesize myivarAlias_myivar;
- (void) setMyivar: (NSNumer*) num

362

111. 1

11

JJ

self.myivarAlias num;
-

(NSNumer*)

11

myivar {

JJ

return self.myivarAlias;
1
@end

@synthesize

@dynamic ( ). r

,
.
, ,

,
, , . ,
.
,
.

, . , ,

:
,

Core Data.

, -
.
, ,

.
, ,
, , ?

Objective-C

. , ,
.

, ,

NSString)

name

numer ( NSNumer),

name

numer

.
, ,

, .

11

1!'1'

name

numer

@implementation MyClass {
NSString* _name;
NSNumer _numer;

@dynamic name,
11 ...

numer;

..

@end

11111

12. n111 n1111111

n111~

363

resolveinstanceMethod:

NSObj ect.

m r r r
. r ,
r, . r :

,
,

resolveinstanceMethod:

. , ,

BOOL.

resolveinstanceMethod:
YES, ,

resolveinstanceMethod:

, ?

.
,

Objective-C .
resolveinstanceMethod:

r . , r

YES,

, .. ,

class_addethod

(). ,
<obj / runtime. h> @import Objective-C,

. .

, .

( , ).

(IMP)

IMP?
Objective-C
Objective-C,

, .
. ,

- , . ,
self , ,

, ,
. , .

, . ,
.

(name
(setName: setNumer: ). ,
resolveinstanceMethod:,
IMP

numer)

class_addethod()
,

. , !
,

? r :

gt-, , , ,

st-, .
gt-, .

gt-?

364

111.

. ? ,
.

, ,
, .. ,

, .

, .

, , ..
.

id callValueForKey(id self, SEL _cmd) {


NSString* key = NSStringFromSelector(_cmd);
key = [@"_" stringByAppendingString:key];
return [self valueForKey:key];
, gt-, , st-. ,

,
, :

set

,
, . ,
.

void callSetValueForKey(id self, SEL _cmd, id value)


NSString* key = NSStringFromSelector(_cmd);
key = [key sustringWithRange:NSakeRange(, [key length]-4)];
NSString* firstCharLower =
[(key substringWithRange:NSakeRange(O,l)] lowercaseString];
key = [key stringByReplacingCharactersinRange:NSakeRange(0,1)
withString:firstCharLower];
key = [@"_" stringByAppendingString:key];
[self setValue:value forKey:key];
,

resolveinstanceMethod:.

, ,

, , ,
. ( ,
,

class _ addethod ()

, ,

.)

+ (BOOL) resolveinstanceMethod: (SEL) sel {


11

if (sel == @selector(setName:) 11 sel == @selector(setNumer:)) {


class_addethod([self class], sel,
(I) callSetValueForKey, "v@:@");
return YES;
if (sel == @selector(name) 11 sel == @selector(numer)) (
class_addethod([self class], sel, (I) callValueForKey, "@@:");
return YES;
return [super

resolveinstanceethod:sel];

n111 12. n1

ynp1111eue n111~

365

, J11.
11 JJI J J

JC11acca NSString.

366

Objective-C.

111.

13

. , ,
. r

,
.
, .
. ,

Manny

Jack

, .
,

Manny

Jack.
Jack

, anny

.
r,
, ,

ero

r , .

Manny
Jack, r r (. r 12). ,
.. r ,
,

"-~ , UIControl, . r

Manny

r , r

Jack

, , ,
(, ,

ARC).

, ,
. ,

ero,

r, . ,

, .
,

. ,

Manny
Jack , r Manny.
r Jack
Manny, Jack i
r . .

textFieldShouldeginEditing: UITextField,
. "-"
r . , Manny

Jack, anny,
.

Manny Jack? .

iOS

r r r , r
CCllKU r . ( r

5.)

, r.

, Manny ,
Jack , ,

r , , Jack.
,
r. r :
r r
r

IOS.

, r n n
- - . ,
r , r,
. , r
. r Manny Jack, r
Jack.


. Manny Jack

, Jack, Manny
, , r, Jack. r

, Manny , Jack
Manny. Manny
Jack, Jack .

r. Manny
Jack ero r. Jack ,
, , Manny r Jack
.
,

UIActionSheet UIAlertView, r r
UIBarButtonitem, r

,
.

. r Manny Jack,

Manny,
r . -, Jack ,
Manny r , Jack. ,
, Jack,
r .
r
r . r

368

111.

, (

TrackViewController),

TrackViewController
ini tWi thediaitemCollection:,

TrackViewController

- (void)showitemsForRow: (NSindexPath*) indexPath {


11
TrackViewController *t =
[[TrackViewController alloc] initWithediaitemCollection:
(self.albums) [indexPath.row]];
[self.navigationController pushViewController:t animated:YES];
self Track
ViewController, TrackViewController
self. self TrackViewController,
- . , self
, TrackViewController
, .

, , ,
.

ni- , , ni
. (

. xib

ni-,
; .

7).

ni- ,

ni- ni-
, ni-.

Manny
Jack, .
Manny, , Manny ,
Jack. , Manny
Jack. r Manny.
, iOS
, it: ,
ni-, , . xib

. , ni- ni-
. , .
" ni-"

7,

.
ni- .

(Jack) -

(Manny)

ni- .

, , .

. , - ()
.
. ,
,

. ,

. ,

prepareForSegue: sender:,

(.. ).

n 13. 11

369

,
( )

Jack

Manny

( ).

Manny)

, .. (

Utility Application,
MainViewController.)

, r w
,
.

, ,
, .

superview.
subviews
tag , viewWi thTag:.
window. ,

, .
, ,

. , ,
.

, ? ni-

(1, 2, 3

(101, 102, 103 ..),

..).

UIView* v = sender; //
UIView* v2 = [v.superview viewWithTag: (v.tag - 100)];
(.

11)

nextResponder.

.
,
.

UIResponder* r = self; // UIView


while (! [r isKindOfClass: [UIViewController class]])
r = r.nextResponder;


.
,

presentedViewController, presentingViewController.
UINavigationController,
navigationController.
UINavigationController

visileViewController. ,

370

111.

view.

. ,

, , ,
,

r pyroro .

nn
r , ..

. .
, .
, , , r r
.

, r

tion, [UIApplication sharedApplication].

UIApplica-

keyWindow
UIApplication. r, r
, ero delegate. :
r

r ,

rootViewController

r ,

,
.

r , r
. r , ,
,
.
I
,

[NSUserDefaul ts standardUserDefaul ts].


, ( , ).

, . ,


. r ,
.
, ,

@"haz yS tr ipy".

,
. ,

.
,

@"hazyStripy",

@"hazyStripy",

r ,

@"hazyStripy"

,
, , . ,
,

13. 111

371

, ,

, !
, ..

@"hazyStripy"

(.

13.1).

,
,
, ,

.
(mn )

[NSUserDefaults
standardUserDefaults)

13.1.

n
(.

11)

, , ,

.
: . ,
.

.
, .

11.


. (
) , ,

( .

NSTirner,

12).

,
, ,
,
. ,
, ,

, .

372

111.

11 11
(

KVO) -

, r ,r ,
. r
r, , - , r,
, .

, r
, , r r

.
"-" (. r

11), ,, , ,~ . (
V NSKeyValueOs\rving,
, r

NSObj ect

,r .)

, r r .
r .
,, r .

-~

~ ,1U1 rUU1 11
,

OS

OS

IOS,

r, , r

V.
V . r.

r r , ,r ,
, r .

, ,r , , ,
V. , , ,
r , , .

( ,
,, , ,r , ,
V.)

,
r r , .

,
V.

MyClassl, ,
obj ectA, MyClass2, , obj ectB.
, r obj ectB , r
value objectA,
. , obj ectB .

11 MyClassl.h:
@interface MyClassl : NSObject

11

13. 11111 061t1111

373

@property (nonatomic,
@end

NSString* value;

11 MyClass2.m:
- (void) observeValueForKeyPath: (NSString *)keyPath
ofObject: (id)object
change: (NSDictionary *)change
context: (void *)context {
NSLog(@"I heard aout the change!");
11

- ~ :

MyClassl* objectA [MyClassl new];


MyClass2* objectB - [MyClass2 new];
11 r~ V
[objectA addObserver:objectB forKeyPath:@"value" options:O context:nil];
11 change the value in V compliant way
objectA.value = @"Hello, world!"; 8
11 observeValueForKeyPath: ...
11 objectB

objectB
objectA addObserver:forKeyPath:. options:
context:, ; . ( , con text:

, ; .

12.)

, , z,
.
.

obj ectA

KVO ,

: ,

.
( ),

V .

obj ectA ,
observeValueForKeyPath: ... objectB.
MyClass2, .

, .

KVO.

observeValueForKeyPath: ...

. , ,

,
. , ,
, , .

- (void) observeValueForKeyPath: (NSString *)keyPath


ofObject: (id)object
change: (NSDictionary *)change

374

111.

context: (void *)context {


id newValue [object valueForKeyPath:keyPath];
NSLog(@"The key path %@ changed to %@", keyPath, newValue);
, .

options:, .

,
.

objectA.value = @"Hello";
[objectA addObserver:objectB forKeyPath:@"value"
options: NSKeyValueObservingOptionNew 1 NSKeyValueObservingOptionOld
context: nil];
objectA.value = @"Goodye"; //

change

- (void) observeValueForKeyPath: (NSString *)keyPath


ofObject: (id)object
change: (NSDictionary *)change
context: (void *)context {
id newValue
change[NSKeyValueChangeNewKey];
id oldValue
change[NSKeyValueChangeOldey];
NSLog(@"The key path %@ changed from %@ to %@",
keyPath, oldValue, newValue);
,

, .
m

(.

12). ,

removeObserver: forKeyPath:.

, .

(nil),

. , , ,
, . ,
,

dealloc.

, ,

, .
,
, !

, . -,
,

I<VO

. , ,
,

I<VO,

. ( ,
. , , m
, .)

I<VO

iOS

, ,

. ,

11111

13.

1111 0611111

375

, , , ~ L

, mutaleArrayVal ueForKey:,
, -. ,

theData ,

(. r

12).

description "The one with glasses.";


name anny;
},
{

description "Looks
name - ;

little like Governor Dewey.";

},
{

description - "The one without


name Jack;

mustache.";

NSMutableArray.

@"theData"

[objectA addObserver:objectB forKeyPath:@"theData" options:O context:nil];


' ,
,

mutaleArrayValueForKey: -, .

[[objectA mutaleArrayValueForKeyPath:@"theData"J removeObjectAtindex:OJ;


11
-,

mutaleArrayValueForKey: . r
, mutaleArrayValueForKey:.

r .

11 MyClassl.h:
@interface MyClassl : NSObject
@property (nonatomic, strong, gettertheDataGetter)
@end

NSutaeArray*

theData;

11 MyClassl.m:
- (NSMutaeArray*) theDataGetter {
return [self mutaleArrayValueForKey:@"theData"J;
r , r '

@"theData"

theData

theData,

[objectA addObserver:objectB forKeyPath:@"theData"


options: NSKeyValueObservingOptionNew 1 NSKeyValueObservingOptionOld
context:nil);
[objectA.theData removeObjectAt!ndex:O); //

376

111. 1

, (

MyClassl) , V,

r (. r

12). ,

-, .

, r

self-> theData ,
-;- ero ( ,
). - r
, , r
:

- (NSUinteger) countOfTheData {
return [self->_theData count];
- (id) objectinTheDataAtindex: (NSUinteger) ix
return self->_theData[ix];
- (void) insertObject: (id) val inTheDataAtindex: (NSUinteger) ix
[self->_theData insertObject:val at!ndex:ix];
(void) removeObjectFromTheDataAtindex: (NSUinteger) ix
[self->_theData removeObjectAtindex: ix];
,
. , .

@"description"

r r

ons: context:,

addObserver: toObj ectsAtindexes: forKeyPath: opti

, r

, ,

r, r ,
.

Apple, ,

V. r , ,
, . ,

V. ,

NSUserDefaul ts

Apple ,

V .
r ,
V.

NSNotification.

AVPlayer,

r , , ,

status

rate,


. AV Foundation Programming Guide,

Apple,

AVPlayer

ero

13.

377

JJJ ,
ero - Vale Observig Gide,
Apple. . ,

, , r r

observeValueForKeyPath: , r

- r

. , ,
r r,
, - . , ,
V , r r
.

n
0 n-nn-nn"

Apple

""--",

MVC.


nr,
. , r, , r

. MVC

Smalltalk, ero r rr

. ""-
.

"
-r
r, .. .

,
r.

r , r r
. r r
.

UILabel,

r, . ,
, .
, (

r), r

r .

r r,

UILabel, , ero,
ero UILabel, ,
, ero

378

111.

. ,

MVC.

, 11 r, 11 .

, , .. .

,
r, ,

Score

UILabel

. , ,
.

.
, , r ,
, , .

, : "

UILabel,

20'~ ,

20

(.

MVC.

13.2)

. ,

, ,
, . ,
.

.J!I

13.2. "11--"

MVC

. .
,

UIView

UIViewController -

UIPickerView

, .

. ,

11

UIPickerView

13.

379

Apple,

V: ,
I

, I ,r .
, ,
:, .

, L- ,

. ::
L- ,
, ,

(Kevin allard).

FeedParser,

UITaleView

:, .

UITaleView ,
, L-
, ,
, , .

MVC

, ,

. ,
,

, . ,
,
, , ,

"-':
.

380

111.

334
159
, 38
,

&

169

335

169

169
, 169
, 22
break, 36
continue, 36
goto, 36
switch, 35
,

,44

87

,80

I}>

Frameworks, 137
Products, 13 7

184;307
, 311

,162;166

, 261
Core Graphics, 157
Foundation, 157
UIit, 157
, 266

,302

#define, 45
#import, 43
#include, 43
#warning, 46
@class, 90
@dynamic, 363
@implementation, 87
@interface, 87
@synthesize, 360
, 320

3
87

,254

46

const,46
static, 46
, 51
NSArray, 282
NSData, 281
NSDate,278
NSDictionary, 285
NSindexSet, 282
NSMutaeArray, 282
NSMutaleDictionary,

NSObject, 96
NSSet, 284
NSString, 276
NSTimer, 301
NSValue, 281
,85

306

172; 323

169

,169

357

,
,

24; 96

,208

231
, 231
, 231
, 283
, 96
, 98

287

,85
,
,
,

224

,267

287
270

285

19

,320

,126;211

125; 211

,127

self, 102
super, 105

,
,

109

22
++, 23

',49
,

,23

132; 213
123
, 131
,

,192

,378
,

163

141

Debug. 141
Release, 141

242

32

,
,

91

33

215

r,215
,

52

217

,108;319

get, 319
set, 319
,

274

145

224
, 91

,
,

212

125

130

ARC,330
fix-it, 210
v, 320; 323

V,373

38

ARC, 61

,
,

,378

129

,128

126
127

382

316

40

,33

217

r,36

65
alloc,96
autorelease, 335
init, 96

32

,32

32
do, 36
for, 35
if."else, 34
return, 38
while, 36
,32

24

Clang,24
GCC,24
LLVM,24
LLVM-GCC, 24
, 22
, 145
, 128

129

86; 263

11

54

350
107

85

102
, 162;378
, 25
, 373

326

335

Xcode, 121
, 122

Devices, 201

-,
,

269

273

,288

,232
,

232

232
, 210

Quick Help, 197



,

193
Availability, 194
Class methods, 195
Conforms , 194
Constants, 195
Declared ln, 195
Framework, 194
Inherits From, 194
lnstance Methods, 195
Overview, 195
Properties, 195
Related, 195
Sample Code, 195
Tasts, 195

323

268

,
,

30
163

,247

,

Store, 247

247

296

,268

Availability, 196
Declared ln, 196
Description, 196
Discussion, 196
Formal Declaration, 196
Parameters and Return Value, 196
Related Sample Code, 196
See Also, 196

87

ni-,
,

161

149

,
,

326
111;356

183
, 184

232
, 126; 198
, 214
, 255
, 210
, 261; 293
,
,

,
,
,

294

,294

,

96

50

227
162

85

142
163

294

,294

nib, 99

Touch, 261
59

,343

69

iPad,201
iPhine/iPad, 202
iPhone, 201
, 128

174

301
301

223
24
CGF!oat,25
char, 24
dou!e, 24

383

floar, 24
int, 24
long, 24
NSinteger, 25
NSString, 26
NSUinteger, 25
short, 24
unsigned short, 24
, 25
,27

,134

,
,

Main.storyoard, 146
nib, 99; 148
Pkglnfo, 147
storyboard, 99
ViewController.m, 146
xib, 99
, 89; 199

89

205

,37

219

,219

,
,

,285

296
,

28

,326

137

29

,342

205
, 34
, 326

138
Compile Sources, 138
Bundle Resources, 139
Link Binary With Libraries, 139

,41

AppDelegate.m, 146
Assets.car, 146
Info.plist, 147
InfoPlist.strings, 146
main.m, 146

384

296

1111n11

,229
,

229

,230

,
,

229

229

MVC,378

51

310