Professional Documents
Culture Documents
Copyright 2006 by Bert Altenburg, Alex Clarke and Philippe Mougin. Version 1.2.
Attribution: The licensors, Bert Altenburg, Alex Clarke and Philippe Mougin, permit others to copy,
modify and distribute the work. In return, the licensees must give the original authors credit.
Non-commercial: The licensors permit others to copy, modify and distribute the work and use the
work in paid-for and free courses. In return, licensees may not sell the work itself, although it may
accompany other work that is sold.
P
P
MS
__________________________________________________ 4
; 0 =
0C% *______________________________________
5
; 1 =
1A?,<(+
_____________________________
7
; 2 =
BD2
@&8$__________________________
13
; 3 =
#______________________________________________
14
; 4 =
OG_______________________________________
20
; 5 =
KRI7A_____________________________________
25
; 6 =
9-__________________________________________
33
; 7 =
! while ".L-_______________________________
36
; 8 =
1F!)
/GUI(A___________________
39
; 9 =
>Q&_______________________________________
55
; 10 = awakeFromNib_____________________________________ 59
; 11 = +J______________________________________________
61
; 12 = ______________________________________________
63
; 13 = 5______________________________________________
69
; 14 = 3NTH:_________________________________________
73
; 15 = 6E4__________________________________________
75
L
-?X Mac =n;I~,:?X=
.w,Z0 Objective-C V Xcode ]=nN
{)%z'S?OZ0o (GUI) n.=6:{
<Hz3_OZ0on=C9N.{vn
J;],8?:njGI~V
y 8.*~sC
<HZ0.
<anXZ0<nq2
X+
PzRE^@@Xa @X
n6]X+n<A])%?nan5V$
aXp@n?Y"=.)%K>nc
y
.(Mn\`(Ma:Fn=unP9
\R\0"|i\<[4]n\(M^Ff
%n=nlPZ0@]q2\enF\<
[4.3] &q\ [4] n
F9rn=#P9=g9Fn{h
B\<
volume = baseArea * height;
// [4.3]
=~nJ}U,XVT.
ng?kD
^.xfoU<H
=\+.~O=ng%S?4Hna Xcode8A
dPzR
@ @nX\V$=
XQ]W~<HJn
0 Fat
0
Fat
aWNg\UEa4l Mac bHc Macintosh
i:2 *.0)qZ+!73)mR%
|
1. Mi: MacyiXO MacDN) Mac (
Mac ) Objective-C v AppleScript g5
:F9Fi: AppleScript 0)
aW#- AppleScript for Absolute Starters0)F)^r
http://www.macscripter.net/books
5,
3. u Macintosh 73M2Q
L
Mjfwi:[i:
P'5
]5Dp0jUlE
4. i:2 Macintosh 60Rje
6 0 : /?$ )
1 ?Ew!
1
?Ew!
=r^';a' 6uz^?
T;aZ:M~w?=3:YAk^
}1^
c+ Xcode e?`0F<
qwSTw?gw1SJ+b
{w(e Objective-C ?
'bT
2+6=
= 3 * 4 * :
+ey.
D iC w x y ww5
8m#jn
wVg
2+6=x
y=3*4
Objective-C c+$+e| ylw5> d=
> Objective-C %statement/LD?+el
lw
[1]
x = 4;
x l 4 sg :%Qw9AC_7X%
%HN...d [1] w?:#G
&P2xF7BSIw?compilereT
w>@Ew Mac ow 0 1pC\
w>{Ow7B&bd=%HQwC
c+w-w
=r:?R ?t_ y&t@w Mac #D
w?I=rYtw?&4,C=3S
:)ew[gw&hKU"w9
5(]pC\`YAwGfAw5#?W
qWq::?wJ;
1 =vDju
=j8xbugR!X(&x
debugging
6?8(j=PJ\* x U>j4]9*^n-
rj4#x pictureWidth [2]
[2]
pictureWidth = 8;
O h#+?`=|vog}j_
{gjv=jv3j.K>U>\*v>j
4 pictureWidth pictureWIDTHcm PictureWidth y3]P
5 :^Hx4_:0_T::)
938] [2] dV[qP7~I |=6x@!
j#b
4v"M:cmB:)
> jA+^a4G>Zq{;@P#Q&0
2!GvWo';j{qvj4v
Objective-C jp:.K8 Objective-C >j:+5:^
Hx4]9 pictureWidthv<0jx {pt4j#bs
84\*:)9f;Zq=j#
9ft{1ZqNw :)\*:
vj
Gv4\*:$
\*jv:"_"
vZ4j]
(j4door8kdo8orc do_or
j4door 8"M l,8doorv:
sj4Door8v:)
8Pk{9FP#*&C|Pzz*^|
j=Lv*^H/Yj= [3]
[3]
pictureWidth=8;
pictureHeight=6;
pictureSurfaceArea=pictureWidth*pictureHeight;
%jl,X8 Ee4:%{=
SP#\*l,
1 v1j8_i
[4]
pictureWidth = 8;
pictureHeight = 6;
pictureSurfaceArea = pictureWidth * pictureHeight;
,nnP [5]SjRvr
[5]
pictureWidth = 8;
pictureHeight = 4.5;
pictureSurfaceArea = pictureWidth * pictureHeight;
1 m3`9W_
AH`#l!rClLm=bm3foE(u
`{W=<`1;F/&pW}s
7"{XW8!`gW<`1S{Xm
Wk`gW{!xkWn@)Q5!)W:
[7]
unsigned int chocolateBarsInStock;
$>
W*!rbg.7 unsigned int !)/unsigned int [?Y+2RP
R
{!6\BmFDk_N# [8]
[8]
int x = 10;
float y= 3.5, z = 42;
!{cG W
/ZiWICl8mjTCl!H),W'3WM`
operatorsJ8v&Wf
+ )J8
- )J8T
/ )J8tT
* )J8jT
H)G
Cl!80Wf1S{ddwW Objective-C 3
foW3{xGqO!r`.blz%2Q4W
3foyx x = x + 1; h,b1I [9] P [10] iWT
[9]
x++;
[10]
++x;
KmI
YD x
/aG|U++ :R-ZP^`]heWd
~JWI [11] [12]
[11]
x = 10;
10
o 1 u Yx(vOr.GM
y = 2 * (x++);
[12]
x = 10;
y = 2 * (++x);
B^]*:#RR
VG<
[14]
int x = 5, y = 12, ratio;
ratio =
y / x;
[15]
float x = 5, y = 12, ratio;
ratio =
y / x;
x % y;
11
) 1 + "-,
*
21 % 7 . 0
30 % 2 . 0
50 % 9 . 5
22 % 7 . 1
31 % 2 . 1
60 % 29 . 2
23 % 7 . 2
32 % 2 . 0
24 % 7 . 3
33 % 2 . 1
27 % 7 . 6
34 % 2 . 0
$#0
2&' %31
12
2 V= uj
2
V= uj
`+=w4P"Pw<Te"m[Tr [1]
[1]
float pictureWidth, pictureHeight, pictureSurfaceArea;
pictureWidth = 8.0;
pictureHeight = 4.5;
pictureSurfaceArea = pictureWidth * pictureHeight;
2qP-oXbZwD*w<c}<
w[$&MwowH&=W:w/
;t=V=]<S&wciKw
<hl+cHw0{8ZPwz]
w<![3)c97R8w2
w;t^w<I $=a"OwS5B
wUx8w
d
//
8 Xcode Cw;t}[9DQ&ph /* */
/*
AdD */
Xcode H=KGPws;F<#?A
wuuoutcommentQ0w<ph /* */ "
w+0w<cfw0_H<"
+cbc;tcw0k"!
Dw<cQ5wk>fV=cw0M*H
wm"Yw}Ew%!cs&hlH\=
Kw6<8A".L*hw
80w<
J+c|]Nnyu,<
cw\bc;t*8g[`+h8(w
8w<+s@-=8<1
=Kw&iK[<r
(wb[V=~P'9w6&8w
s
13
3 a@
3
a@
b2xRbqt@(AG)b#P
Gq@LA~
YM9 Objective-C qh\R-sVq@|=Kq
=n@#PI
tq)+uTZ0C*~
7q@%;q@!<B=nA-;<
:0q|9ulQi_:9
C !o^@+Ul0
qX|S)+q"^]=%A)%1^
.}[)qn|%vq6}[@^
||;`a@functionq)AEq8>%\18
>^c'a@Z[@G\1a@gu/9CW@F
Aa@;`main() a@$T main() a@+r;
GeG@
R
main() a@[1]
[1]
main()
{
// main() a@q@kC
}
14
M 3 P -
pictureWidth = 8.0;
pictureHeight = 4.5;
// 2<E9?_3V
9
// [3.9]
{
}
circleRadius, circleSurfaceArea;
pictureWidth
// [4.4]
= 8.0;
pictureHeight = 4.5;
circleRadius
= 5.0; // [4.7]
pictureSurfaceArea =
pictureWidth * pictureHeight;
15
v 3 { J2
// ?j/6L?j[J2
circleSurfaceArea = circleArea(circleRadius); // [4.11]
}
Xyk~2I[z)DB5*CG [3]
?j float [4.4]D\Oinitialize circleRadius&<!
ki [4.7]|
X[c [4.11] 8y}c circleArea() J2wL[.0sS
C+ circleRadius wT/a!ck circleArea() J2[argument
circleRadius [irwJ2 circleArea()J2 circleArea() @!S8[
:>3_!#-returnW?jlA/G [3] [ circleArea() J2
Hby'E [5]
XQ* circleArea() J2
[5]
circleArea(float theRadius) // [5.1]
{
float theArea;
// Mu pi hm r "
theArea = 3.1416 * theRadius * theRadius; //[5.5]
return theArea;
}
16
g 3 l C+
int noOfEyes;
// B,I 1 D 6 twLq+
return noOfEyes;
// p x .Lq+
return;
// q+'/
17
z 3 O/
int main()
{
float pictureWidth, pictureHeight, pictureSurfaceArea,
circleRadius, circleSurfaceArea;
pictureWidth = 8;
pictureHeight = 4.5;
circleRadius = 5.0;
pictureSurfaceArea =
pictureWidth * pictureHeight;
circleSurfaceArea = circleArea(circleRadius);
return 0; // [10.10]
}
float circleArea(float theRadius)
// [10.13]
{
float theArea;
theArea = 3.1416 * theRadius * theRadius;
return theArea;
}
// O/`<
int main()
{
Z/\N~'H#*uL [10]
BmbAjM\}n/9ej(CJ
M\Ix{y?
Bm/oawC^d/#M\)%UEq-Bm\/p0n
rectangleArea() O/
lL [12]
\3}nO/-Bm\ main() O/
R;KBmW-nO/
\/|%1}e0:\,g.2M
18
3 b@
main() b@j>l-o@U$&Ii
@JoLj\:~&+Ii|b@:C/d
o}sHo*D)}b@o*O&UoLj
=,'z
[12]
float rectangleArea(float length, float width)
{
return (length * width);
}
19
y 4 +,/
y4
+,/
?h/?hW4 5E1Wk;a?hGC5vnd`A?hWeS
'K5||00WUAS'/ /~"m?hsH$i Cocoa
OIWL4NSLog() L4~aiR.bx/us
$*bdAuWS
"+," M 7NY):4
NSLog() L4da}eK'ol7
a$K4SW;a.b
jQH$O?h/"mW$UK'?hWS!u Cocoa B
t_usH$Bb W@
?hKcc NSLog() L4d`H$
[1]
int main()
{
NSLog(@"Julia is a pretty actress.");
return 0;
}
i39=N0i3character
T/wKWJ5 main() L4Wgdf{+
[2]
NSLog(@"");
NSLog(@" ");
f [2.1] =i3
{bX39empty string(<WZ]bf
[2.2] G[X39cpK^=iX%space.6~i39WZ]
a 1
20
} 4 -.0
04;Go>\4B-J6om\HIgvMCk#\_
l4-.L\9lom\%ALh# [3.1] lb \n]
94
[3]
NSLog(@"Julia is a pretty \nactress.");
{0XfrI3"6e\-
Julia is a pretty
actress.
h# [4.1] t9_\Xb
Julia is a pretty actress.\n
L)^dCk"6*PR\4;{0CkD_\X.L
[5]
int x, integerToDisplay;
x = 1;
integerToDisplay = 5 + x;
NSLog(@"The value of the integer is %d.", integerToDisplay);
Y0aCk6l4;ll/l4;A G6
\W:%dz74 % 6o>\$_il d decimal number \t9_0 %d U0\<u_\W:+
? integerToDisplay \jt9H [5] wL
The value of the integer is 6.
g*nx%( %f N %d
[6]
21
d 4 i !"%{
float x, floatToDisplay;
x = 12345.09876;
floatToDisplay = x/3.1416;
NSLog(@"The value of the float is %f.", floatToDisplay);
mMu`Dx'/TR}
M`
fsrQLXVG\rzXo~
tKkG'A`Q|HCg5V`s1b%9CVwZ)p<=C
K`% % ~ f
q>F % ~ d
q8N=gXKl+'A`N=
CKVCK[_saVCK
[8]
int x = 123456;
NSLog(@"%2d", x);
NSLog(@"%4d", x);
NSLog(@"%6d", x);
NSLog(@"%8d", x);
7 [8] )p'C
123456
123456
123456
123456
22
_ 4 b "#%u
tyG.5{C`qJHMKC'@\4_ Q2
_QTdA
{C 6'
[10b]
int x = 8;
float pi = 3.1416;
NSLog(@"The integer value is %f, whereas the float value is %f.", x, pi);
h
"C
The integer value is 0.000000, whereas the float value is 0.000000.
circleRadius, circleSurfaceArea;
pictureWidth
= 8.0;
pictureHeight = 4.5;
circleRadius
= 5.0;
= circleArea(circleRadius);
23
4
//
{
float theArea;
theArea = 3.1416 * theRadius * theRadius;
return theArea;
}
float rectangleArea(float width, float height) //
{
return width * height;
}
24
s 5 v i.)
s5v
i.)
8[DQUHCK)
TM/WlK'|->@
%1TnK Mac ->y<nK Mac Tt_\dcK
)UcompilerT$9nK)z* Mac Hfi.Ki.aH
KT Apple K2 Xcode )uYKnB Mac OS X HN
K!(% Xcode1T{&0Fn+wKJnm
http://developer.apple.com K}L# DX2*U^
r$pg Xcoden$ Developer `6 K Applications `6 :Dns
,pgKa]hnAh"?AuK=+P-&InX
K~Sa$ Preferences ;[XeKEm File x New Project\5jb3qxKyr
Xcode 4)nR
jb
BECOME AN XCODER
P
v 5 } k1-
zMlhQ'2
ZpQ"- c'+G*
W
Finish
justatryDLcp_"H,plhQ2
;bs(_V&Qlh#xTerminalk1*Op8rpQ-#x
k1D_4E~CMplhQ'/c^+0
/cGX#xNk1Q-'+vc+!
_\Q/9
[aQ-'T"+!
s(cBZ-z`eQpmnn]KQ5s(puS{c/Ici
YQiYX "Groups & Files""H,Lw.p-QN/h$S{@/)
h3XWpV&)AQ GUI -g({m<KpQ GUI t)AN
_Qh{EhywDR,(h73X*Op({Eh7U
NXcode F{EQh7"Groups"HwpQ>f
({c'Z Groups & Files QiYqw justatry KaQ Source wa/
c'Z justatry.m [1] Qhjo?c-|6c'Z main() QJ-{
X6/ main() J-QCch(}W;bmd=6;b-Q-
*OpQ% justatry.mpmsc:QApple ZpV&
main() J-
26
+ 5 - 451(.
[1]
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) // [1.3]
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // [1.5]
// insert code here...
NSLog(@"Hello, World!");
[pool release]; //[1.9]
return 0;
}
"",&.*2)
* "
NSLog() /3#
import $ 0'
main()
%.7
!0
27
5 GB
.i1[\[|Bv=b
NSlog (.i=
8AI
return 0; (
Ce|xH
jiC|U= main() lB| [1.3]
/ NSAutoreleasePool o|( [1.5]
')&S pool release jA|( [1.9]
[i[O~@O~[|B$[|(
:[|[CZ`[5
X "lB" r@EDm>r}l
B.iB|z^B main() lB!lB
F[+t=`CzV6=h [1] m|sCxH[|
u+_5qe( [1.31.5 1.9]Cek"w ObjectiveC a|xH+5|B?j
T|i||[7meT|xH
@y|`Cm4L3|p|Jw main lB|
GBs||BM.|Bf.V
k*|B.*OBs||O
9|f.V+*bjC "pool" A|
(=|d
[G Apple sg|B [1]1 Build and Go | 1i2
buildR compilecGB
Build and Go
28
w 5 z n4.
[2]
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
NSLog(@"Julia is a pretty actress")
[pool release];
//{{;
//[2.9]
return 0;
}
^V!xd.X
H%S Build
Xcode Yd
,Or
R%v4xdSN
error: parse error before "release".
PparseZb#^7SBs@>4.A[Z9>
4\J8'd&y"Sr~Di(1M import _
[2.1]r~Dd-#\_S: [2.8]r~D
Iw [2.9] 4gvBs2AlAZ+x42Z
+SUax4+xpIS`^ukZ^~D/S)|
6ZxC)|?phSl/WS}_L)|S5?pZ.h
S*jWtT
FexdlA$0n4.Ko7
v+<c=qzfFS.G Apple ~DS. [1] pIE [3]
[3]
#import <Foundation/Foundation.h>
float circleArea(float theRadius);
// [3.3]
29
- 5 / =A:*1
// [3.5]
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int pictureWidth;
float pictureHeight, pictureSurfaceArea,
circleRadius, circleSurfaceArea;
pictureWidth = 8;
pictureHeight = 4.5;
circleRadius = 5.0;
pictureSurfaceArea =
pictureWidth * pictureHeight;
circleSurfaceArea = circleArea(circleRadius);
NSLog(@"Area of picture: %f.
pictureSurfaceArea, circleSurfaceArea);
[pool release];
return 0;
}
float circleArea(float theRadius)
// [3.22]
{
float theArea;
theArea = 3.1416 * theRadius * theRadius;
return theArea;
}
float rectangleArea(float width, float height)
// [3.29]
{
return width * height;
}
!@)4;,7.(1 29' main() #' circleArea() [3.22] rectangleArea() [3.29] "?0'8 '
main() [3.5] %6
' main() B 1< Apple 3'
51*$'+&
>
Area of circle:
78.54.
30
L 5 R m{fF&X
bX }Inx
}IzEw"!CAJ`_<X F&C)QW
h*$ Xcode O*}IB0<J_<4d}j?3=6>#%yDMt
Xcode T`U@ "
ut"breakpoint@v#%3lse5
J3X
k N-@ ut
o1]JG`:-3=F&6;,}j3?"PHJ`g<(
ut/J^.
p3=37>&
Ko9|38Z'
3L@as8\/V7T`!@rSc+
Build and Go i
rSpopup menu
31
\ 5 _ xpS%e!
32
Z6`X
I
Z6`
X
*MLVHV@d(v%[#EKX
)^Ku@ [1.2]
I
MU,S/*E5N0@{z'aD9n
[1]
int age = 42;
if (age > 30)
{
NSLog(@"age is older than thirty.");
//[1.4]
}
NSLog(@"Finished."); //[1.6]
[2]
int age = 42;
if (age > 30)
{
NSLog(@"age is older than thirty.");
//[2.4]
}
else
{
NSLog(@"age is not older thirty.");
//[2.7]
}
NSLog(@"Finished."); //[1.6]
e<
>
<
33
<
Q
>=
QOQ
<=
QOQ
!=
Q
6 (h
// y ` 0
1Sg+tb/n(C`9V1S4/QnV(!*3'
G% AND `In & HY&&&1Sg8n(3'=
G% OR `In | HY&||
[4]
if ( (age >= 18) && (age < 65) )
{
NSLog(@"Probably has to work for a living.");
}
gUVB(h}H`9VgVBn(hPJn(h
V_=k)jV()1S3'jV
nh
\]
[5]
if (age >= 18)
{
34
6
35
y7~
H& while Ked!
M'[bBhumXQ64F!d!}
4Ker:L4X4 [1]
r:7Bh17NL
[1]
NSLog(@"Julia is a pretty actress.");
NSLog(@"Julia is a pretty actress.");
NSLog(@"Julia is a pretty actress.");
>@Z28"ceXN6ljtcr:P1!d!79Q6
X4GObjective-C IiVKM"
2UtY|id!P|zd!cer:X7tJ [2] 0
for d!A|i3K^OeX7|i3#a/btVsip?
eJK 2.7 7
[2]
int x;
for (x = 1; x <= 10; x++)
{
NSLog(@"Julia is a pretty actress.");
}
NSLog(@"The value of x is %d", x);
6tcX4
[3]
float celsius, tempInFahrenheit;
for (tempInFahrenheit = 0; tempInFahrenheit <= 200; tempInFahrenheit =
tempInFahrenheit + 20)
36
C 7 G ( while *8T7
{
celsius = (tempInFahrenheit - 32.0) * 5.0 / 9.0;
NSLog(@"%10.2f -> %10.2f", tempInFahrenheit, celsius);
}
F;I.V
0.00 ->
-17.78
20.00 ->
-6.67
40.00 ->
4.44
60.00 ->
15.56
80.00 ->
26.67
100.00 ->
37.78
120.00 ->
48.89
140.00 ->
60.00
160.00 ->
71.11
180.00 ->
82.22
200.00 ->
93.33
Objective-C
+P*8TD7
while () { }
do {} while ()
37
BECOME AN XCODER ?
1 7 3 while (;'
int counter = 1;
do
{
NSLog(@"Julia is a pretty actress.\n");
counter = counter + 1;
}
while (counter <= 10);
NSLog(@"The value of counter is %d", counter);
38
8 q4?n (GUI) [2
8
q4?G%^nGUI[2
Objective-C \[@p=/Izeb'q4?G%^in
GUI[2<g@".5NT*EObjective-C Eg,h C [2C
[6K&`h@pz[g[ CS Objective-C C KP4;r
r. "Objective" q+Objective-C uKqhZ*object[UQ
K&`h@pl.1`nK[Objective-C $1[
Q)> .yb'1D%
J p[2l
1tH0m2_/%<g0X[2gqHIoV
2l3Va^MR^~0[2gq](A
lxv eM~0 Objective-C FW:w.
1gcgZ*[|G% Objective-C7O
l[Z*[d2I p
IjqH
@pjjq Safari Objective-C [2g0;
L[jj Mac S[q Safari !B4
qfk8[gf
Sfqk8fIqt$EMq{smessage
}ql-q{s9F2I 7
39
BECOME AN XCODER
F
W close ^Yh{_ujWvr
WG$=*jWvr6?HG$=*j<Oy
40
8 @Q (GUI) p=
Ry+p=p
:lR=pa||
%a NhFpmp3
%Lf8pZ^
close o
,%}Kp5BR8p}o,D%`|
?[M;Go,!*
5BR.y+REpK{y+%po,}\|
p?rC
po,Rp}o,I}
41
8 n7Ck (GUI) [5
Z*-[e~;n5[roDm0 hNDm[40U
[y
Mac
Dm[6N&MncS{L[zpa[X~;nX
[5e=U@
:]!G ~;nX{nzp3=
Z*|3=Z*[.3zp\'5message sending expression
0Dm5 [Z*Q9zp)[x
42
#f?LE9][7PF@^4MoZ&][<TFJ,c>Fb<@^;
.K84M<][TFJ,e%v)3*MIcDLE9][74M]
[<;
Uh
43
8 {8Fx (GUI) g6
kgGz2uTm,{B?q2XkGzK ttB
qo@g
rs
g6v@4`!Q)Bm,3g_=:);X
[8g_=Tm,;g6NST4`um,{8Y
g"u ^PYg6C!:ur[8Ug<r
behavior4ZT6m,2Bg6v}D7g
_=Ag\inherit$[8g<r:q Objective-C C 8[/
g1
44
8 CO (GUI) qA
?IaqCKNSWindow<ZF' j
G*qK<$ ]HaqKFqBa
"close" -\e[TC*2IAFTC~WZ]A
aqK?lqKTC%NgmqA
GKijqK*q "K"superclassF?
qJ}H
&raRamhsajU
hierarchy of inheritanceq
?lmTCRa#qmSYq
L^YETm<n
Objective-C #signalerror
?ljGKqmJimplementGqH{x
' overridegqm_`' A|
|
<v4Q*a')qK.`qm
d Apple gqZ^.8q9:DqBa
HqmqFt Apple qZi <4#)zq
q/ Apple >PGq close mP
' invoke/PqKiJq close m*8qc
(A uPGq close mrecursiveqc(
[2]
// .`Qa')qAk<D
[super close]; // ^.Kq close m
3+
"FVFPyH
*
iCKq9 "NSObject" qK5w0h^.qKrh
q NSObject qKsubclass_`NSWindow K NSResponder K
qKF*+X NSObject qKNSObject KgiCqp1i6.q
m_?-p1q@p1M' q
<P.=!avP`?Iw0K
a MainMenu.nib [b Classes <a NSObject K
b*za7q Classes b Subclass NSObject;a MainMenu.nib [q
K>9@PPqf9 "MAFoo"
45
U&_ MAFoo Q
46
} 8 i2=e (GUI) Y1
47
OW?
/+ MAFoo a!
4*>1M2CI3#=:J#=2*>6LNQ27FA>6L
8::'#=2 MAFoo TebdX 5#=E$-9 "Set to 5"#=
P[R:%c6L2\V `_F5]O2Y2#=$
A>6L-9 "Reset"Z.NJ#=26L>>!2B>&fU#=2G
48
%O+zn*(23FJ?YF!G0M-T0M?4@HKsXv4@(
2Fuc'gm?
V"0Mlj\#JrxB?Za
a) "Dd "Reset" w MAFoo rf
b) "Dd "Set to 5" w MAFoo rf
c) " MAFoo rw$)f
JBZa" MainFile.nib b`
Instances L^CDSy ? Control 3
ipR Reset Dd96 MaFoo r JRI? 9o5}t QhV
UAYNZa?{z8YU{FDdE6 MAFoo r^C:eip
49
BECOME AN XCODER
7
inspector
;_i
50
$ MAFoo D/7B
51
// [3.3]
52
- (IBAction)setTo5:(id)sender
{
}
@end
X!MAFoo.h }i|%,M}E=H/jC}i
A[Ireset: setTo5:ZQ7Z4LIID*S2emU8eL
u*GE
Pz&7ZLu*[OyiO]}{_[^\weL
MAFoo K@U:b.C[I7Z
URj=`3 1u*"lU
3L<q+& Interface Builder 3Oy MAFoo KzLkvt-7ZLU
u* MAFoo K{_^\E)0%,7Zr?V [5.75.12]
[5]
#import "MAFoo.h"
@implementation MAFoo
- (IBAction)reset:(id)sender
{
[textField setIntValue:0]; // [5.7]
}
- (IBAction)setTo5:(id)sender
{
[textField setIntValue:5]; // [5.12]
}
@end
53
BECOME AN XCODER 6
#,'
5
)%%.$(&,)
0!4
,3
21--
54
q 9 v z;7N
q9v
z;7N
)Sv9`ENsaK29`0DaNQ6W9`
a Apple I|AQNsetIntValue: W)+3P"!_QN6Wn[
*5;EsaQNG
h4JnQ=a Apple xtQNnu[%0#5,
.f<>-gbug-free(.)r\n0QNS$R
cXXZWW-/'QNWT_mQ
) Interface Builder *Ln:}ke)]MQP"-a
CBC*Ln:}ke)V!nZE "NSButton"*Lnke)!Y
''System Font Text" Q+3nZE "NSTextField"s@=auWa7&
p)9`CZZ NSTextField 7-QN
Xcode)yF Help->Documentation)Q^dF Cocoa U)
z3 "NSTextField"H API-Search ,WFjCQl
]Q
)n QcboyQbL{~T8Qn{ZE NSTextField p)w]
NSTextField I)Q?17Y ClassC NSTextField 7Qi!)
Q^
d
55
W 9 \ `-u*;
IPph:e2>CYLu*Cv7(1.>u*!@^BH>C^]r
NSObject Hrn5 QCmt
Method Types
YaC,KGc3`-> +Z>sz fbU,K!Yg-2,K6kG>
;0!#x)=
{lJEv7>MA,KkGDF NSTextField u*>
?wu*NSControl'"9,KS,KdvyqD>u* NSView
&uRE6%>[C HTML N$6,KkGr {! Inherits from T_
># NSControla{ NSControl u*>iO
NSControl
Inherits from
PF2,K
VLu*!;T_
,K:e2Lmt
56
9 C>W
~Kh)SBwKnq
[t setIntValue:
setIntValue:
- (void)setIntValue:(int)anInt
Sets the value of the receivers cell (or selected cell) to
the integer anInt. If the cell is being edited, it aborts all
editing before setting the value; if the cell doesnt inherit
from NSActionCell, it marks the cells interior as needing to
be redisplayed (NSActionCell performs its own updating of
cells).
-Bw[2Bw[ NSTextField Z#l3]7BwrxBw
!xW[|2signatureqK
- Objective-C s"xWf@[Pp[l>WBw
iMvoid ^"+$;U9W[~]jlBwx setIntValue: }z textFieldBw[ MAFood Z#!0:Z#H3M$;[v+
KFa-biu(int) ^" anInt lx-Bw[J
Bw[lv 5 R 07wlF*6BwM$;
4{yrCM[WK
[S`k
l4A[<lD%#iX.
&5-L2WS4[gT([I
K_*or-2mx%Q[x=M:
T>L2e4p'([x7L2(l[
Objective-C 8DE[gW(r-'x>l[?7
57
q 9 w y96J
"N6P-X"NJ%uHR,>U_T}Ng&V
,t\b^#06/C.NJ%pY
-B3H"6
N"JQ-X"N%u'DZs
V "(
R" polymorphismuUM$,t\object-oriented programming*.e
6Na&n'[;!OnFNMUH46NoK zg
ljN,['k2|run-timedu_fNMgl
niNhc7u_)rnz't\
?-E-EN
,=>'8^xvN GUI ,
*I8^@gl setIntValue: h
cN6M>A+38^N,~'`:,W1]
NoK m58^W1'k2|G{M/
4;ouF<
NzUM$,t\NS
58
10 awakeFromNib
10
awakeFromNib
Apple byu-:y,]&7
X2mrxlQC,yX2y
!b, _-IBz6j:X
$
HjoaframeworkG3>i,XF [12] X Foundation Kit oa
E
=D#YcgXSvjoab Application Kit\~y
, eJXW'D#Yw<Hjoa4@.XR'
>i+J>iX GUI 2t>i,f>iX2,|wZ5Xmk
&;,08W' %jpLXh
N4jdXs1,j nib nnib [X` Next Interface Builder[%>ifXUr`P Application Kit XI(>ieef/9
?PjoaXsJ Xcode X Help Documentation
,R'L Full-Text Search)q`|#Xf|#
8XO
A,XK Full-Text Search{,8 Application Kit ^_ Return Xcode EyjTI4('*b Application Kit Reference for Objective-Cy,I?J(joaNEXSv},
Protocols M4ju NSNibAwakening X
NSNibAwaking
Declared in
AppKit/NSNibLoading.h
Programming Topic
Loading Resources
Contents:
Protocol Description
Method Types
Instance Methods
Protocol Description
This informal protocol consists of a single method, awakeFromNib. Classes can implement this method to perform final initialization of state after objects have been loaded from an
Interface Builder archive.
59
] 10 c awakeFromNib
'1M
pjgl[DROawakeFromNib Ao^)W=h@pZI;`NnlDjg
R$*ou
60
BECOME AN XCODER
Z
11 h
11
h
9v:[QFP[ C DQ|L_^
*X(<#Y
!
}2D - hpointer*
56f/8 - VN! Objective-C J3-qF
i[
Ovg[ Mac >v~[jG]J
,v[t
IJk [r
[1]
int x = 4;
G 11 J 4\
[3]
y = &x;
N=4\EI=4\2Y6Q(*D,41_Z'TI=U
*y
L3ESI[+
[5]
int x = 4;
increment(&x);
// F x M- 5
62
12 3<
12
3<
P(_gDmhP s`@integerlong]floatu
doublekbuBOOL#X+Dm[ pointere
Dm_~P3<stringnt 70P NSLog() O5[toP
KnO5Dm,-n3<P
&nlN % [v
@M2 %d
[1]
float piValue = 3.1416;
NSLog(@"Here are three examples of strings printed to the screen.\n");
NSLog(@"Pi approximates %10.4f.\n", piValue);
NSLog(@"The number of eyes of a dice is %d.\n", 6);
Dm_JG7E3<?gns`@N}y/g7nd1['"mfZ*f'
NSString @T NSMutableString @Uc)[0DmN}yK@' NSString
R
[2]
NSString *favoriteComputer;
favoriteComputer = @"Mac!";
NSLog(favoriteComputer);
|w
nj!fdrV[>f! [2.1] iK x{
DmaAnetDm$Wnee.[fps`@Sf 11
[2] [j!
[3]
int *y;
63
y 12 4;
L
[5]
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *x;
x = @"iBook";
// [5.7]
s:^}h6-
MacBook Pro Intel
h NSString @Y4;|bEYimmutable0b"n|iE
tniE4;72{P?FzOniEY4;kT{wR
tY6YCKtM' Objective-C OtY6ltx~
YuVtJeiEtY4;
64
s 12 x /8
{3gbpX]cAS/8*43;5pNU"S/
8R$TXcASva]JS;X NSMutableString ;>`,x|Vm
iJ_%>`LpSJ/8XaR$W{`XR$>`y
kjf~`GH>`k length jf~a/8R$ [6]
[6]
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int theLength;
NSString * foo;
foo = @"Julia!";
theLength
= [foo length];
// [6.10]
l7Vva}0&
The length is 6.
65
C 12 E
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *foo, *bar;
foo = @"Julia!";
bar
= [foo uppercaseString];
> 5D8GL
Julia! is converted into JULIA!
<9?=LJ7:%8B /
;348K/DM@,?H&
NSMutableString P"/.)1?/ NSMutableString F'OM
+)R?:%
/
;(appendString: D8
+L$!6OI/ 2*A0/#N
[8]
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableString *foo;
// [8.7]
// [8.8]
foo);
[pool release];
return 0;
}
> 5D8GL
66
k 12 s (.
Z(.I
SqQ?hB
Z(.I
Z#T "bar" J
4*Z(.
I J/5
&ZcA!ZI
67
BECOME AN XCODER F %
5 12 7
foo);
bar);
NSLog(@"------------------------------");
[foo appendString:@" I am happy"];
NSLog(@"foo points to the string: %@.",
foo);
bar);
[pool release];
return 0;
}
2
)6-9;
foo points to the string: Julia!
bar points to the string: Julia!
-----------------------------foo points to the string: Julia! I am happy
bar points to the string: Julia! I am happy
03.'1<#-&A&D9B!C+-$/'0
@,
('7=8>?6-0E !C5 8 7,84"-
'*:&1<#,' MAFoo &
68
13 +
13
+
8|v[P+gWXv?g4?3L
{4?,<U${88{mgN+
array+r{8Ggf*?+ajKg r{f*qg?+
If*Z+%+f*ajvM{+h50s{
@index)Dq^g@gr{f*9vM+h F8
1{element
c>g|% 1 ]A0+{&gr
{gr
1T9
{4?
{4?
{4?
W{F8{4?g+
Hz0"pS6W %]wg
+r%Y{CbVNSArray NSMutableArray4?8}J
}Jge"0"Hz:}Jg{e"
{o(+gdr=
yg6
[NSMutableArray array]
=p=6o(Q/{ig+Ar
{62``g
rg0{WHzU$ { NSMutableArray Cg-XBtg
7jArHzv;lCOE
Hz~~Z {c>R0 Objective-C HzC
;.rCrf* zrHzt meta-classes gHz0
Kg{_0 Cocoa *Hz0C\gdr
"+" Xk';lHz!0d-nyuZg "-" W3 8 [4.5]WX
0*HzuZ{ array dgx
array
+ (id)array
69
5 13 7 1
Creates and returns an empty array. This method is used by mutable subclasses of NSArray.
2 (6.9;
There are 3 elements in my array
70
1 13 4 *
// [2.13]
-!3%56
The element at index 0 in the array is: first string
/8.6<#2%*;* %'+0#+3%&/
:
$3%"7( *' 5=),9
[3]
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *myArray = [NSMutableArray array];
[myArray addObject:@"first string"];
[myArray addObject:@"second string"];
[myArray addObject:@"third string"];
int i;
int count;
71
13 -
=mz7.
The element at index 0 in the array is: first string
The element at index 1 in the array is: second string
The element at index 2 in the array is: third string
`-M!wY]n95>#yn9,@uec+
NSArray NSMutableArray CP3Tea;HyqN
Ce_+QJ3]-efHyz'zc+Q
replace z?]pz?c+eaM:r%
"za
X0r replaceObjectAtIndex:withObject:U)lrHy!39z
eaAoz/;or@Hyu2s#e{1#VRz
(#0[FeRzk;Q2 Objective-C a9,
e
ou4@O'zaea
[4]
[myArray replaceObjectAtIndex:1 withObject:@"Hello"];
72
14
14
23I0pL;SbnQv!>NQv!m'Tb
b8Om Mac b8> RAM myqb0=5^b8.
tn,bJ"Mb%
Ht;Od
Xor{4$m2lu8GRb8m2@b8[
freeb8
>b9
b8i)ya*{ya*2C'Qe>#2.R'
ya*j[e"bkmba*.R'j|
destroy">tEya*{j.R'~Og]PS
T28b@ba*~3Uba*Z0= t;Ua
*~R'V""~|R'y|ba*~sb
8Y&_b@p
pWF2a*.tb{z|"xCocoa Jyu
Kya*
"fa*Zb "h}"retain count2b86yna*b
{#Jya*bh}T"c*Prbyn
a*b{#Jya*bh}Tc"ya*bh}\
{ya*c".+B1ZO7-b|ya*
|"?O[rb
STb8myA>;D'Tf(:[/fba*
2;ny:a*y[/fa*V5^"L;.Ub1V
b:a*;y\bh}
[/f
1
w:
h} =
3
[/f
2
[/f
3
ya*c"<>t\"bh}
73
y 14 ox
74
15 =
15
=
)l.{5 Xcode Objective-C l7i)]<
X?RY[W67C*xl
,)Vlm\NlFh`
6H,_ l>flYs{jl
5bl9r;lv
bc0~
}4 Apple $M:EenZ%lR3
SlG2l| $M:lSXPbZ"\f0~
/X\?ll{ Apple lnAg
http://www.apple.com/developer
OlvP1#
http://osx.hyperjeff.net/reference/CocoaArticles.php
http://www.cocoadev.com
http://www.cocoabuilder.com
http://www.stepwise.com
lL;`_
\l5
http://lists.apple.com/mailman/listinfo/cocoa-dev cocoa-dev l/1p
mailing list5$lll\aI
lqzX0{J$5u8http://www.cocoabuilder.comQ`
l Y g 5 / 1 p l v U A g
http://www.catb.org/~esr/faqs/smart-questions.html l "How To Ask Questions The
Smart Way"k "l" Ag h t t p : / / m i s . n d h u . e d u . t w / d o c u /
question.htm
'
;Yg Cocoa l6Stephen Kochan l Programming in Objective-C {
onl;Y^-)f`lmOw-B5
Big Nerd Ranch l Aaron Hillegass fl Cocoa Programming for Mac OS X 5W
Xcode +Ow- James Duncan Davidson Apple 3 O'Reilly @l Cocoa
with Objective-C
yKl{{5 Mac 95"l9rq&D{T
;l>&\wXdg Apple &Ag
http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuid
elines/index.html>(M:&gPl9"\_
lv
aIX!l9Xz5t
75
15
$
!('
Xcode #"&% 0
76