BAT公司面试宝典无水印版


ᒫ ᶭ1 186 ش———ᤑ ҁ24҂ ᭗ᎣӨവᭆ 184 ҁ23҂ ௔ᚆս۸ 178 ҁ22҂Runtime 159 158 ګ๢قҁ21҂ਞ ҁ20҂ᦡᦇཛྷୗ 148 ҁ19҂ग़ড়֛ 147 ҁ18҂ग़ᕚᑕ 137 ҁ17҂WebViewӨJSԻ԰ 128 ҁ16҂ᗑᕶ 117 ҁ15҂Runloop 110 ҁ14҂හഝਂؙ 101 ҁ13҂ᕲࢶӨۖኮ 95 ҁ12҂ᒫӣො໛ຝٌ݊ᓕቘ 90 ᦶ 85᧣ޞҁ11҂ಸᲙᦄ ҁ10҂UI 62 ҁ9҂Swift 59 ҁ8҂Block 47 ҁ7҂KVO-KVC 45 ҁ6҂ٖਂᓕቘ 35 ҁ5҂Objective-C 15 ҁ4҂C᧍᥺ 9 ҁ3҂UNIXଉአ޸ե 8 4 ګҁ2҂ᇇ๜ഴ ҁ1҂ଧ᥺ 2 ҁ1҂ଧ᥺ iOSiOS每 下 每 github每 以每 ᒫ ᶭ2 ᒫ ᶭ3 ᒫ ᶭ4 $ open main.c ಑୏ଚᖫٟ෈կٖ਻ $ touch main.c ୌ෈կڠ $ svn log filename@1 ັ፡຤Ӟӻ෈կ຤ӻᇇ๜ጱ෭ப $ svn log filename ັ፡຤Ӟӻ෈կጱ෭ப $ svn log ັ፡svn෭ப ޸ե Კ᧏൉ᐏғ"is not a working copy"҅஠ᶳࣁsvnጱૡ֢ፓ୯ӥ಍ᚆྋᏟֵአsvnጱ $ svn st ັ፡๜ࣈդᎱପᇫா ൉ᐏғcheckout(co)ԏݸ҅޸եᤈտᦕ୯አಁݷ޾ੂᎱ҅ݸᖅ඙֢ӧአٚݚᤈ೰ਧ $ svn co http://xxx/svn/xxxx --username=manager --password=manager ࢏ӤጱդᎱՙପۓcheckout๐ $ cd ૡ֢ፓ୯ ഘૡ֢ፓ୯ڔ •SVN •SVN() ᛗ੝؉Ӟེ"ڹ࢏҅"ྯॠӥቔԏۓ๐ک3> commit       ਖ਼ૡ֢൉Ի Ԫఘ" ๜ࣈ҅"ྯॠӤቔ஠ᶳᥝ؉ጱکදӥ᫹ץ࢏Ӥਖ਼ٌ՜Ոಅ؉ጱۓ2> update       ՗๐ ๜ࣈ҅"ݝᵱᥝ؉Ӟེ"ک࢏Ӥ๋ෛጱդᎱՙପӥ᫹ۓ1> checkout     ਖ਼๐ ඙֢ғ දץጱՈ੒դᎱ؉ጱ ӧݶڊړ܄4> አಁݷ&ੂᎱ   ᦢᳯդᎱՙପᵱᥝֵአᛔ૩ጱ"አಁݷ޾ੂᎱ"҅՗ᘒݢզ አಁጱդᎱՙପڹ୮ਂכ3> Client       ਮಁᒒ҅ݝ ಅํᇇ๜ጱդᎱՙପਂכ࢏҅ۓ2> Server       ๐ դᎱጱՙପਂכ1> Repository   դᎱՙପ҅ ༷ஷғ •SVN SVN 每 SVNGit ګҁ2҂ᇇ๜ഴ ᒫ ᶭ5 '~' ݑഴ෈կᤩٌ՜෈կᴥᵍ ᴻጱ෈կ҂ڢ'!' ෈կӶ०౲ᘏӧਠෆҁӧฎ᭗ᬦsvn޸ե ๜ࣈᇇ๜ପٖکے'?' ෈կဌํᤩႲ ୌጱᇇ๜ፓ୯ڠ'X' क़᮱ਧԎ 'R' ᤩ๊ഘ දץᤩ ''M 'I' ᤩ஺ኼ ᴻڢᤩ ''D ٫ᑱ ''C ๜ࣈդᎱՙପکے'A' ᤩႲ දץ' ' ဌํ svn st ดᐏጱ෈կᇫா (tc) theirs-conflict    ֵአ੒ොጱ (mc) mine-conflict      ֵአ౯ጱ p) postpone            ੒ྲ) ٫ᑱᥴ٬ $ svn update -r 5 ጱ຤ӻᇇ๜ڹԏک௩॔ $ svn revert Person.m දץඋᲀ ᴻ෈կڢဳ఺ғӧᥝֵአ෈կᓕቘ࢏ፗള ᴻԧ෈կ"ڢ" $ svn ci -m ᴻڢ ൉Ի $ svn rm Person.h ᴻ෈կڢ ဳ఺ғӞਧᥝِ౮ٟဳ᯽ጱᜉঅԟబ "௳מ$ svn ci -m "॓ဳ ࢏ጱᇇ๜ପӾۓ๐کਖ਼෈կ൉Ի $ svn add main.c/main.* ๜ࣈᇇ๜ପӾکےਖ਼෈կႲ $ svn st ፡ૡ֢ፓ୯ᇫாັ ᒫ ᶭ6 $ touch Person.h Person.m ग़ӻ෈կےႲ $ git add . դᎱପکےදጱ෈կӞེ௔Ⴒץ෈կ४ӥጱಅํෛୌ౲ڹਖ਼୮ vim ᖫᬋ࢏҅ইຎ੒vimӧᆧఀ҅տฎஉᔩᔤጱԪఘ فտᬰڞވ ௳מදጱ॓ဳץࣁྌӞਧᥝֵአ -m ݇හ೰ਧ ԧmain.c"ے$ git commit -m "Ⴒ դᎱପکද൉Իץਖ਼ $ git add main.c դᎱପکےਖ਼෈կႲ $ git status դᎱପᇫாڹັ፡୮ դᎱପکےਖ਼դᎱႲ $ open main.c touch main.c $ ݎୌդᎱ҅୏ত୏ڠ $ git config -l ಅํᯈᗝڹັ፡୮ ࣁአಁፓ୯ӥጱ .gitconfig ෈կӾਂכ௳מզӤӷӻ޸ետਖ਼አಁ $ git config --global user.email manager@gmail.com $ git config --global user.name manager ইຎᥝӞེ௔ᯈᗝਠ౮ݢզֵአӞӥ޸ե դᎱՙପӾڹࣁ୮ਂכ௳מզӤӷӻ޸ետਖ਼አಁ $ git config user.email manager@gmail.com $ git config user.name manager ᯈᗝአಁݷ޾ᮒᓟ $ git init ୌդᎱՙପڠ "෈ਁىፘ"ف෈ਁ҅ೲ"/"ᆐݸᬌىᥝ൤ᔱፘ ᘉ፡Ӥᶭ҅ೲ"CTRL+B" ᘉ፡ӥᶭ҅ೲ"ᑮ໒" ೲ"q"҅௳מଆۗڊᥝᭅ $ git help ৼ޸ե ັ፡gitಅํ޸եጱଆۗ $ git help • git Git ᒫ ᶭ7 每 • Git 每每 每 • ⼒SVN被 • svngit每 • SourceTree⼒GIT被CornerStone⼒SVN被经 ૡٍฎՋԍ҅ᚆय़༷ᦖᦖܻቘԍҘګ๋ଉአጱᇇ๜ഴ • • • ԅՋԍᥝአრդᎱᓕቘૡٍ $ git reflog ඪ୚አᦕ୯ړັ፡ $ git reset --hard e695b67 ೰ਧᇇ๜ݩጱᇇ๜کࢧ $ git reset --hard HEAD~3 ᦈᇇ๜ץᒫ3ӻڹԏکࢧ $ git reset --hard HEAD^ ӤӞӻᇇ๜کࢧ $ git reset --hard HEAD දץᇇ๜҅න୒ಅํဌํ൉Իጱڹ୮کࢧ $ git log ෈կݷ ັ፡೰ਧ෈կጱᇇ๜ପ෭ப $ git log ັ፡ಅํᇇ๜ପ෭ப ٚ൉Ի҅ᬯӞᅩฎӨsvnӧӞ໏ጱےද᮷ᵱᥝႲץဳ఺ ֵአgit෸҅ྯӞེ Personᔄં௔"ے$ git commit -m "ी $ git add . $ open Person.h ԧPersonᔄ"ے$ git commit -m "Ⴒ git add . $ ҁ3҂UNIXଉአ޸ե 每每 1. cd 
 2. pwd 
 UNIX 
 3. ls 
 $ ls 
 $ ls -a 
 $ ls -l 
 $ ls -la 
 4. touch UNIX 
 $ touch test.txt touchtest.txt信test.txt 1. cat 
 2. more 
 1> 
 2> TAB ᒫ ᶭ8 ᒫ ᶭ9 ಘ઀ғইຎӤᶎጱ*p++ද౮*(++p)ই֜Ҙ ੪ฎ2҅ᘒӧฎ3.؀ᘒݸᶎጱ(*p++)Ԟ੪ӧտಗᤈ҅ࢩྌpಅ೰ݻጱࣈ࣎੒ଫጱ ੪ฎ1̶؀ݒ౮ԧ2҅֕ฎ1 > 1ԅ㮔҅ಅզ๋ᕣmaxጱ؀ᒫӞӻ*p++ጱᕮຎฎ҅pಅ೰ݻጱ => (1) > (1) ? (*p++) : (1) => (*p++) > (1) ? (*p++) : (1) *p++ፘ୮ԭ*p, p++,ಅզMax(*p++, 1)ፘ୮ԭғ ӤࢺೡݩےਡਧԎ෸Ӟਧᥝဳ఺ྯӻࣈොᥝ ԅ1.؀ᔰ੒ଫጱࣈٌ࣎҅زp೰ᰒ೰ݻԧහᕟarrayጱḒࣈ࣎҅Ԟ੪ฎᒫӞӻ ຉғړ ֢አጱ҅ࢩྌᥝైአ̶ ۅ֢አ̶੒ԭ++̵–҅ࣁਡ୮Ӿֵአฎ๋਻ฃԾኞۅਡਧԎಅଃ๶ጱکਡ෸҅੪տమک୮፡ #define Max(X, Y) ((X) > (Y) ? (X) : (Y)) ݇ᘍᒼໜғ 1҅2 printf("%d %d", max, *p); int max = Max(*p++, 1); int *p = &array[0]; int array[5] = {1, 2, 3, 4, 5}; ڊզӥդᎱጱᬌڊਡMax҅ଚᕳٵٟӞӻຽ define MIN(A,B) ҁҁA҂ <= (B) ? (A) : (B)) ӷӻ݇හଚᬬࢧ᫾ੜጱӞӻ̶فਡMIN ҅ᬯӻਡᬌ"ٵٟӞӻ"ຽ define SECONDS_PER_YEAR (60 60 24 * 365)UL(UL෫ᒧݩᳩෆ୵) ᳱଙᳯ᷌҂ አᶼ॒ቘ೰ե#define्กӞӻଉහ҅አզᤒก1ଙӾํग़੝ᑁҁ஺ኼ አ҅೰ᰒpտ֢ӣེ++ᛔी඙̶֢ ֢ۅ• ᕮຎฎғ((p++) <= (b) ? (p++) : (*p++)) ᬯӻᤒᬡୗտԾኞ • least = MIN(*p++, b); ኞՋԍԪҘݎ୮֦ٟӥᶎጱդᎱ෸տ 每 每C C⼦iOSCCiOS ҁ4҂C᧍᥺ ᒫ ᶭ10 ੒᨝ԏᳵጱ೩ᨬٌ҅Ӿ୮ᆐԞ۱ೡਁᒧԀ೩ᨬզ݊च๜හഝᔄࣳጱ೩ᨬ̶ හ᭗ଉᴴԭݶᐿᔄࣳහഝ౲ڍහᒵᳩ೩ᨬጱᇙᅩզ݊හഝᔄࣳդᤒጱᇔቘ఺Ԏ҅memcpyڍ ݢ̶ᰄԭmemcpyܨଚӬ੒᨝ٍํݢ඙֢௔̵௳מ੒᨝ጱ᩸তࣈ࣎޾ٖਂᳩଶڊࣳ҅ݝᥝᚆᕳ ᚆ̶ٖਂࣘኧٌḒࣈ࣎զ݊ᳩଶᏟਧ̶ࢩྌ҅memcpy ጱ඙֢੒᨝ᭇአԭձ఺හഝᔄۑӞ ݚӞӻٖਂࣘᬯکګහᶶݷ௏Ԏ੪ฎٖਂ೩ᨬ҅ਫሿਖ਼Ӟӻٖਂࣘጱٖ਻॔ڍ- memcpyғ ᚆ̶ۑຎრ੒᨝ฎਁᒧԀ҅ଚӬ೰ਧ%s໒ୗᒧ҅ԞݢਫሿਁᒧԀ೩ᨬ ᚆ̶ইۑහԆᥝአ๶ਫሿҁਁᒧԀ౲च๜හഝᔄࣳ҂ݻਁᒧԀጱ᫨ഘڍ- sprintfғᬯӻ ᚆ̶ۑፓጱਁᒧԀጱ೩ᨬکහ඙֢ጱ੒᨝ฎਁᒧԀ҅ਠ౮՗რਁᒧԀڍ- strcpyғ ᚆզ݊඙֢੒᨝ӧݶ̶ۑࣁԭਫሿڦ܄හጱڍᬯԶ ࡅཻߺӞӻҘԅՋԍҘ֦?ڦ܄හํՋԍڍᳯᬯԶ හ҅᧗ڍਠ౮ਁᒧԀ೩ᨬݢզֵአsprintf̵strcpy̵զ݊memcpy Ձጱݒᰁوۓӻձپ• ग़ᕚᑕଫአӾᤩ variables) ጱᶋᛔۖݒᰁ(Non-automaticکৼᑕଧӾտᦢᳯۓ• ӞӻӾෙ๐ • ଚᤈᦡ॓ጱᏝկੀਂ࢏ҁইғᇫாੀਂ࢏҂ ӻֺৼғپࣁੀਂ࢏᯾ጱ॓ղ̶ӥᶎฎvolatileݒᰁጱਂכአ ᘒӧฎֵ҅؀ᬯӻݒᰁ෸஠ᶳྯེ᮷ੜஞࣈ᯿ෛ᧛ݐᬯӻݒᰁጱک• ս۸࢏ࣁአ ӣӻӧݶጱֺৼڊ఺?ଚᕳތᲫਁvolatileํՋԍى ฎ3.5؀ฎ2.5҅ݢਫᴬӤaጱ؀int a = N / 2;  // ౯ժᶼమጱaጱ ฎ5҅౯ժᬯ໏ֵአN؀#define N 2 + 3 // ౯ժᶼమጱN #defineਧԎᤒᬡୗ෸ᥝဳ఺“ᬟᖭපଫ”ֺ҅ইইӥਧԎғ ᖫᦲ෸տᬰᤈᔄࣳ༄ັ̶ ᯈٖਂ҅ᘒӬࣁړλ    constਧԎጱଉᰁ҅ࣁᑕଧᬩᤈ෸ฎਂනࣁଉᰁᤒӾ҅ᔮᕹտԅਙ Კጱ༷ሲᥝय़ӞԶ̶ڊਂ҅ᘒӬࣁᖫᦲ෸ӧտ༄ັහഝᔄࣳ҅ ᯈٖړ๊ഘ̶ࢩྌᑕଧᬩᤈ෸҅ଉᰁᤒӾଚဌํአ#defineಅਧԎጱਡ҅ᔮᕹଚӧԅਙ λ    #defineਧԎਡጱ೰ե҅ᑕଧࣁᶼ॒ቘᴤྦྷਖ਼አ#defineಅਧԎጱٖ਻ݝฎᬰᤈԧ Ҙڦ܄defineਧԎጱਡ޾constਧԎጱଉᰁํՋԍ *p = 3҅max = 3; => max = *++p; => (2) > (1) ? (*++p) : (1) => p) > (1) ? (*++p) : (1)++*) ᒫ ᶭ11 ত۸ԅ0.ڡstaticݒᰁ᮷ฎἕᦊ ੴݒᰁ޾قӾጱಅํਁᜓ᮷ฎ0x00҅ਂٖ҅܄ত۸ԅ0.ࣁᶉாහഝڡ• ἕᦊ ԧݒᰁጱ֢አ᝜ࢱ̶ګত۸Ӟ̶ེstaticഴڡত۸҅ݝڡতᬩᤈ੪ ᑕଧ୏҅܄ੴݒᰁ޾staticݒᰁ᮷ਂؙࣁᶉாਂؙق೮ݒᰁٖ਻ጱ೮ԋ̶כ • ᥠ̶ ੴݢقහ᮷ڍੴݒᰁ޾قᖗጱڹstaticے• ᵌᡐ̶ᖫᦲग़ӻ෈կ෸҅ಅํ๚ Ძਁጱ֢አىstatic 
 ̶ڊጱय़ੜ҅᭜౮ფ܄ ᖨ٫ڊහጱᳩଶӧݢഴ҅ํݢᚆ໒ୗ۸ݸጱਁᒧԀտ᩻ڍӾ̶݄sprintf໒ୗ۸ጱ ܄ӞӻਁᒧԀᖨ٫کහ̶ਖ਼Ӟྦྷහഝ᭗ᬦᇙਧጱ໒ୗ҅໒ୗ۸ڍ•sprintfฎ໒ୗ۸ 
 ᧏̶(ྲইlenጱᳩଶय़ԭᥝ೩ᨬጱᑮᳵ౲ፓጱᑮᳵ) හጱᳩଶݢഴ̶֕ฎտํٖਂ᧛ٟᲙڍdstӾ݄҅ᬯӻکጱӞྦྷٖਂ҅՗src೩ᨬ memcpy(char dst, const char src, unsigned int len);ਖ਼ᳩଶԅlen හܻࣳԅڍහ҅ਙጱڍහํmemcpy҅ᬯฎӞӻٖਂ೩ᨬڍᚆጱۑ• ٍ॓ਁᒧԀ೩ᨬ 
 Კ̶ڊጱ҅ಅզᬯӻਁᒧԀ೩ᨬஉ਻ฃګԭ೩ᨬጱᳩଶӧฎኧ౯ժᛔ૩ഴ dst୏তጱٖਂӾ݄҅ᕮ๳ጱຽபᒧݩԅ '\0'҅ኧک• ਖ਼src୏তጱӞྦྷਁᒧԀ೩ᨬ 
 char src); හܻࣳԅstrcpy(char dst, constڍහ҅ਙጱڍ•strcpyฎӞӻਁᒧԀ೩ᨬጱ sprintf,strcpy,memcpyֵአӤํՋԍᥝဳ఺ጱࣈො ౲ᘏහᕟጱ೩ᨬٌ҅ፓጱฎ౲ᘏṛප҅౲ᘏֵአො׎҅ኜ౲ӷᘏّํ̶ Ԓӧᤩֵአ̶memcpyጱᳩ॒ฎአ๶ਫሿҁ᭗ଉฎٖ᮱ਫሿ੷ग़҂੒ᕮ຅پӥmemcpy٭ఘ ᬩᓒᒧݢզො׎Ӭṛපࣈᬰᤈݶᐿ౲ّ਻ᔄࣳጱහഝԏᳵጱ೩ᨬ҅ಅզᬯᐿ؀ᨬ҅ኧԭํᩙ ဌํՋԍ୽ߥ̶֕ฎ҅੒ԭच๜හഝᔄࣳ๶᧔҅ੱᓕݢզአ memcpy ᬰᤈ೩ܩmemcpy ԧ҅ݢฎ੒ێ๶᧔҅strcpy޾snprintfӞᛱ੪෫ᚆԅګ੒ԭᶋਁᒧԀᔄࣳጱහഝጱ॔ - ̶ڦጱ̶ࢩྌֵ҅አ memcpy ޾ strcpy ೩ᨬਁᒧԀࣁ௔ᚆӤଫᧆဌํՋԍय़ጱ૧ ṛපጱፓکහ౲ᘏአ࿤ᖫፗളਫሿጱ҅զᬡڍහӞᛱฎࣁٖ᮱᧣አ memcpyڍ strcpy Ӭইຎᳩଶ೰ਧᬦय़ጱᦾҁ๋սᳩଶฎრਁᒧԀᳩଶ + 1҂҅ᬮտଃ๶௔ᚆጱӥᴳ̶ٌਫ ೩ᨬጱٖਂᳩଶᬯӞ݇හ҅ฃᲙӬֵአӧ׎Ҕଚ׀- memcpy ᡱᆐṛප҅֕ฎᵱᥝ᷐क़൉ - snprintf ᥝ᷐क़೰ਧ໒ୗᒧଚӬᬰᤈ໒ୗ᫨۸҅ἋᅸӬපሲӧṛ̶ - strcpy ෫ወฎ๋ݳᭇጱᭌೠғපሲṛӬ᧣አො׎̶ ଶӧݶғ හ᮷ݢզਫሿ҅֕ฎٌਫሿጱපሲ޾ֵአጱො׎ᑕڍ੒ԭਁᒧԀ೩ᨬ๶᧔҅አӤᬿӣӻ - ᒫ ᶭ12 每 友 每 alloc做 每友2每 
 • 友 每友 友 new/delete 
 • 每 每没每 ◦ 还每 每 友 overflow每友 友2M⼒1M被 友友Windows ◦ 友Windows,友还每 • ⽣ (memory leak)每 • 友经 ञ຾ ) • int const * const a;a ( ) • int * const a;a ( ) • const int a;int const a; a ( • const int a;int const a; a Ძਁconstى 回 •static做做static做做 经 果果 •staticstatic ; 果果 •staticstatic ғڦ܄Ძਁىstatic ᒫ ᶭ13 and returns an integer被 
function that takes an integer as an argument • 做做⼒A pointer to a • 10⼒ A pointer to an array of 10 integers被 integers被 • 10每⼒An array of 10 pointers to • 10⼒ An array of 10 integers被 intege被r • ⼒ A pointer to a pointer to an • ⼒ A pointer to an integer被 • ⼒An integer被 ӥᶎጱਧԎڊአݒᰁaᕳ • 每 • (++)++++++ • sizeof⼒被sizeof每 • • const • 每 • ⼒*被 • 每 每 • ڦ܄୚አ޾೰ᰒጱ 三 • 回经 经全全 • 每全全 sizeof经4 
友经 • ڦ܄හᕟ޾೰ᰒጱ C/C++做 友友友友 每 友友 
 • ᒫ ᶭ14 NSLog(@"%.1f", money); float money = 1.011; ኸӞ֖ੜහכଚ҅فӞӻၶᅩᔄࣳ҅ᕮຎࢥᛣԲڊහᬌڍአNSLog • 友做做信做 • malloc做new 信 • 信 做 • ٭ఘ܄ړᓌᬿٖਂ ੪ฎ5̶؀ጱ ԧ̶ᘒ*(ptr – 1)੪ፘ୮ԭa + 4҅੒ଫ؀+ 6҅ಅզ๋ݸጱ*(ptr + 1)੪ฎӞӻᵋ๢ ࢩྌ҅ptrฎ೰ݻint *ᔄࣳጱ೰ᰒ҅ᘒptr೰ݻጱ੪ฎa + 5҅ᮎԍptr + 1Ԟፘ୮ԭa හᕟጱḒࣈ࣎҅೰ᰒ+1੪ฎᑏۖsizeof(int)ӻਁᜓ̶ڹ೰ᰒ҅೰ݻ୮ ᤒጱฎෆӻහᕟ҅ਙጱᑮᳵय़ੜԅ5 * sizeof(int)҅ࢩྌ&a + 1੪ฎa+5̶aฎӻଉᰁ ԅ2.֕ฎ҅ᬯ᯾ฎ&a + 1҅ࢩԅaդ؀1҅ᮎԍ੪ฎa[1]҅Ԟ੪ฎ੒ଫԭےᐏහഝḒࣈ࣎ ฎ1҅2҅3҅4҅5̶ളӥ๶҅a + 1ᤒڦړᔰزᔰጱහᕟጱḒࣈ࣎҅a[5]ጱزaդᤒํ5ӻ ຉғړ ഇଉᥠጱ̶ᘍጱ੪ฎC᧍᥺Ӥጱ೰ᰒጱቘᥴ޾හᕟጱቘᥴ̶؟ᬯᐿᔄࣳ᷌অ ؀݇ᘍᒼໜғ 2, ᵋ๢ printf("%d, %d", *(a + 1), *(ptr + 1)); int *ptr = (int *)(&a + 1); int a[5] = {1, 2, 3, 4, 5}; ڊզӥդᎱᬌڊ᧗ٟ return an integer • int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and • int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer • int (*a)[10]; // A pointer to an array of 10 integers • int *a[10]; // An array of 10 pointers to integers • int a[10]; // An array of 10 integers • int **a; // A pointer to a pointer to an integer • int *a; // A pointer to an integer • int a; // An integer • 
 hat take an integer argument and return an integer 被 
⼒ An array of ten pointers to functions t 10做做 • ᒫ ᶭ15 [stu performSelector:selector withObject:@"Mike"]; 
SEL selector = NSSelectorFromClass(@"setName"); 
 • •SEL NSString *className = NSStringFromClass(class); 
Class class =[Student class]; 
 • Student *stu = [[class alloc ]init]; 
Class class NSClassFromString@(@"student"); 
 • •class ᘱӞӥ༷ஷ޾ֵአܔҘᓌګ੘๢ݍള᥶ᬦOCӾጱވ֦ฎ 
 • new每 • newmalloc做每 • new malloc malloc每 • ⽣mallocnewnew mallocfree做 • new 做delete做 new c++mallocc 做 • ڦ܄malloc޾Newጱ • CFRunLoopObserverCreate release做CFRelease(); release • Create信Copy信Retain做 Core Foundationጱٖਂᓕቘ • selectormethod. selector?) ොဩ޾ᭌೠ࢏ํ֜ӧݶҘ(Difference between method and 每OC每 ҁ5҂Objective-C ᒫ ᶭ16 每经 • ⼈ 每 ⼒信被经⼒被每 • 每 ᶎݻ੒᨝᮷ํߺԶᇙ஄զ֦݊੒ᬯԶᇙ஄ጱቘᥴ̶ • 做UIkit⽆ • 做CoreAnimation.frameworks⽆ • 做CoreGraphics.frameworks⽆ • 做core Fundation⽆ • 做cocoa Fundation⽆ ԎތฎՋԍڦړᖗڹNS/CF/CG/CA/UIᬯԶ • id gettersetter • 每 • • NSObject ᦓ੒᨝?ܐࣳጱݒᰁᥝਂؙጱࣈ࣎ฎ᭽ਝӞӻ ᦓӾᚆड़ਧԎ౮ާݒᰁ?ই֜ᕅ๳Ӟӻ੒᨝ᔄܐ?ހᦓܐᔄӾ᭽ਝጱ ᦓӾฎՋԍ఺௏?ৼᔄᖀಥԧᆿᔄ,ᮎԍৼᔄտ᭽ਝᆿܐ 
 ;[• 2.SEL SEL aaa=@selector(text); [person performSelector:aaa • 1. [person text] • • SEL s2 = NSSelectorFromString(@"test1"); // SEL • SEL s1 = @selector(test1); // test1SEL果 每 SELSEL 每 •SEL每SEL ๶ጱොဩ? ՋԍฎSEL?ই्֜กӞӻSEL?᭗ᬦᮎԶොဩᚆड़,᧣አSEL۱ᤰ᩸ NSStringFomrSelector(@selector*(setName:)) 
 • ᒫ ᶭ17 • atomic, nonatomic每 • nonatomic ,setter getter; • copy 三,setter;; retaincount+1; • retain ,setter,三, ,NSInteger,double,bool; • assign 三,setter三;; assign • readonly getter setter ,; • readwrite ;gettersetter; አ? readwrite, readonly, assign, retain, copy, nonatomicં௔ጱ֢ 
 ⼦. (eat)每, life,eat,eat每 • (life)-eat;,, • :每 每 • , , ,每 • ,每 objective c is runtime language what does it mean?) ౯ժ᧔ጱObjective-Cฎۖாᬩᤈ෸᧍᥺ฎՋԍ఺௏? (When we call 
 每每 • 被每 被经2. ⼒ 1. ⼒ 被⼒override被⼒⼈被每 每⼒overload被⼒⼈ 每 • 最每 每 每 ᒫ ᶭ18 , tableView, , , • ,每每 ᫹(What is lazy loading ?)ےౡ delegate每 NavgationController B A 知 (popViewController) calldelegate 做delegate ◦ delegate notificaiton每 ◦ notification 每notificationdid每 should每notification ◦ delegatenotificationdelegate ◦ delegateNSNotification每 • 每 • Notification: , 每 每 delegatedelegate ◦ ⽆每(sender)(receiver) 每 ◦ 有每最 • Delegate: 每 ◦ valueForUndefinedkeysetValueforUndefinedKey每 ◦ _keykey三每 ◦ set_key三每 ◦ keysetset每 • KVC(Key-Value-Coding), setValue 每 •KVO⼒Key-Value- Observing被, , ᯿ᅩ))?ڦ܄ጱ ᓌᬿNotificationCenter̵KVC̵KVO̵Delegate?ଚ᧔กਙժԏᳵ ᒫ ᶭ19 . ◦ @class, 每 ◦ import经@class • import@class 
 有每 importObject-C#include#import • ?ڦ܄importӨ@classጱ# ?ڦ܄includeӨ#importጱ ,.m每Objective-C,, .m每,@private • objective-c,. ๊ጱොဩ? Objective-Cํᐺํොဩԍ?ᐺํݒᰁޫ?ইग़ဌํጱᦾ,ํဌํՋԍդ • Category,:, ◦ ⼀每 每 ◦ ,是, ⼀每 ◦ ,,, 每 ◦ 每 • : 每 • :著,.m, • : .m⼦,; ౮ާݒᰁ?ےӧᚆႲܩ,ොဩے ԅՋԍCategoryݝᚆԅ੒᨝Ⴒ?ڦ܄ࣁਫሿӾํ֜ڦᖀಥ޾ᔄ?ڦ܄ categories)޾୊઀(extensions)ฎՋԍ?զ݊ӷᘏጱ)ڦൈᬿᔄڦړ 每 • Category⼒被,Category,Category, • protocol⼒被,; 每 • Object-c,,, • ,每 ဌํጱᦾݢզአՋԍොဩ๊դ??ހOCํग़ᖀಥ ᒫ ᶭ20 每 每 • ګፓຽ-֢ۖ๢ (⼈) crash (⼈)每 crash经 C++ C++ object->function()每 Objective-C • Objective-C [object function]经 每 ⼈活()做()没 (dynamic typing)⼈(dynamic binding)(dynamic loading)经C++ • ObjectC++Objective-C • Objective-CC++C每 Ҙڦ܄Objective-CӨC̵C+++ԏᳵጱᘶᔮ޾ • @package • @public ; • @private ; • @protected ; 每 Ԏ?ތ ᔄݒᰁጱ@protected,@private,@public,@package्กݱํՋԍ 
 , A,A_copy每 • (mutableCopy)每, • (copy)每 and deep copy?) Difference between shallow copy) ?ڦ܄ጱګ೩ᨬ)޾Ⴎ॔)ګၠ॔ 每 @class ◦ :A–>B, B–>A#import 能每@class每 A–>B, B–>C, C–>D每 ◦ 100#import import每# ◦ ᒫ ᶭ21 //namea // predicate = [NSPredicate predicateWithFormat:@"self.name IN {'1','2','4'} || self.age IN{30,40}"]; // array = [persons filteredArrayUsingPredicate:predicate]; predicate = [NSPredicate predicateWithFormat:@"name='1' && age>40"]; //&&那 NSArray *array = [persons filteredArrayUsingPredicate:predicate]; //那那 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"age<%d",30]; //那 NSPredicate美种每 Ջԍฎ᧲᦯ 做做每 每C被每 做⼒OC做做 •OC做每每 每 C做做每 • ?ڦ܄Ջԍํګහ᧣አ޾ocጱၾ௳๢ڍC᧍᥺ጱ 
 每 ,做,每(做), • :1. 2. 3. 4. C 7.Objective-CC++ • :1.Cateogies 2.Posing 3. 4. 5.有 6. Objective-Cսᅩ޾ᗌᅩ 每-每 . • ᒫ ᶭ22 • arc arc • null⼦ c • ocnil Ҙڦ܄nil޾NULLጱ • nil⼒0被 •idOC id޾nilդᤒՋԍ char int 友 • NSString NSNumber NSArray NSDatec • CGFloat3264floatdouble • NSInteger3264intlong NSInteger CGFloat NSString NSNumber NSArray NSDate • ڦ܄ଉᥠጱocහഝᔄࣳߺԶ҅޾cጱच๜ᔄࣳํࠨ nonatomic每 • nonatomic 每 atomic • ڦ܄atomic޾nonatomicጱ .mcoc.mmc c++ oc cppc/c++ CӨOCႰአ predicate = [NSPredicate predicateWithFormat:@"name like '?s'"]; //?names predicate = [NSPredicate predicateWithFormat:@"name like 's'"]; //names //like出 predicate = [NSPredicate predicateWithFormat:@"name CONTAINS 'a'"]; //namea predicate = [NSPredicate predicateWithFormat:@"name ENDSWITH 'ba'"]; //nameba predicate = [NSPredicate predicateWithFormat:@"name BEGINSWITH 'a'"]; ᒫ ᶭ23 • self-> •self • self.getset 每self.self-> • nil 0每0每0去每 -Mac OS X ABI 做⽼nil 
 doublelong double long longnil0每 • sizeof(void*)float • nil0(nil) • nil——每 ኞՋԍҘݎᭆၾ௳տݎݻӞӻnil੒᨝ • NSNullJSnull •NilObjective-C • nilObjective-C •NULLC NSNull •NULL信nil信NilObjective-C(void *)0 @"value1",@"arg2" : arg2.isEmpty ? [NSNull null] : arg2}; 每NSDictionry *parameters = @{@"arg1" : 每 • NSNull:NSNullNSObject每著 每Objective-CNULL((void*)0). •NULL: CNULL. C/C++ . Class myClass = Nil; •Nil:Objective-CNil((void *)0)每 时每 CNULL每Objective-Cnil nilCNULLobjc/objc.h每nilObjective-C每 • ڦ܄nil̵Nil̵NULL޾NSNull ᒫ ᶭ24 self self @property = ivarҁਫֺݒᰁ҂ + getterҁݐොဩ҂ + setterҁਂොဩ҂ @propertyጱ๜ᨶғ ᬯӻᔄӾጱҘک ے@propertyጱ๜ᨶฎՋԍҘivar̵getter̵setterฎই֜ኞ౮ଚႲ • 三 ҁ᧍ဩ҂Ҙڦ܄init޾initwithobject “#ifndef INCvxWorksh#define INCvxWorksh信#endif” endif endif } ifdef __cplusplus endif extern "C" { ifdef __cplusplus define __INCvxWorksh ifndef __INCvxWorksh १෈կ᮷ํᔄ֒զӥጱᕮ຅ҘٵԅՋԍຽ NSString *str = [[NSString alloc]initWithCString:nullTerminatedCString encoding:encoding]; ٟӞӻNSStringᔄጱਫሿ • _blockblock三_weak每 • _weakarc(NSString)(int) blockarcmrc_ • ڦ܄᷶ᒧץ_block/weak ޾ᘶᔮڦ܄ᔄොဩ޾ਫֺොဩጱ๜ᨶ ᒫ ᶭ25 
 4. getter信setter 3. ⼒assign, strong, weak, unsafe_unretained,copy被 2. ⼒readwrite, readonly被 1. ⼒atomicnonatomic被 ᲫਁҘى@propertyӾํߺԶં௔ •    objc_getAssociatedObject •    objc_setAssociatedObject හғڍ௔ጱਫሿ҅ᵱᥝ׵ۗԭᬩᤈ෸ጱӷӻંے፥ጱᵱᥝᕳcategoryी •    categoryֵአ@propertyԞฎݝտኞ౮setter޾getterොဩጱ्ก҅ইຎ౯ժ ᦓጱ੒᨝ᚆਫሿᧆં௔ܐ௔ጱፓጱฎ૶๕᭽ਝ౯ •    ࣁprotocolӾֵአ@propertyݝտኞ౮setter޾getterොဩ्ก҅౯ժֵአં @protocol޾categoryӾইֵ֜አ @property 信⼀信crash • copyNSArray NSSpinLock信@syncronized nonatomicatomic nonatomic每 • nonatomicatomic每 *array; Ջԍᳯ᷌ғ@property (copy) NSMutableArrayڊᬯӻٟဩտ runtime෸҅տଃ๶உग़ጱӧො׎ጱ̶ ᦜ्กં௔ฎֵአ_୏१ጱ҅ӧᥢ᝜ጱ޸ݷ҅ࣁֵአرӧᬦ҅޸ݷ᮷ᥝํᥢ᝜҅ฎӧ զ_୏१ԧ̶ވෙฎڣইຎ౯ժᥝಋۖኞ౮getterොဩ҅੪ᥝ (nonatomic, copy) NSString *_name;ᮎԍಅኞ౮ጱ౮ާݒᰁݷ੪տݒ౮__name҅ ই्กં௔ԅ@propertyྲ҅_ํވ௔ݷฎંڹෙ୮ڣኞ౮getterොဩ෸҅տ ԧ҅ᴻᶋ֦፥ጱᥝද౮ާݒᰁݷ̶ےྌӧٚᵱᥝಋۖႲ synthesize propertyName = _propertyName;ࢩ@ےሿࣁᖫᦲ࢏૪ᕪἕᦊԅ౯ժႲ ӧտᛔۖݳ౮̶ڞဩ҅ @synthesize propertyName = _propertyName;ᝑಋۖਫሿԧgetter/setterො Ძਁ೰ਧ҅ᝑӧ೰ਧ҅ἕᦊԅىᬯฎᖫᦲ࢏ᛔۖݳ౮ጱ҅᭗ᬦ@synthesize ᔄӾғکےivar̵getter̵setterই֜ኞ౮ଚႲ getter + setter҂ ௔” (property)ํӷय़༷ஷғivarҁਫֺݒᰁ҂̵ਂݐොဩҁaccess method Җં“ ᒫ ᶭ26 • ,. 
 . • @selector[object @selector(:..) ] ;object 
class_func = @selector(add:int); SEL class_func ; //ਧԎӞӻᔄොဩ೰ᰒ @end -(int)add:int val; @interface foo 
 . 做Object-C做@selector • @selector()C做,C做三 每 ⼒isa被 Class 每[NSClassFromString][obj class]每最 • හ᧣አጱҘڍ᥺ጱ Objective-C ጱclassฎই֜ਫሿጱҘSelectorฎই֜ᤩ᫨۸ԅ C ᧍ meta-class(NSObject,meta-classNSObject) meta-class,Classmeta-class,meta-class meta-class Class ,Class,, Objective-C Ӿ҅meta-class ೰ጱฎՋԍҘ readonly,.mreadwrite ই֜ԅ Class ਧԎӞӻ੒क़ݝ᧛੒ٖݢ᧛ٟጱં௔? • runtime • KVC දӞӻᔄጱᐺํં௔Ҙץই֜ᦢᳯଚ 每 (root meteClass).isa ⼒meteClass被每isa,isa 每 isa, meteClass()每每 •isaClass . isa,Class isa೰ᰒᳯ᷌ ᒫ ᶭ27 每 信⼀信每信⼀ 信⼀信经NSMutableArray • NSArray • ᷶Ծኞጱݒ۸҂ ץcopyکNSMutableSet̵NSMutableDictionaryጱᇙ௔޾֢አҁ᭬ NSArray̵NSSet̵NSDictionaryӨNSMutableArray̵ ݒਁᒧԀݢզፗളአstrong̶ ෙ҅ಅզ҅ӧݢڣෙ੪տᘙᩇ௔ᚆ҅୽ߥአಁ֛ḵ҅አstrong੪ӧտٚᬰᤈڣᬰᤈض᮷ᥝ ग़҅ྯӞེڦNSStringጱࣈොᇙکᯈᑮᳵ̶ইຎᑕଧӾአړᯈᑮᳵ҅ইຎฎݢݒਁᒧԀ಍ ړฎӧݢݒਁᒧԀ҅ইຎฎӧݢݒਁᒧԀ҅੪ӧٚވෙਁᒧԀฎڣضᵱᥝ҅ײአcopyጱ෸ ᯈӞེٖਂ҅֕ฎইຎړአcopy޾strong᮷ฎݝ҅ײOCӾNSStringԅӧݢݒਁᒧԀጱ෸ Ҙڦ܄አcopy޾strongጱײNSString ጱ෸ ෸ဌᳯ᷌҅ᬩᤈ෸಍ಗᤈፘଫጱොဩ҅ᬯ੪ฎಅ᧲ጱۖாᕬਧ̶ someVar = var ෸҅ኧԭᗌ getter ොဩݶ໏տ੕ᛘૄმ̶ᖫᦲ کૄმҔ౲ᘏ୮ᬩᤈ instance.var = someVar҅ኧԭᗌ setter ොဩտ੕ᛘᑕଧ ک᷌҅֕ฎ୮ᑕଧᬩᤈ ဌᳯײsetterොဩ޾ @getter ොဩ҅ᖫᦲጱ෸@ ׀@dynamic var҅ᆐݸ֦ဌํ൉ ইӞӻં௔ᤩ्กԅ؃ݢ҂̶ܨ getter ׀ኞ౮̶ҁ୮ᆐ੒ԭ readonly ጱં௔ݝᵱ൉ ᦫᖫᦲ࢏ғં௔ጱ setter Ө getter ොဩኧአಁᛔ૩ਫሿ҅ӧᛔۖޞ - @dynamic Ӥᬯӷӻොဩ̶ےᦲ࢏տᛔۖԅ֦ - @synthesize ጱ᧍Ԏฎইຎ֦ဌํಋۖਫሿ setter ොဩ޾ getter ොဩ҅ᮎԍᖫ @synthesize޾ @dynamic᮷ဌٟ҅ᮎԍἕᦊጱ੪ฎ@syntheszie var = _var; - @propertyํӷӻ੒ଫጱ᦯҅Ӟӻฎ @synthesize҅Ӟӻฎ @dynamic̶ইຎ Ջԍ֢አҘํڦړ@synthesize޾@dynamic • NSString NSData. ฎՋԍᔄࣳҘڦړobj ੒ԭ᧍ݙNSString *obj = [[NSData alloc] init]; ҅ᖫᦲ෸޾ᬩᤈ෸ [果performSelector:SEL果withObject:1果withObject:2]; 
• selectorseletor每 SEL.performSelecor. 
 NSStringFromSelector(SEL); • SEL每NSString果*果=果 SEL果果=果NSSelectorFromString(); • ᒫ ᶭ28 ypedef struct HYBStruct { 
 performSelectorapi每 withObject:(id)object2; - (id)performSelector:(SEL)aSelector withObject:(id)object1 - (id)performSelector:(SEL)aSelector withObject:(id)object; - (id)performSelector:(SEL)aSelector; 3ӻզӤ݇හٌ҅ӾӞӻԅᕮ຅֛فெ໏ֵአperformSelectorփ 三UI每每 Setter 每 Setter 
三每 self.name[self setName:@object];每name • setter三三每 ԍӧݶ ࣁӞӻ੒᨝ጱොဩ᯾ғself.name=@object;޾name=@objectํՋ NSLog(@"%@", date); // 2015-04-09 16:00:00 +0000 NSDate *date = [formatter dateFromString:timeStr]; formatter.timeZone = [NSTimeZone defaultTimeZone]; formatter.dateFormat = @"yyyy-MM-dd"; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; NSString *timeStr = @"2015-04-10"; ᧗಩ਁᒧԀ2015-04-10໒ୗ۸෭๗᫨ԅNSDateᔄࣳ iosJSON每 • 每 • 信信iOS 每 • dataSource • 每key信信⼀每 key经NSMutableDictionary信⼀信 • NSDictionarykey 信⼀每 经NSMutableSet信⼀信每 NSSet信信• ᒫ ᶭ29 ᔄࣳ᫨ഘ̶ ᔄࣳᬰᤈፘଫጱ؀@selector(foo));ᬯ໏ጱ୵ୗ҅֕ฎᵱᥝ໑ഝٍ֛ጱ݇හᔄࣳ݊ᬬࢧ Ԟ੪ฎ᧔҅[obj foo];ࣁobjcۖாᖫᦲ෸҅տᤩ᫨ഘԅғobjc_msgSend(obj, sel_registerName("foo")); ((void (*)(id, SEL))(void)objc_msgSend)((id)obj, ᬯ໏ғ؟ਫᴬӤ҅ᖫᦲ࢏ࣁᖫᦲ෸տ᫨ഘ౮objc_msgSend҅य़༷տ ᔮҘىՋԍ හԏᳵํڍ()ᭆၾ௳[obj foo]޾objc_msgSendݎobjcӾݻӞӻ੒᨝ }     NSLog(@"%d %d", obj.arg3->a, obj.arg3->b); - (void)call:(HYBObject *)obj { ྋᏟጱහഝጱک// ࣁࢧ᧣෸஑ [self performSelector:@selector(call:) withObject:obj]; obj.arg3 = str; obj.arg2 = @"arg2"; obj.arg1 = @"arg1"; HYBObject *obj = [[HYBObject alloc] init]; str->b = 2; str->a = 1; my_struct str = (my_struct)(malloc(sizeof(my_struct))); @end }   free(self.arg3); - (void)dealloc { ᯈጱٖਂ҅౯ժᥝಋۖ᯽නധړ// ࣁञӤ @implementation HYBObject @end @property (nonatomic, copy) NSString *arg2; @property (nonatomic, copy)  NSString *arg1; @property (nonatomic, assign) my_struct arg3; @interface HYBObject : NSObject } *my_struct;   int b; int a;   ᒫ ᶭ30 performSelector:withObject:afterDelay: • alloc信class信 description init信dealloc信– • NSObjectObjetive-CNSObject每 ᔄNSObjectጱᮎԶොဩᕪଉᤩֵአ? NSMutableArray每 每NSArrayNSMutableArray NSAarry⼀ NSArray每NSArray • NSMutableArray አNSArray?ֵײአNSMutableArray҅Ջԍ෸ֵײՋԍ෸ • 每 զզfooᬮฎ_foo֢ԅkeyҘ ᝑӞӻᔄํਫֺݒᰁNSString *_foo҅᧣አsetValue:forKey:෸҅ݢ ᤒӾ୏তತ̶ᆐݸ᧣አᆿᔄጱᬯӻොဩ̶ڜ՗ᆿᔄጱොဩڞᘒ୮ֵአsuper෸҅ ᤒӾ୏তತ҅ইຎဌํ҅੪՗ᆿᔄӾٚತҔڜᔄጱොဩڹ୮ֵአself᧣አොဩ෸҅տ՗୮ Son ҃xxx ᬯӻ੒᨝̶ ڹӤᶎጱֺৼӧᓕ᧣አ[self class]ᬮฎ[super class]҅ളݑၾ௳ጱ੒᨝᮷ฎ୮ ᬯӻොဩ෸҅ᥝ݄ᆿᔄጱොဩ҅ᘒӧฎ๜ᔄ᯾ጱ̶ ᦫᖫᦲ࢏҅᧣አclassޞฎ೰ݻጱݶӞӻၾ௳ളݑᘏѺ՜ժӷӻጱӧݶᅩࣁԭғsuperտ ਫ superฎӞӻ Magic Keyword҅ਙ๜ᨶฎӞӻᖫᦲ࢏ຽᐏᒧ҅޾self̶ٌ܄Ӟӻ᧏ Ѻ”̶ᬯฎஉฦ᭭ጱމஉग़Ոտమ୮ᆐጱᦊԅ“super޾selfᔄ֒҅ଫᧆฎ೰ݻᆿᔄጱ೰ᰒ አොဩጱᬯӻᔄጱਫ̶ֺᮎsuperޫҘ᧣ڹᔄጱᵌᡐ݇හ҅೰ݻ୮ ԭObjective-CӾ੒self޾superጱቘᥴ̶౯ժ᮷Ꭳ᭲ғselfฎىᬯӻ᷌ፓԆᥝฎᘍ੊ NSStringFromClass([super class]) = Son NSStringFromClass([self class]) = Son ڊ// ᬌ @end }     return self;     }         NSLog(@"%@", NSStringFromClass([super class]));         NSLog(@"%@", NSStringFromClass([self class]));     if (self) {     self = [super init]; - (id)init { @implementation Son : Father ՋԍҘڊӥᶎጱդᎱᬌ ᒫ ᶭ31 •id每 Ҙڦ܄idᔄࣳฎՋԍ҅instancetypeฎՋԍ҅ํՋԍ • person.run //personrun • int age = person.age; // personage • person.name=@”itcast”;//personsetName • Person *person = [Person new]; • Person @propertynameage,run每 get每 每setgetset • ᅩ᧍ဩ๜ᨶฎՋԍ,ٟӞӻᅩ᧍ဩጱֺৼ,ଚٟӤဳ᯽ , Ҙހᕮ຅֛୮ӾᚆਧԎoc੒᨝ ◦ 那 ◦ •Set •Set每 Setොဩጱ֢አฎՋԍҘSetොဩጱঅ॒Ҙ Get Getොဩጱ֢አฎՋԍҘ • • • 动 ୌӞӻ੒᨝ᵱᥝᕪᬦᮎӣӻྍṈҘڠ init initWithName initLayout 
 每 Ջԍฎ຅᭜ොဩֵ҅አ຅᭜ොဩํՋԍဳ఺ᅩ̶ 每 • Foundation numberWithChar: + numberWithDouble: + numberWithFloat: + numberWithInt: • CocoaTouch⽆NSNumber + numberWithBool: + Ջԍฎᓌ׎຅᭜ොဩ? ᒫ ᶭ32 -(void)run { NSLog(@"ݰ:%@!",foodName);} -(void)eat:(NSString *)foodName; @implementation person //ਫሿ @interface person: NSObject< MyDelagate> //्ก @end -(void)run; @optional -(void)eat:(NSString *)foodName; @required @protocol MyDelagate ୌڠ// ٟӞӻਠෆጱդቘ,۱ೡ्ก,ਫሿ } objectAtIndex:i]); for (int i = 0; i<[array count]; ++i) { NSLog(@"%d=%@",i,[array ጱ౼ݐݸጱਁᒧԀڊᬌ ڦړNSArray *array = [str componentsSeparatedByString:@"|"]; //ᬯฎ    NSString * str = @"20 | http://www.baidu.com"; ਙժ̶ڊᬌڦړ,ഝ ᶎ޾ݸᶎጱහڹ౼ݐਁᒧԀ”20 | http://www.baidu.com”Ӿ,”|”ਁᒧ ଚӬԡٟӧᥢ᝜:setterොဩӾጱnewAgeଫᧆԅage ݢ;ܨտྒ஗ሾ,տ᯿॔᧣አᛔ૩!self.age දԅ_age @end self.age = newAge; } - (void)setAge:(int)newAge { implementation Person@ :ހᬯྦྷդᎱํՋԍᳯ᷌ • 每 • get经 ᕚ୏१ጱঅ॒Ҙښ౮ާݒᰁݷጱ޸ݷզӥ instancetype每 • ᒫ ᶭ33     BOOL isDir = NO;     NSFileManager * fileManger = [NSFileManager defaultManager]; ෙ෈կᬮฎፓ୯ڣ.    // 1 + (void)deleteFiles:(NSString *)path;{ ᴻ೰ਧ᪠ஆӥጱಅํ෈կ̶ڢහ҅ਫሿ᭓୭ڍᖫٟӞӻ ◦ ARC: __bridge CF->F被 ◦ ARC:bridge_retained,F->CFbridge_transfer⼒ • FoundationOCCore FoundationC • ڦ܄Foundation੒᨝ӨCore Foundation੒᨝ํՋԍ 02321 unsigned int2 0~655354 
231 2311 
 int:2 -32768~327674 ᝜ࢱ؀unsigned intӨ intጱݐ ڊᦡintᳩଶԅ65535҅᧗ٟ؃̶ڦ܄unsigned int ޾int ํՋԍ •@:OC 
 ,id *每 •idObject(NSObject)每id 
 •SEL“selector”,------- SEL̵id̵@ጱ఺௏?ڊٟڦړ᧗ 
 • selector:,做 
 • isMemberOfClass: 
 • isKindOfClass,, ฎՋԍڦړisKindOfClass̵isMemberOfClass̵selector֢አ @end NSLog(@"run!");} } ᒫ ᶭ34 }     } ጱฎፓ୯౲ᘏӧਂࣁ");ܦ        NSLog(@"֦಑     }else{         }             [manager removeItemAtPath:filePath error:nil];              NSLog(@"%@",path);         }else{             }                 [self deleteFiles:subPath]; isDirectory:&issubDir];                  [fileManger fileExistsAtPath:subPath                 BOOL issubDir = NO; stringByAppendingPathComponent:str];                 subPath  = [path             for (NSString * str in dirArray) {             NSString * subPath = nil; contentsOfDirectoryAtPath:path error:nil];         NSArray * dirArray = [fileManger         if (isDir) { ෙฎӧฎፓ୯ڣ .        // 2     if (isExist) { isDirectory:&isDir]; BOOL isExist = [fileManger fileExistsAtPath:path     ᒫ ᶭ35 A -shared B -fno-objc-arc C -fobjc-arc D -dynamic Ջԍ݇හےႲ MRC෈կࣁARCૡᑕႰݳᖫᦲ෸҅ᵱᥝࣁ෈կጱCompiler FlagsӤ NSZonedealloc每 ⽣每ARC ⽣每forfor 每 drain0 每 • ARC • A D ࣁֵአARCጱᶱፓӾӧᚆֵአNSZone ౮ٖਂအᶂ ݢᚆտ᭜ڞᯈ੒᨝ᘒӧአautoreleasepoolړC ୮ֵአARC๶ᓕቘٖਂ෸҅ࣁᕚᑕӾय़ᰁ ᯈጱ੒᨝ړտ᯽නࣁٌӾײB autoreleasepool ࣁ drain ጱ෸ ሿautoreleaseڊA ୮ֵአARC๶ᓕቘٖਂ෸҅դᎱӾӧݢզ ԭObjective-CٖਂᓕቘጱൈᬿᲙ᧏ጱฎىӥᶎ 每 每ARCretainrelease retainrelease • ARC objc_retain每 objc_release每retain每ARC 每ARC是release每ARC 每release 每deallocdeallocARC release每⼒/被dealloc __strong每 “”release每 • 每 releaseautorelease ARCObjective-C都想ARC ARC॒ቘܻቘ ҁ6҂ٖਂᓕቘ ᒫ ᶭ36 දԏݸ:ץ ୌጱ੒᨝releaseڠٖ҅ྯེ஗ሾ᮷ਖ਼ӤӞེ ᥴ٬ොဩ2ғইຎiሻ޸य़҅Ӟེ஗ሾ᮷տ᭜౮ᛔۖ᯽න࿰ᤩऴჿ҅ᛔۖ᯽න࿰නࣁfor஗ሾ ጱᳯ᷌ਂٖ܄ഝ຾ܛୌጱ੒᨝҅ᥴ٬ڠᕮ๳ݸ҅ᲀྪ ဩ1ғইຎiྲ᫾य़҅ݢզአ@autoreleasepool {}ᥴ٬҅නࣁfor஗ሾक़҅஗ሾېᥴ٬ ጱሿ᨝̶ڊሿԧٖਂფڊᑮᳵਖ਼ᤩᘙੱᘒဌํᤩ᯽නധ҅ಅզ੪ Ӟਧᑕଶ෸ٖ҅ਂکᦡ҅୮someLargeNumberय़؃አጱٖਂᑮᳵ಍ᚆᤩ᯽නധ̶ܛහഝಅ ᛔۖ᯽න࿰ӾጱຽᐏԧautoreleaseጱᬯԶ҅ײ࿰Ӿ҅ݝํ୮ᛔۖ᯽න࿰ᤩreleaseጱ෸ runloopӾጱᛔۖ᯽නڹ୮کےਂࣁᳯ᷌ғᳯ॒᷌ࣁྯಗᤈӞེ஗ሾ҅੪տํӞӻstring }     NSLog(@"%@",string);     string = [string stringByAppendingString:@"xyz"];     string = [string lowercaseString];     NSString *string = @"Abc"; {   for (int i = 0; i < someLargeNumber; ++i) ᛔۖ᯽න࿰ଉᥠᶎᦶդᎱ տ᧣አԧ੒᨝ጱdealloc ොဩ಍ᚆᬰᤈ᯽න੒᨝ጱٖਂ̶ײԅ0ጱ෸     ӧտ҅᧣አ੒᨝ጱrelease ොဩݝฎਖ਼੒᨝ጱ୚አᦇහ࢏-1҅୮੒᨝ጱ୚አᦇහ࢏ Ҙހ᧣አ੒᨝ጱrelease ොဩտᲀྪ੒᨝ • assigin OC , weak OC “” (scalar type CGFloat NSlnteger )三每 然(nil out)每 assign “” 每assign • weak “” (nonowning relationship)每 •weakassign? IBOutlet weak经strong每 ,, weak, 
 : delegate • ARC ,, weak , • weak? Ძਁ҅ፘྲ assign ํՋԍӧݶҘى አ weakֵ٭Ջԍఘ ᘍᒼໜғB݇ ᒫ ᶭ37 • ୌٖਂ࿰?ڠᵱᥝࣁᑕଧӾײՋԍ෸ ӧݒ,Ֆԅ1؀ᝑฎ:copy personጱretainCount ݒԅ2,1ے؀ฎ:retain personጱretainCountጱ ӧݒ,Ֆԅ1 ᝑ؀ࣁself.person ෸,ইຎฎassign,personጱ retainCountጱ 1 self.person = per; ฎ؀Person * per = [[Person alloc] init]; ྌ෸person ጱretainCountጱ ଚᥴ᯽ԅՋԍ,؀ࢧᒼpersonጱretainCount ᴻಅํ੒᨝҅ಅํහᕟٖጱ੒᨝ᛔۖ-1 1ڢහᕟ retain+1҅release-1҅release-1 2 හᕟᛔۖ+1 3فےୌ+1҅retain+1҅ڠstrጱretainCount NSLog(@”%@%d”,str,[str retainCount]); [aryremoveAllObjects] NSLog(@”%@%d”,str,[str retainCount]); [str release]; [str release]; [str retain]; NSLog(@”%@%d”,str,[str retainCount]); [aryaddObject:str]; [str retain]; NSString *str = [NSString stringWithFormat:@"test"]; NSMutableArray* ary = [[NSMutableArray array] retain]; ੝?ᒫԫӻ޾ᒫӣӻޫ? ԅՋԍ? Ջԍ?ᬯ෸strጱretainCountฎग़ڊ፡ӥᶎጱᑕଧ,ᒫӞӻNSLogտᬌ • Objective-Cisa objective-C੒᨝ጱٖਂ૲ੴฎெ໏ጱҘ [pool1 drain]; } //᯽න࿰ NSLog(@"%@",string); string = [string stringByAppendingString:@"xyz"]; string = [string lowercaseString]; NSString *string = @"Abc"; NSAutoreleasePool * pool1 = [[NSAutoreleasePool alloc] init]; for(int i = 0; i<1000;i++){ ᒫ ᶭ38 • ARC要, , . , iOS5.0 (Xcode4) 每 • Garbage collection (都想)每iOS都想, ARCLLVM3.0 • ARC(automatic reference counting) • MRC(manual retain-release) ᓕቘ੒᨝ٖਂ(౲ᘏٖਂᓕቘොୗํߺԶ)Ҙ(᯿ᅩ)ګobjcֵአՋԍ๢ ,,⽣. 友,, ,友),,, ,友( • NSObject, . ٖਂᓕቘጱ᝜ࢱ? . , , . , • , ԅՋԍᥝᬰᤈٖਂᓕቘ? 每 retainCountretainCount0 • (retainCount)每 runloop ᓕቘ੒᨝ٖਂҘګobjcֵአՋԍ๢ release඙̶֢ ಗᤈpush̵pop඙̶֢ᲀྪ੒᨝෸ಗᤈڦړහݷ੪ݢզᎣ᭲҅੒autoreleaseڍ፡ •    objc_autorelease •    objc_autoreleasepoolPop •    objc_autoreleasepoolPush හਠ౮.ڍӣӻڜහᕟጱ୵ୗਫሿ,Ԇᥝ᭗ᬦӥڜautoreleasepoolզӞӻᴚ ᝘ຎฎই֜ਫሿautoreleasepoolጱҘ • ᕳ౯ժ?׀࿰൉ਂٖํވୌٖਂ࿰҅ฎڠইຎ౯ժӧ ᒫ ᶭ39 
 • : 三,nil 
 • ⼰ : (retainCount = 0) 2. 三nilrelease每 1. ◦ MRC, ⽣ , new, ⽣ ◦ Person * person = [Person new]; (三nil)友person • ⽣ [nil retain]每 ◦ release三niloc ◦ 时每 • :每 ٖਂᓕቘᎸᑪጱ੒᨝: , 1, 1 
• : ◦ retain ,, release • retain release ◦ release release autorelease 1 ◦ alloc, new, copy , release , • 1 , • 1 , • , • ڞٖਂᓕቘጱܻ 
 unwarp ,unowned,unowned,weak ,,ocunsafe_unretained,assignoc, ,weak,,unowned,时 delgateweak,[weak self],swift,unowned,,self 
• swift: 
 • ,block,ARC每 iOSฎই֜ᓕቘٖਂጱҘ ᒫ ᶭ40 • ,+1, -1每 Objective-C (retainCount)每: • ?ڦ܄ԍ [NSAutoreleasePool release]޾[NSAutoreleasePool drain]ํՋ ӧኧ֦᯽න?ײኧ֦ᨮᨱ᯽න੒᨝,Ջԍ෸ײᓌᬿՋԍ෸ releaseጱ?ᤩײNSAutoreleasePool?ଚ᧔กautoreleaseฎՋԍ෸ ൈᬿٖਂᓕቘᥝᅩ̵autorelease̵release̵ڦړ • retain • release • 要 ྋᏟ᯿ٟsetොဩ • 要set • release •setretain Ҙ٭ᐿఘپᔮӾٖ҅ਂအᶂํߺى੒᨝ᕟݳ • dealloc ౮ާݒᰁጱ੒᨝҅ࣁߺ᯾ᯈ੒᯽නҘ • setsetretain每 ᯽නҘڹ౮ާݒᰁӧᤩ൉כᔮӾ҅Ꮯى੒᨝ጱᕟݳ 3. (有) 2. ⼒被 1. ᔮى੒᨝Ө੒᨝ԏᳵਂࣁጱ • retainCount = 0retain • dealloc[super dealloc] ෙ੒᨝૪ᕪᤩᲀྪڣই֜ ᒫ ᶭ41 ⼒kCFRunLoopBeforeWaiting被 • ObserverRunLoopRunLoop ᯽නҘײᛔۖ᯽න࿰Ջԍ෸ release • autorelease • autorelease runloop⽽PushPop Autoreleaserunloop⽽ • autorelease"}"每 • 活 • autorelease release • • ᛔۖ᯽න࿰ฎՋԍ,ই֜ૡ֢ ? 
 ,Run loop! • ,releaseautorelease?autorelease, ,release no-op(),GCdrain • :(ARC),,GC(都想) 每 
• autorelease ,release release,,release每 • NSAutoreleasePool: NSAutoreleasePoolautorelease, • autorelease:,, -1每 • release: -1; • mutableCopy:, 1; 1回+1 • copy: +1;//copyOCmutable回 • retain: +1; • alloc,allocWithZone,new(): +1; dealloc ,⼀每 , 0 = • ᒫ ᶭ42 经 • FIFO : FIFOFIFO经FIFO cache每 • FIFO,LRU,LFU每NSCacheapp cache每 • 每cacheapp每 ጱࢶᇆٖਂᖨਂ࢏ҁᑏᴻᒽኼฎӞਧᥝ᧔ጱ҂ܔἋᅸ֦ᦡᦇӻᓌ ARC weak block 
weakSelf block weakSelfblockstrongSelfblock • instrumentsleak • analyze ᶱፓ෸֦ฎெԍ༄ັٖਂအᶂݎ୏ • ARC retain/release⼒被 ARCretain/release/autorelease • ARCCretain/release/autorelease 每 ARCMRCretain/release/autorelease每 ᘏᓕቘٖਂҘݎARC᭗ᬦՋԍොୗଆۗ୏ strongweak 5. arc.h@class 4. arcretainrelease. -1 3. arcretainCount+1 - 1 autoreleasepool 2. 要 1. arc. ARCᳯ᷌ ,,每每 •iOS 都想每autorelease,gc, ᔮ?ى gc)ํՋԍ)ګIPhone OSํဌํ࣯࣍ࢧත?autorelease ޾࣯࣍ࢧත ᒫ ᶭ43 [dict release]; value" forKey:@"akey"]; NSLog(@"%@", [dict objectForKey:@"akey"]); NSDictionary *dict = [NSDictionary dictionaryWithObject:@"a string ᕮຎڊӥᶎᑕଧྦྷጱᬌڊٟ } return [person autorelease]; ॓ဳ:ARC෸ӧአ autorelease Person *person=[Person alloc]init]; +(id)Person { • Objective-Catomic,readwrite,strong • atomic,readwrite,assign Ძਁ᮷ํߺԶҘىᲫਁ෸҅ἕᦊጱىARCӥӧดୗ೰ਧձ֜ં௔ 每 时每每 每 • 每 ሿՋԍᳯ᷌Ҙڊනԧ҅ݢᚆտ ૪ᕪᤩ᯽ܩ᭗Ꭳ෸҅ᬯӻ੒᨝ݎ᭗ᎣӾஞӾ҅୮᭗ᎣӾஞکے੒᨝Ⴒ retainstrong delegateassign(MRC)weak(ARC) • ⼒delegate被 >block->_ivar⼒被 self.otherVar = XXX;_otherVar = …};self->block->selfself- self.someBlock =Type var{[self dosomething]; blockblock retainCount1(ARC)每ARCARCblock • blockblockcopyblock(ARC) invalidate validate0 selftarget⼒self->timer->self被每 timer • ⼒NSTimer被NSTimerNSTimer ሿٖਂ஗ሾ୚አጱ࣋วํߺԶҘڊଉᥠጱ ⼀经 经 • LFU : ⼒1被经 经 LRU : 经经 • ᒫ ᶭ44 tableviewretain每 • tableviewviewretain retainҘ உग़ٖᗝጱᔄ҅ইtableviewጱdelegateጱં௔ฎassignӧฎ 每 • ARC 每 _testId 每blockcontroller block 每controllerdealloc每 • Blockblock 
每每 iOSฎই֜ᓕቘٖਂጱҘ Ҙ٭ොဩ឴ݐiosٖਂֵአఘڊٟ ऒ܄ୌጱڠڹऒݒ౮ԧᰀ೰ᰒ,ԏݸጱ᯽න,ӧᚆ᯽නԏ܄೰ݻጱضܻ--- ᕮຎ —տ᭜౮ٖਂအᶂڊ࣐ํᬌܦݸ಑ڹ[ᕮຎฎ: Habb,ࣁ[name releaseڊᬌܦ಑ [ name release]; name = @”Habb”; NSString * name = [ [ NSString alloc] init ]; զӥդᎱጱಗᤈᕮຎڊ᧗ٟ տ᭜౮ᬦଶ᯽න ୌጱ੒᨝,ԏݸጱrelease,ڠ຅᭜࢏ڥa string value,ᆐݸૄმ——ܻࢩ:׎ ڊᬌܦ಑ ᒫ ᶭ45 controllerKVO感 KVO每 KVOጱᗌᵅ? ԧᥡ੊຤Ӟં௔ݒ۸ጱොဩ׀ਙ൉҅ګᥡ੊๢؀KVO:Ძ ᖫᎱ ֵአਁᒧԀፗളᦢᳯ੒᨝ጱં௔̶؀ – ᒼғKVC:Ძ ՋԍฎKVO޾KVC? ᤩදݒ౮NSKVONotifying_MYPerson ᘏԏݸ҅personᔄࣳ૪ᕪኧMYPersonލፊے>isa=(Class)MYPerson,ኧྌݢᥠ҅ࣁႲ person->NSObject-_ک[[MYPerson alloc]init];ݸᶎ಑ෙᅩ҅፡ >isa=(Class)NSKVONotifying_MYPerson.ݶ෸౯ժࣁ self.person = person->NSObject-_ کऒ੪ᚆ፡܄಑ෙᅩ҅ࣁ᧣ᦶ ࣁself.person.age = 20; ᬯ᯾҅ܔNSKVONotifying_MYPersonஉᓌک- మᥝ፡ ӻොဩ̶ ᘏٖ᮱ጱ - (void)observeValueForKeyPath ᬯލ,ᘒᬯӷӻොဩٖ᮱տԆۖ᧣አፊ didChangeValueForKey:@"age"] [super setAge:age] [self willChangeValueForKey:@"age"] ޾ [self ᛔMYPerson ғNSKVONotifying_MYPerson҅ࣁᬯӻᔄጱsetAgeොဩ᯾ᶎ҅᧣አ ኞදݒ෸҅ᔮᕹտᛔۖኞ౮Ӟӻᔄ҅ᖀಥݎ(ᦡpersonጱage؃)؀ᔄฎMYPerson)ጱં௔ ᦡฎperson੒᨝҅personጱ؃)- ֵአԧisa Ⴐٟҁisa-swizzling҂҅୮Ӟӻ੒᨝ ਫሿ̶ګ- kvoचԭruntime๢ KVOጱବ੶ਫሿҘ ୑ଉ҅౯ժݢզ໑ഝᵱᥝ᯿ٟਙժ̶ڊᬯԶොဩጱἕᦊਫሿ᮷ฎಲ ොဩ̶ አvalueForUndefinedKey:޾setValue:forUndefinedKey:᧣ڞ҅کɣইຎᬮဌತ ؀key,੪տັತፘݶݷᑍጱં௔key҅ইຎํ੪ፗളᩙ_کɢইຎဌํತ ؀ളᕳ౮ާં௔ᩙ ፗڞᕚጱ౮ާં௔҅ইຎํ҅ښɡইຎsetොဩӧਂࣁ҅੪տັತӨkeyፘݶݷᑍଚӬଃӥ ࣁፘଫkeyጱsetොဩ҅ইຎਂࣁ҅੪᧣አsetොဩਂވɠ༄ັฎ ୮Ӟӻ੒᨝᧣አsetValueොဩ෸҅ොဩٖ᮱տ؉զӥ඙֢ғ KVCጱବ੶ਫሿҘ ҁ7҂KVO-KVC ⼒controllercontroller被每 每每 1.每modelview经 2. ⼒SKD被经 3.经 4.key paths活经 5.最 1.strings每经 2.经 3.“IF”,经 4.每 ᒫ ᶭ46 ҁ8҂Block Block • 做 void test1() {     int a = 10;     void (^block)() = ^{         NSLog(@"a is %d", a);     };     a = 20;     block(); // 10 } void test2() {     __block int a = 10;     void (^block)() = ^{         NSLog(@"a is %d", a);     };     a = 20;     block(); // 20 } void test3() {     static int a = 10;     void (^block)() = ^{         NSLog(@"a is %d", a);     };     a = 20;     block(); // 20 } int a = 10; void test4() {     void (^block)() = ^{         NSLog(@"a is %d", a);     }; ᒫ ᶭ47 ᒫ ᶭ48 }     return 0;     }        test1(); __autoreleasepool;             /* @autoreleasepool */ { __AtAutoreleasePool { int main(int argc, const char * argv[]) } ((_block_impl *)block);     ((void (*)(__block_impl *))((__block_ipml *)block)->FuncPtr)     a = 20; *))__test1_block_func_0,&__test1_block_desc_0_DATA,a);     void (*block)() = (void (*)())&__test1_block_impl_0((void     int a = 10; { void test1() } ๶ԧ̶ڊդᎱॡᳩ҅ᘒӬဌ఺Ԏ҅౯੪ӧළ҅؀aጱܦ    NSLog(a);//ᬯ᯾੪ฎ಑     int a = __cself->a; { *__cself) static void __test1_block_func_0(struct __test1_block_imp_0 };     }     Desc = desc;     impl.FuncPtr = fp;     impl.Flags = flags;     impl.isa = &_NSConcreteStackBlock; Desc,int _a,int flag=0): a(_a){     __test1_block_impl_0(void *fp,struct __test1_block_desc_0*     int a;     struct __test1_block_desc_0* Desc;     struct __block_impl impl; struct __test1_block_impl_0 { .cpp • 每.mc++每 }     block();//20 a = 20;     static struct IMAGE_INFO { unsigned version; unsigned flag; } _OBJC_IMAGE_INFO = { 0, 2 }; • void test1()void (*block)() a10 . 
 • void (block)()void (block)() = &__test1_block_impl_0();block 每 
 • 10block__test1_block_impl_0a = 10经 
 • void test1()做(block)->FuncPtr)(block) test1_block_impl_0impl.FuncPtr = fp;fp void (*block)()test1_block_func_0 (block)->FuncPtr)(block) =⽼__test1_block_func_0(block); 
 • test1_block_func_0 int a = cself->a;blocka有a经10. 
 ===== • test2( );__block void test2() {     __attribute__((_blocks__(byref))) __Block_byref_a_0 a = {(void*)0,(__Block_byref_a_0 *)&a,0,sizeof(__Block_byref_a_0),10};     void(*block)() =  (void (*)())&__test2_block_impl_0((void *))__test2_block_func_0,&__test2_block_desc_0_DATA, (__Block_byref_a_0 *)&a,570425344);     (a.__forwarding->a) = 20;     ((void (*)(__block_impl *))((__block_ipml *)block)->FuncPtr) ((_block_impl *)block); } int main(int argc, const char * argv[]) {     /* @autoreleasepool */ { __AtAutoreleasePool __autoreleasepool;                test2();     } ᒫ ᶭ49 ᒫ ᶭ50 
 __weak typeof(self) weakSelf = self; 
 • block,block blockጱ஗ሾ୚አ ◦ blockcopystrong,block ◦ block,block • ARC ◦ copy, ◦ blockretain, ◦ block,block友 • MRC • ARCMRC,block,block blockጱٖਂᓕቘ };     <#statements#> ^(<#parameters#>) { <#returnType#>(^<#blockName#>)(<#parameterTypes#>) = inlineblock int(^block1)(int number); // ํ݇ํᬬࢧ int(^block1)(); // ෫݇ํᬬࢧ void(^block)(); // ෫݇෫ᬬࢧ blockጱਧԎ • 每 test4ablocka每 void(*block)()做&a,a每test2 • _OBJC_IMAGE_INFO = { 0, 2 }; static struct IMAGE_INFO { unsigned version; unsigned flag; } } return 0;     ᒫ ᶭ51 
 (nonatomic ,strong) void(^valueBlcok)(NSString *str); • ModalViewController.hblock @property [self presentViewController:modalVc animated:YES completion:nil]; }; str);,"@%ک NSLog(@"ViewController೭ modalVc.valueBlcok = ^(NSString *str){ init]; ModalViewController *modalVc = [[ModalViewController alloc] • touchesBegan: block,block • ؀᭗ᬦblock๶փ 每 self->block->self.property/self->_ivar每 • 每 ጱԍҘے᮷ᵱᥝײblockӾጱweak self҅ฎձ֜෸      weakSelf.data = responseData; [ downloadData:^(id responseData){    __weak typedof(self)weakSelf = self  ᥴ٬ොဩғ _dataં௔҅blockտcopy Ӟղself҂ self ೜ํ_handler, _handler ೜ํblock, block೜ํselfҁࢩԅֵአԧselfጱ    }]; _data = responseData;    [ downloadData:^(id responseData){     _handler = [httpRequestHandler sharedManager];   @property (nonatomic,strong)NSData  *data;    @property (nonatomic,strong)HttpRequestHandler * handler;    blockӾጱ஗ሾ୚አғӞӻviewController ᬦጱretain cycleֺৼ̶کൈᬿӞӻ֦᭬ 
 __strong typeof(self) strongSelf = weakSelf; 
 block,block • ᒫ ᶭ52 make,make.top.equalTo make.top,make.equalTo,make.with,make.offset,make.top • block make.top.equalTo(superview.mas_top).with.offset(padding.top); • masonry⽆ አֵ؀block֢ԅᬬࢧ }]; return result; result += 5; [mgr calculator:^(int result){ CalculatorManager *mgr = [[CalculatorManager alloc] init]; 
 • } self.result = block(self.result); { -(void)calculator:(int (^)(int))block • .m 
 • ,.h- (void)calculator:(int(^)(int result))block; block֢ԅӞӻ݇හֵአ ModalViewController • ModalViewController,label     }         }         _valueBlcok(@"123");         if (_valueBlcok) { አblock᧣:؀        // փ     { (UIEvent *)event     -(void)touchesBegan:(NSSet *)touches withEvent: 
 m. • ᒫ ᶭ53 
 block • block做,, 
  __weak typeof(self) weakSelf = self; 
 • block,__weak blockጱဳ఺ᅩ a • __block&a, *)__main_block_func_0,         &__main_block_desc_0_DATA, a));     void(*block)() = ((void (*)())&__main_block_impl_0((void (__Block_byref_a_0 *)&a, 570425344)); *)__main_block_func_0,         &__main_block_desc_0_DATA,     void(*block)() = ((void (*)())&__main_block_impl_0((void • clang -rewrite-objc main.m • Clangmain.mC++ • 有,block,, • block__blockstatic,, • block,有,, blockጱݒᰁփ᭓ mgr.add(1).add(2).add(3); • 
 } }; return self; _result += a; return ^(int a){ { -(CalculatorManager * (^)(int a))add • .m h- (CalculatorManager *(^)(int a))add;., • • ᒫ ᶭ54                            queue:[NSOperationQueue mainQueue]                            object:nil addObserverForName:@"someNotification" [[NSNotificationCenter defaultCenter] addOperationWithBlock:^{ self.someProperty = xyz; }]; [[NSOperationQueue mainQueue] layoutIfNeeded]; }]; [UIView animateWithDuration:duration animations:^{ [self.superview “”⼒block self 被 
“” block apiUIViewblockapi每 Ԟᘍᡤ୚አ஗ሾᳯ᷌Ҙވ ֵአᔮᕹጱ຤Զblock apiҁইUIViewጱblockᇇ๜ٟۖኮ෸҂҅ฎ • • • • ғ؟හஉڍblock᪙ forMode:NSRunLoopCommonModes]; [[NSRunLoop currentRunLoop] addTimer:timer }   weakSelf.secondsLabel.text = ...                                    callback:^() {                                     repeats:YES NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 ᬯ໏ғ؟ֵአ᩸๶ NSTimer੗ᤰ౮Blockᇇ: http://www.henishuo.com/nstimer-block/ ᥧ஑ᬯฎࣁᘍḵଫᘷᘏই֜ਖ਼NSTimerٟ౮Ӟӻ᭗አአጱBlockᇇ๜̶ ୮ᆐ҅ᒟᘏ̶؀ෛUILabelดᐏ҅ࢩԅ᮷ฎፗളᩙڬ੒ԭᬯ᯾໑๜ဌํ஠ᥝֵአblock๶ Ꮁ̶ ࢧ᧣᮷உො׎҅፜݄ԧٟդቘጱஉग़դ̵؀փ҅ٻblockጱঅ๋॒҅ፗളጱ੪ฎդᎱᔲک᧔ UILabelӤ҂ᑁᤒጱդᎱ̶ ӞӻֵአblockดᐏҁࣁڊֵአblockํՋԍঅ॒ҘֵአNSTimerٟ • block,__block 
strong typeof(self) strongSelf = weakSelf;__    ᒫ ᶭ55                                        completion:NULL]; [[self view] insertSubview:yellowViewController.view atIndex:0]; } animations:^{ [[blueViewController view] removeFromSuperview];                                       ptions:UIViewAnimationOptionTransitionFlipFromLeft                                       [UIView transitionWithView:self.view duration:0.2 (CPUBlock) • Block做如做 ӞӻֵአBlockಗᤈUIVewۖኮ?ڊ᧨᧨੒Block ጱቘᥴ?ଚٟ self –> _observer –> block –> self ดᆐᬯԞฎӞӻ஗ሾ୚አ̶ }];   [strongSelf dismissModalViewControllerAnimated:YES];   __typeof__(self) strongSelf = weakSelf; usingBlock:^(NSNotification *note) {                                                         queue:nil                                                              object:nil                                                             addObserverForName:@"testKey" _observer = [[NSNotificationCenter defaultCenter] __weak __typeof(self) weakSelf = self; });     [strongSelf doSomethingElse];     [strongSelf doSomething];     __typeof__(self) strongSelf = weakSelf; dispatch_group_async(_operationsGroup, _operationsQueue, ^{ __weak __typeof(self) weakSelf = self; 每GCD selfGCD apiGCD信NSNotificationCenter 
“”每                                                     }];                            self.someProperty = xyz; notification) { usingBlock:^(NSNotification *                            ᒫ ᶭ56 տᤩදݒ̶؀හӾጱڍᲫਁ्กጱੴ᮱ݒᰁ҅ݢզᤩblockಅදݒ҅ଚӬٌࣁܻىֵአᧆ __blockฎӞᐿᇙྛᔄࣳ҅ ղ̶ Ӟګblock ݇හ෸҅׎տᛔۖ॔ک्กӞӻblokc੒᨝҅ဳ఺੒᨝ં௔ᦡᗝԅcopy҅ള @property (nonatomic,copy) didFinishBlock finishBlock; ᆐݸ׎ݢአ ᬯ੪्กԧӞӻdidFinishBlockᔄࣳጱblock҅ typedef void(^didFinishBlock) (NSObject *ob); ֵአtyped्กblock • :cocoaTouch⽆Block ()每 信过美 • gotoblock • Objective-CC还block做每 block ਫሿܻቘ 
 block每 )A做M BlockMF1( A A()MA • BlockMA 
 每 AMBM F2AF1BF2CF3就 A信B信CAF1AB 做M3 funA();} funA(){funB();} funB(){…..}; 做main做A做A做B… • Blockmain(){ 
 每 • (block),做如做 Ջԍฎblock 
 • typedef void(^completion) (BOOL finished); 
 • typedef void(^animations) (void); ӤᶎդᎱጱBlockጱਧԎ̶ڊٟ ᒫ ᶭ57 forIndexPath:indexPath]; dequeueReusableCellWithIdentifier:@"TestCell"     HJTestCell *cell = [tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {       - (UITableViewCell *)tableView:(UITableView *)tableView @implementation HJTestViewController ᥴ᯽զӥդᎱጱٖਂအᄋܻࢩ dispatch_async(dispatch_get_main_queue(),^(void){finishBlock();}); queueblock每 finishBlock block dispatch_block_t block); dispatch_queue_t queue, void dispatch_async( dispatch_async GCD dispatch_async block GCDBlock 2). block protocol每 真; blockblock做 iOS—- Objective-Cid每 iOS 1). blockdelegate? 每 : blockblock ԭblockى     [cell setTouchBlock:^(HJTestCell *cell) {         [self refreshData];     }];          return cell; } [cell setTouchBlock:^(HJTestCell *cell) {     [self refreshData]; }]; ⽣ cellTouchBlock__strongselfBlocktouchBlock 友selfretaintouchBlocktouchBlock cellcelltableViewtableViewselfself touchBlocktouchBlockself objectretainCount0 ⽣ 
 weakSelftouchBlockself __weak __typeof__(self) weakSelf = self; [cell setTouchBlock:^(HJTestCell *cell) {     [weakSelf refreshData]; }]; ᒫ ᶭ58 ᒫ ᶭ59 (.swift) 每 每 Objective-C (.h) (.m) Swift 每 Xcode 
 • Swift 每 只每 活[[[ ]]]每Swift 做 if/else 每 
 • Swift SwiftྲObjective-CํՋԍս۠Ҙ 每SwiftGenerics⼒发被每 SwiftObjective-CObjective-C发 
每 被每SwiftObjective-C 信还信信如做Swift⼒ Objective-C信ARC信信信信 
• SwiftObjective-C SwiftC++Objective-C每 Swift@objc⼒被Objective-CSwift每 
Objective-C做每 Objective-CSwift每Swift Objective-CSwift每 
• SwiftObjective-C Objective-CSwift每 
每 Objective-C每SwiftObjective-C SwiftObjective-C每Swift 
每 每学个 每 每 
• SwiftObjective-C Swift޾Objective-Cጱᘶᔮ 每 SwiftSwift ҁ9҂Swift ᒫ ᶭ60 每 Optionals Objective-CnilSwift Objective-Cnil X每Optionals • Swift⼒Optionals被每 有每 • SwiftObjective-Ctuples⼒被 Ԉֺ᧔กSwift᯾ᶎํߺԶฎ Objective-CӾဌํጱҘ ⽆么 Objective-C 每 • Objective-C ⽇ Cocoa ҘހSwiftඪ೮ᶎݻᬦᑕᖫᑕ GC每每 GC, ARCGC • Swift ⼒Automatic Reference Counting, ARC被, Swiftጱٖਂᓕቘฎெ໏ጱҘ 每 ARC Swift C Cocoa ⽆ 信每 每 —— -- • : Swift SwiftC++, OC1.4. ⼀CSwift, 
 • Swift 最 每Swift Objective-C著⼒%s%d%@被只 Swift--每 
“+” 快每Swift Swift 每 Objective-C , 
 • Swift Objective-C 美bug能. . , . 给 Swiftnil, 
 Swift • ᒫ ᶭ61 ሿդᎱғ ᬯฎਫ̶قᦤԧහഝᔄࣳਞכ᯻አာࣳጱᦾ֦҅ݢզਖ਼ӤᶎӷӻොဩݳଚԅӞӻ҅ଚݶ෸ᬮ ᕮຎ̶ మᥝጱکᦜӞӻਁᒧԀ޾Ӟӻෆࣳහഝᬰᤈྲ᫾ݢᚆӧտ஑ر//ᑕଧݢᚆӧտૄმ҅֕ฎ -     areTheyEqual(1, "ray") 每最 -    areTheyEqual(1, 1) // true -    areTheyEqual("ray", "ray") // true -    } -      return x == y -    func areTheyEqual(x: NSObject, _ y: NSObject) -> Bool { -    import Foundation Objective-CNSObject areIntEqual(1, 1) // true areStringsEqual("ray", "ray") // true }   return x == y func areStringsEqual(x: String, _ y: String) -> Bool { }   return x == y func areIntEqual(x: Int, _ y: Int) -> Bool { “” 
每 • 发每 信每 • 发每Swift发做 Ջԍฎာࣳ҅ਙժ݈ᥴ٬ԧՋԍᳯ᷌Ҙ nil“” option经“” • “”“”“” ӻᳯݩҘےԅՋԍᥝࣁݒᰁᔄࣳݸᶎ 有每 StringSwiftInt • SwiftOptionals每Swift Ҙހ᧍᥺قSwift ฎӞᳪਞ ᒫ ᶭ62 ⼼被 觉willAnimateRotationToInterfaceOrientation⼼⼒ 觉shouldAutorotateToInterfaceOrientation⼼ 觉didReceiveMemoryWarning 觉viewDidDisappear信是 觉viewWillDisappear信是 觉viewDidAppear 觉viewWillAppear () 觉viewDidUnload 觉initWithNibName: bundle:nib就觉loadView觉viewDidLoad nib每 viewDidLoad:loadView 每 loadView; .nib每 viewDidDisappear:样是每 viewWillDisappear:样是每 viewDidAppear:成 viewWillAppear:每 ֢አҘ viewDidLoad,viewWillDisappear, viewWillAppearොဩጱ ᶲଧ޾ viewcontrollerጱӞԶොဩጱ᧔ก ҁ10҂UI -    areTheyEqual(1, 1) -    areTheyEqual("ray", "ray") -    } -      return x == y func areTheyEqual(x: T, _ y: T) -> Bool {    - ᒫ ᶭ63 ӥ:٭ဌํstoryboardఘ * ดᐏᑻݗ ୌ޾ᦡᗝUIWindowጱrootViewControllerڠ * ୌUIWindowڠ * (storyboard ᫹Main.storyboard(ํے,3.໑ഝInfo.plist឴஑Main.storyboardጱ෈կݷ ୌUIApplicationጱdelegate੒᨝ڠ * ୌUIApplication੒᨝ڠ * 2.UIApplicationMain හڍ1.main ӥ:٭ํstoryboardఘ ԅӷᔄ:1.ํstoryboard 2.ဌํstoryboardړۖސ    ᑕଧ ᬦᑕ,՗main෈կ୏ত᧔᩸ۖސ᧔ӞӥAPPጱܔᓌ ጱ੗ᤰ᩸๶݄ڊ- ᓌᘒ᥺ԏ, ᛔ૩ጱԪఘᛔ૩؉, ಩ӧᵱᥝูᶂ - ٚളතཛྷࣳහഝ໑ഝཛྷࣳහഝᦡᗝৼഴկහഝ޾֖ᗝ ಅᵱৼഴկےႲض - ᧨Ӟ᧨֦ฎெԍ੗ᤰviewጱ 每 有每 • 每有 Ջԍฎkey windowҘ 3信dealloc initviewDidLoad 2信viewDidDisappear 1信viewWillDisappear 6信viewDidAppear 5信viewWillAppear 4信viewDidLoad 3信loadView nib 每xib 2信init (initWithNibName) 1信 alloc ᒫ ᶭ64 
 contentsize每 constraintcontentsize每viewDidAppear ◦ autolayoutsubviewconstraint 
 ◦ autolayoutcontentsize • 
 是每 viewdidloadcontentsize每 subviewconstraintscrollviewcontentsize每 • viewDidLoadautolayoutviewDidAppear ᦡᗝscroll viewጱcontensizeᚆࣁViewdidload᯾ᦡᗝԍ,ԅՋԍ 
 • UITableViewUITableView > UIScrollView > UIView > UIResponder > NSObject 
 • UIButtonUIButton > UIControl > UIView > UIResponder > NSObject 
 • UIButtonӨUITableViewጱ੶ᕆᕮ຅ javajava每 cell每 UITableView iOSios ெԍᥴ٬ᖨਂ࿰ჿጱᳯ᷌(cell) * ดᐏᑻݗ ୌ޾ᦡᗝUIWindowጱrootViewControllerڠ * ୌUIWindowڠ* ࣁapplication:didFinishLaunchingWithOptions:Ӿ application:didFinishLaunchingWithOptions:ොဩ ੪տ᧣አդቘጱ ,ײਠླጱ෸ۖސ* ᑕଧ ᔮᕹԪկ(ဌํstoryboard)(ލ3.delegate੒᨝୏ত॒ቘ(ፊ ୌUIApplicationጱdelegate੒᨝ڠ * ୌUIApplication੒᨝ڠ * 2.UIApplicationMain හڍmain.1 ᒫ ᶭ65 NextViewController *nextVC = [[NextViewController alloc] init]; //Aᶭᶎ.m෈կ @property (nonatomic, copy)NSString *paramString; //Aᶭᶎ.h෈կ paramString̶ ত۸ڡײғAᶭᶎᦡᗝં௔ NSString *paramString҅ࣁ᪡᫨Bᶭᶎጱ෸؀ં௔փ ጱᳯ᷌?؀ԭᶭᶎᳵփى 
 • boundsview⼒被 被 • frameviewview⼒ bounds?) frame޾boundsํՋԍӧݶҘ(Difference between frame and ;,每 每,modelview;⼼ •()UIViewController:, 
 每 • UIViewCALayer,UIViewCALayer,CALayerUIView 
 UIView,每 • CAlayer:QuartzCore.framework,, 
 ◦ UIViewController,⼼ 
 ◦ 有view 
 ◦ ,app : UIWindow,UIWindow,每UIWindow • UIWindow:UIKit.framework⽆,著UIView, 
 , • UIView: UIkit.framework⽆,道,道, ᓌᬿ֦੒UIView̵UIWindow޾CALayerጱቘᥴ ᒫ ᶭ66 _Nullable)context (NSKeyValueObservingOptions)options context:(void * (NSString * _Nonnull)keyPath options: - (void)addObserver:(NSObject * _Nonnull)anObserver forKeyPath: ғࣁAᶭᶎᦡᗝBᶭᶎጱݒᰁsecond҅ଚӬ੒ᬯӻݒᰁᬰᤈᥡ੊؀ kvoփ     };         self.nameLabel.text = str; second.block = ^(NSString *str){ [self presentViewController:second animated:YES completion:nil]; හڍblock ੪տࢧ᧣ᬯӻײᬯ໏ࣁBᶭᶎ᪡᫨ጱ෸҅؀੒BᶭᶎጱblockᩙײBᶭᶎጱ෸ک//Aᶭᶎ᪡᫨ [self dismissViewControllerAnimated:YES completion:nil]; self.block(self.nameTextField.text); Aᶭᶎ᧣አᬯӻblockک//Bᶭᶎ᪡᫨ @property (nonatomic, copy) ablock block; typedef void (^ablock)(NSString *str); BᶭᶎਧԎblock҅ଚᦡᗝblockᔄࣳጱݒᰁ// ̶؀੒BᶭᶎጱblockᩙײBᶭᶎጱ෸کࣁAᶭᶎ᪡᫨ አᬯӻblock̶᧣ײғࣁBᶭᶎਧԎӞӻblockᔄࣳጱݒᰁ҅ࣁBᶭᶎ᪡᫨Aጱ෸؀blockփ [[NSNotificationCenter defaultCenter] removeObserver:self]; ᑏᴻᥡ੊ᘏײ//᭗Ꭳӧֵአጱ෸ }     self.nameLabel.text = [nameDictionary objectForKey:@"name"];     NSDictionary *nameDictionary = [notification userInfo]; -(void)ChangeNameNotification:(NSNotification*)notification{ ጱ॒ቘොဩײ᭗Ꭳ෸ک//ᥡ੊ } name:@"ChangeNameNotification" object:nil]; selector:@selector(ChangeNameNotification:) [[NSNotificationCenter defaultCenter] addObserver:self //Aᶭᶎဳٙᥡ੊ᘏ [self dismissViewControllerAnimated:YES completion:nil]; userInfo:@{@"name":self.nameTextField.text}]; postNotificationName:@"ChangeNameNotification" object:self [[NSNotificationCenter defaultCenter] ᭆ᭗Ꭳݎ//Bᶭᶎ ᴻᥡ੊ᘏ̶ ᑏײᭆ᭗Ꭳ҅ࣁAᶭᶎဳٙᥡ੊ᘏଚӬࣁӧአጱ෸ݎғࣁBᶭᶎӾ؀᭗Ꭳnotificationփ ᦓܐdelegate ғࣁBᶭᶎਧԎdelegate҅ଚӬᦡᗝdelegateં௔҅ࣁAᶭᶎਫሿ؀঩ಓdelegateփ [self presentViewController:nextVC animated:YES completion:nil]; nextVC.paramString = @"݇හփᨶ"; ᒫ ᶭ67 
 . 有每touch每 • 每每友 ߥଫᘏ᱾๵? (What is responder chain?) 
 
• image image image image image image image image image image image image • • viewWill/DidLayoutSubviews经 • viewWillDisappear经做经被经 • viewDidAppear • viewWillAppear经做经 • viewDidLoad经经 经 • 要loadViewstoryboard ԭᥤࢶጱኞ޸ޮ๗ጱᳯ᷌ى ?ݱᛔսᅩ ?ڦ܄ ?ӥֵአ٭ࣁՋԍఘڦړ੒ԭ᭗Ꭳդቘᶎᦶଉᳯ, դቘ޾᭗Ꭳ ਂכੴጱොୗقғ᭗ᬦ؀ֺཛྷୗփܔ کލ//ࣁBᶭᶎ੒userNameᬰᤈᦡᗝ҅ࣁAᶭᶎ᮷ݢզᳵ (id)object change:(NSDictionary *)change context:(void *)context -(void)observeValueForKeyPath:(NSString *)keyPath ofObject: //ਫሿᬯӻᥡ੊੒᨝ጱොဩ completion:nil]; [self presentViewController:self.second animated:YES options:NSKeyValueObservingOptionNew context:nil]; [self.second addObserver:self forKeyPath:@"userName" initWithNibName:@"SecondViewController" bundle:nil]; self.second = [[SecondViewController alloc] ইӥդᎱےBᥤࢶጱࣈොႲک//ࣁAᥤࢶ᪡᫨ property (nonatomic, strong) SecondViewController *second;@ ̶کࣁBᶭᶎ੒ݒᰁkeyPathᬰᤈᦡᗝ҅ࣁAᶭᶎ᮷տᥡ੊ጱ (void *)contextොဩ̶ (id)object change:(NSDictionary *)change context: - (void)observeValueForKeyPath:(NSString *)keyPath ofObject: ଚࣁAᶭᶎਫሿ ᒫ ᶭ68 
 release每 retainview release,retainIBOutlet viewrelease,IBOutlet viewcontrollerviewviewDidUnload • view, viewmemory warning notification, • loadViewcontrollerviewnil每 • viewDidLoadviewnib ଫᧆ؉Ջԍૡ֢Ҙ හ᯾ᶎڍӻپᬯײአጱҘࣁᛔਧԎViewControllerጱ෸᧣ײࣁՋԍ෸ ฎڦړViewControllerጱloadView,viewDidLoad,viewDidUnload ᧆԪկ ଳ୒ڞ॒ቘጱᦾ੪ਖ਼Ԫկփ᭓UIApplication๋҅ݸইຎᬳApplicationԞӧᚆ॒ቘ҅ փ᭓ᕳWindow(UIWindow)҅ྌ෸Windowӧᚆڞ- ইຎViewControllerԞӧᚆ॒ቘ҅ ViewController҅ տਖ਼Ԫկփ᭓ᕳਙժጱڞইຎᶮ੶ጱViewᬮฎӧᚆ॒ቘᬯӻԪկጱᦾ҅ ᖀᖅஃӤփ᭓҅஗ሾᬯӻᬦᑕ̶ڞ- i n i t i a l v i e w ጱᆿView឴ݐԪկݸইຎՖӧᚆ॒ቘ҅ ጱᆿViewᬰᤈփ᭓̶ Ԫկտஃਙڞ- ളතԪկጱinitial viewইຎӧᚆ॒ቘᧆԪկଚӬ঄ӧฎᶮ੶ጱView҅ imageimageimageimageimageimageimageimageimageimageimageimageimage (Responsder Object)每 view(Responder Chain)有 • 有 . ViewViewController ◦ 每 ◦ UIResponder UIView信UIViewController每 ⼒被每View UIResponderUIKIT每 ◦ • ᒫ ᶭ69 • ݢ?ܨই֜ਫሿ,᧔᧔௏᪠ ࣁӞӻtableViewӾᵱᥝᛔਧԎग़ᐿ໏ୗጱcell(ӷᐿ౲ӣᐿ),᭗ଉ֦ 
 每 ◦ Cellcell三 reusableTableCells每Cell . visiableCells,cell1 reusableTableCells;cell2 visiableCells,cell2 dequeueReusableCellWithIdentifier:CellIdentifier],cell1每 cell1 cell, cellForRowAtIndexPath,[tableView ◦ tableView,reusableTableCells,, reusableTableCells每 )每cell11visiableCells,cell1visiableCells,cell1 ◦ tableView,cell1,cell11(alloc, visiableCells,reusableTableCells每 cell)每10cell reuseIdentifier:CellIdentifier]10cell,cell(, ◦ [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault • TableView: 每 :100,iPhone10cell每 reuseIdentifier:CellIdentifier] ,cellForRowAtIndexPathcell • cell [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault [tableView dequeueReusableCellWithIdentifier:CellIdentifier]nil每 
• TableView,reusableTableCells, • visiableCellscells,reusableTableCellscells每 reusableTableCells每 • UITableView,NSMutableArray visiableCells,NSMutableArray ሿ௏᪠?) cell), ই֜ᕟᕢݱӻtableViewጱdelegate޾dataSource?᧗᧔᧔ਫ tableView,tableViewᥝ࿢ӧݶጱහഝრզ݊ӧݶጱ໏ୗ (ᥝ࿢ᛔਧԎ ౲ᘏই֜ࣁӞӻviewӤดᐏग़ӻ)?ګUITableViewጱ᯿አ๢ ᒫ ᶭ70 
 每被 每⼒ 每UIImage ◦ 每 每 ◦ 每drawRect:rect 每 layer信每 contentView.layeraddSublayer:每layer -CALayerlayercell 
 UITableViewCellSelectionStyleNone每 每cellselectionStyle cell为 
lineBreakMode:UILineBreakModeTailTruncation]; } drawAtPoint:imagePoint]; } [text drawInRect:textRect withFont:font (image) { [image drawAtPoint:imagePoint]; self.image = nil; } else { [placeHolder UITableViewCelldrawRect- (void)drawRect:(CGRect)rect { if ◦ cellcell每 每 contentView能 ◦ 每CelltextLabel信detailTextLabelimageViewview 每 insertRowsAtIndexPaths:withRowAnimation:reloadData ◦ cell每 每cellsetNeedsDisplayInRect:setNeedsDisplay 每cell ◦ cell每UITableViewUITableViewCell opaqueYES⼒被每 ◦ 每每cell • tableView: cell每 • ᥴ٬Ҙ ጱఽᥧฎԅՋԍҘெԍܜᐿํײUITableViewጱ௔ᚆս۸? ჶۖጱ෸ ᒫ ᶭ71 
 ◦ ◦ ◦ , ◦ 要 • tableView: ◦ , , 开每 ◦ , , 要 , ◦ ⽇, tableView, willDisplayCell要 • tableView: ӥ೉޾Ӥ೉ጱܻቘ? UICollectionView ,UITableViewCell,initWithFrame, tableviewጱcell᯾ই્֜ॺcollection viewҘ 每 ◦ gzip/zipgzip/zip /⼀每 /⼀每: 每: ⼦每: 每 ◦ ◦ heightforrowatindexpath 2每 5每 ◦ 2每 ◦ 做每 每每 每tableview ◦ ᒫ ᶭ72 每native ◦ 每每 webview事的每 nservern时 每App每Appn 著 webview每 • 每每 webview每App每 • webviewApp 中每 iOSweb native app每 • 每webiOS每web 
 ◦ ◦ • webviewnative code iOS AppHTML5每 nativeHTML5 •HTML5web每web app每 • native code每 code每 • webviewApp经native •iOSwebviewnative code每 ᧨᧨webView 
 • , • tableView.rowHeight = UITableViewAutomaticDimension • tableView.estimatedRowHeight = 200 • , , 1., 2. ই֜ਫሿcellጱۖாጱᤈṛҘ ᒫ ᶭ73 • uiview • viewframe • ⼼ • uiscrollview • init layoutSubview֜෸᧣አ? viewdidload • viewdidloadviewviewdidloadnib 每 .nibviewawakefromnib awakefromnib做 awakefromnib.nibawakefromnib.nib • ڦ܄awakeFromNibӨviewdidload 
 floatValue];webViewDidFinishLoad每 stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] [[self.webView ◦ cell活webviewocjsweb CGFloat height = 每 每中webview 200pixely-200每webview webview⽆⼒iScroll被每webview ◦ webviewnativeview每每 AppURL每 shouldload⼿天每webviewURL 每webviewwebview delegate 每webviewnative code webviewwebviewApp最 ◦ OKwebview4 
 每出每 ◦ 每HTMLwebtext 每 每native code 给每webviewhold ◦ 每 每 每太 webview每 ᒫ ᶭ74 • imageWithData ᫹ොୗےᐿپUIImageํߺ • 3: item,. ),/, • 2: itemsize(,uicollectionviewcontent sizeitemize ,scrollviewcontentoffset>bounds) • 1: ,shouldInvalidateLayoutForBoundsChange(bounds layoutAttributesForCellWithIndexPath),你 • ,attributes( • prepareLayout • layoutAttributesForElementsInRect(itemframe) • FlowLayout • UICollectionView ই֜ਫሿᅀ૲ၞ,ၞ࿜૲ੴ • contentinset frame • contentoffset frame • contentsize ⾃ UIScrollView • CALayer,, • UIVIew,(UIResponder),CALayer • nCALayerlayerUIView每 CALayer每UIViewCALayer每UIView 每CoreAnimation每 UIViewiOS⼦ 
UIView⼒event被UIViewUIWindow. • UIwindowUIViewUIWindow 经 UIViewUIViewControllerUIResponder • ?ڦ܄UIWindow޾UIView޾ CALayer ጱᘶᔮ޾ viewviewdidunload • viewviewWillUnload • didreceivememorywaring ֢ฎՋԍ አ ἕᦊ඙᧣ײviewcontrollerጱdidreceivememorywaringࣁՋԍ෸ ᒫ ᶭ75 ◦ • +(void)initialize; ◦ load , ◦ load , ◦ , runtime load void)load;)+ • ڦ܄load initializeොဩጱ 每 • -(void)applicationWillTerminate:(UIApplication *)application 每 • -(void)applicationWillEnterForeground:(UIApplication *)application 每做 • -(void)applicationDidEnterBackground:(UIApplication *)application • -(void)applicationDidBecomeActive:(UIApplication *)application • -(void)applicationWillResignActive:(UIApplication *)application (NSDictionary )launchOptions • -(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions: (NSDictionary )launchOptions • -(BOOL)application:(UIApplication )application willFinishLaunchingWithOptions: ଫአጱኞ޸ޮ๗ • ImageViewScrollViewImageView • ScrollView多ImageView • ScrollViewImageViewImageView ਫሿࢶᇆ᫪ඎࢶ • CGFloat viewY = (index / col ) * (viewH + 10); • CGFloat viewX = (index % col ) * (viewW + margin); • CGFloat margin = (self.shopsView.frame.size.width - col*viewW) / (col - 1);// • NSInteger index = self.shopsView.subviews.count;// • NSInteger col = x;// ൈᬿԜ਴໒ᓒဩ • imageWithContentOfFile Bundle imageWithName • ᒫ ᶭ76 ,说,, 说.说, • ,layer., ጱᇫாҘضܻکԅՋԍ୮ Core Animation ਠ౮෸҅layer ݈տ௩॔ [tableView endUpdates]; [tableView beginUpdates]; ᚆۑ// ᯿ᅩฎᬯ2ݙդᎱਫሿጱ [tableView deselectRowAtIndexPath:indexPath animated:TRUE]; ሿҘޝ୮TableViewጱCellදݒ෸҅ই֜ᦏᬯԶදݒզۖኮጱ୵ୗ imgData = UIImageJPEGRepresentation(image, 0.6f) ই֜಩Ӟୟय़ࢶᖽੜԅ1/4य़ੜጱᖽኼࢶҘ 成每, • CALayer. ኞ̿ᵌୗۖኮ̀ҘݎտײՋԍ෸ completion:ฎਧ෸࢏ᕮ๳զݸጱӞӻࢧ᧣block ୌਧ෸࢏ᵱᥝਫሿጱSELڠanimations:ᬯฎ ୌӞӻਧ෸࢏ڠanimateWithDuration:ᬯ੪ᒵԭ ༷ฎই֜ਫሿጱҘ +[UIView animateWithDuration:animations:completion:] ٖ᮱य़ (UIGestureRecognizer )otherGestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer: • (BOOL)gestureRecognizer:(UIGestureRecognizer )gestureRecognizer // UIScrollViewUIGestureRecognizerDelegate,, • , 
 bounds,UIScrollView • UIScrollViewframecontentSize,bounds, UIScrollView य़༷ฎই֜ਫሿጱ҅ਙฎই֜ഔ഍̵ߥଫಋ۠ጱҘ ᒫ ᶭ77 • ⽆ • UIWebView • UIImageView UIImageView ই֜ඎන GIF ࢶᇆ҅ํՋԍս۸ොໜԍҘ 
} [path stroke]; ๶҂ڊดᐏܨࢶ੶Ӥҁکጱࢺୢ჉ວګ //ਖ਼ᕲ clockwise:YES]; radius:radius - 5 startAngle:startAngle endAngle:endAngle bezierPathWithArcCenter:center UIBezierPath *path = [UIBezierPath ࢺୢګ//ֵአUIBezierPathᔄᕲ CGFloat endAngle = - M_PI_2 + 2 * M_PI * self.progress; //ᦡᗝࢺୢጱᕣྊ᥯ଶ CGFloat startAngle = - M_PI_2; ҂ګ//ᦡᗝࢺୢጱ୏তጱ᥯ଶҁୢଶ CGPoint center = CGPointMake(radius, radius); //ᦡᗝࢺୢጱࢺஞ CGFloat radius = rect.size.width * 0.5; //ᦡᗝࢺୢጱ܎ஆ { -(void)drawRect:(CGRect)rect -(void)drawRect:(CGRect)rectҁ໐ஞ҂ 3. 
} [self setNeedsDisplay]; //୮ӥ᫹ᬰଶදݒ෸҅ಋۖ᧣አ᯿ᕲොဩ _progress = progress; { -(void)setProgress:(CGFloat)progress ੪տ᧣አਙጱsetter҅؀//ྯེදݒ౮ާં௔progressጱ 2. progresssetter property (nonatomic, assign) CGFloat progress;@ ؀Ӟӻ౮ާં௔҅ളතӥ᫹ᬰଶ׀//൉ 1. UIView ᦡᦇӞӻᬰଶ๵̶ ᒫ ᶭ78 storyboard҅੕ᛘय़ᰁ٫ᑱ҅ᥴ٬᩸๶ፘ୮ࢯᵙ̶ දӞӻץ෸҅य़ਹտݶ෸ݎӧݶดᐏٖ਻෸҅ྲ᫾ࢯᵙ̶୮ग़Ոࢫᴚ౲ᘏग़ࢫᴚ୏ګ ੒ԭ॔๥᭦ᬋഴ̶ݎᕅ๳տ᭜౮य़ᰁጱ٫ᑱ҅੦ٌฎग़ࢫᴚ୏ےᕅ๳҅౲ᘏႲےᚆᥝ᯿ෛႲ දstoryboardӤ੒ଫጱኴᶎጱᕅ๳҅ӨXIBӞ໏ݢץ- Storyboardғᵱ࿢ݒۖ෸҅ᵱᥝ ᛘ٫ᑱ҅ᘒӬᥴ٬٫ᑱፘ੒ᥝࢯᵙஉग̶़ ຄฃ੕҅ۖݎ෸҅ইຎXIB෈կᤩݎ෸ֵ҅አXIBฎྲ᫾ࢯᵙጱ̶୮ग़Ոࢫᴚ౲ᘏग़ࢫᴚ୏ ӧݶᇫாӥดᐏӧݶٖ਻ګፘྲᕍդᎱᛔᆐᥝౌӞԶ̶੒ԭྲ᫾॔๥᭦ᬋഴفᳩ̶XIB᫹ ๗ݒޮݎᕅ๳҅੕ᛘ୏ےኜᛗᵱᥝ᯿ෛႲײදXIBஉय़҅ํ෸ץ- XIBғᵱ࿢ݒۖ෸҅ᵱᥝ ෆӻAppጱᕮ຅̶ڊݢզፗᥡࣈ፡ ᘒӬӞӻstoryboardݢզํஉग़ጱኴᶎ҅ྯӻኴᶎ੒ଫӞӻᔄ෈կ҅᭗ᬦstorybard҅ ෸ྲ᫾ፗᥡ҅ݎᕅ๳҅ࣁ୏ےԧݢᥤ۸ኴᶎ҅ݢ೒ഴկ҅ݢ׀൉ڹ- Storyboardғࣁᖫᦲ ᔄ̶ ୌഴկጱդᎱ҅Ꮯਫᓌ۸ӧ੝҅᭗ଉྯӻXIB੒ଫӞӻڠፗᥡӞԶ҅ᘒӬᔄ෈կӾ੪੝ԧ ᕅ๳҅ๅےԧݢᥤ۸ኴᶎ҅ݢզፗള೒ഴկ҅ԞݢզፗളᕳഴկႲ׀੪൉ڹ- XIBғࣁᖫᦲ XIBӨStoryboardsጱսᗌᅩ? • 每XcodeShow Slicing • images.xcassets了XcodeAsset Catalogslicedice这 • UIImage • UIImage这 • UIImageView这 Ջԍဳ఺ԪᶱҘ ᐿොୗݢզ੒ࢶᇆᬰᤈᖽනֵ҅አ CoreGraphics ᖽන෸ํپํߺ 
 每 UIWebView UIWebView每 • UIWebView⾃UIWebView⾃ imageWithContentsOfFile:每 每 ⼒被imageNamed 每 UIImageView也 • ᒫ ᶭ79 ᘍᒼໜғB݇ ̶ۓձܔኞኞӞེጱᓌݎD Blockғᭇአԭࢧ᧣ݝ ੒᨝॒ቘݶӞӻԪկ෸̶      ىC NSNotificationғ୮ᵱᥝग़ӻ੒᨝౲ӷӻ෫ ᭆၾ௳̶      ݎᦓਧԎጱොဩ๶ܐ஠ᶳׁᩢԭ຤ӻ ګग़ӻԪկ҅ଚᥝ࿢ݶӞӻ੒᨝๶॒ቘಅํԪկ෸̶঩ಓ๢کB delegateғ୮຤ӻ੒᨝ත ࢶ̶       ࢏Өٌӥጱ຤ӻᥤګᔮ෸҅ইᥤࢶഴىA target-actionғ୮ӷӻ੒᨝ԏᳵํྲ᫾ᔲੂጱ ጱቘᥴӧྋᏟጱฎګࢧ᧣๢ڜӥ փ᭓ᕳӤӞӻߥଫᘏ,ള፳੪տ᧣አӤӞӻߥଫᘏጱtouchesොဩ ୮᧣አtouchesොဩ,ਙጱἕᦊ؉ဩ, ੪տਖ਼Ԫկᶲ፳ߥଫᘏ᱾๵ஃӤփ᭓҅ ဩ๶؉ٍ֛ጱԪఘ. ݸ੪տ᧣አᥤࢶഴկጱtouchesොکԆᑻݗտ᧣አhitTestොဩ੔ತ๋ᭇݳጱᥤࢶഴկ,ತ Ԇᑻݗ. ᭆԪկᕳଫአᑕଧጱݎضᶎጱԪկ,ਖ਼ਙփ᭓ᕳڹ๋ڊӾݐڜUIApplicationտ՗Ԫկᴚ Ӿ,ڜӞӻኧUIApplicationᓕቘጱԪկᴚکفےࣁԾኞӞӻԪկ෸,ᔮᕹտਖ਼ᧆԪկ Ԫկփ᭓Өߥଫጱਠෆᬦᑕ? ᫹ਠླ.ےinfo.plist෈կ,ইຎဌํ,ᮎԍଫአᑕଧ ᫹ےstoryboard file base name᯾ᶎํဌํ೰ਧstoryboard෈կ,ইຎํ੪݄ ෙӞӥinfo.plist෈կ୮ӾํဌํMainڣ.᫹ᯈᗝ෈կے.᫹info.plistے.5 .ڊᦤଫአᑕଧӧᭅכ.ӞӻԆᬩᤈ஗ሾސ4.୏   UIApplicationጱᒫࢥӻ݇හԅUIApplicationጱդቘ. ԅUIApplication.   UIApplicationጱᒫӣӻ݇හ੪ฎUIApplicationጱݷᑍ,ইຎ೰ਧԅnil,ਙտἕᦊ ୌUIApplication੒᨝,ଚᦡᗝUIApplicationMain੒᨝ጱդቘ.ڠ.3 හ.ڍ2.ಗᤈUIApplicationMain 1.ಗᤈMain ၞᑕҘۖސଫአᑕଧጱ ୌӞӻᑮᥤࢶᬬࢧ̶ڠࣁ҅੪տ ࢏ጱViewҔইຎstoryboardӧਂګ᫹ഴےইຎstoryboardਂࣁ੪տೲᆙstoryboard ࣁҔਂވෙstoryboardฎڣ࢏ጱloadViewොဩဌํਫሿ੪տګইຎഴ ᫹ᛔਧԎጱViewҔےೲᆙloadViewොဩ ࢏ጱloadViewොဩਫሿԧ҅੪տګአloadViewᬯӻොဩҔইຎഴ᧣ضইຎӧਂࣁ҅੪տ ૪ᕪਂࣁጱViewҔ ࣁ҅ইຎਂࣁ੪ፗളᬬࢧਂވ࢏ጱViewฎګෙഴڣض࢏ጱViewં௔෸տګ୮ᑕଧᦢᳯԧഴ ᫹ᬦᑕҘے࢏Viewጱګഴ ᒫ ᶭ80 }   [self.image drawInRect:bounds]; addClip];   [[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:8.0]   CGRect bounds = self.bounds; - (void)drawRect:(CGRect)rect { • UIBezierPath得 !⼒被 on-screen-rendering没->debug->Color Off-screen-rendering hyb_imageWithCornerRadius:4]; imgView.image = [[UIImage imageNamed:@"test"] }   return image;   UIGraphicsEndImageContext();   UIImage *image = UIGraphicsGetImageFromCurrentImageContext();   [self drawInRect:rect];   CGContextClip(UIGraphicsGetCurrentContext()); cornerRadius:radius].CGPath);                    [UIBezierPath bezierPathWithRoundedRect:rect   CGContextAddPath(UIGraphicsGetCurrentContext(), UIScreen.mainScreen.scale);   UIGraphicsBeginImageContextWithOptions(self.size, NO,   CGRect rect = (CGRect){0.f, 0.f, self.size}; - (UIImage *)hyb_imageWithCornerRadius:(CGFloat)radius { • UIImage还API 能每 GPUUIFPS⼒被 • GPUCPUCPU 每 CPU信GPU信每CPUGPUGPU 每每 • 每⼒off-screen-rendering被能 imgView.clipsToBounds = YES; // ᬯӞᤈդᎱฎஉၾᘙ௔ᚆጱ imgView.layer.cornerRadius = 10; • ࢺ᥯ےᕳUIImageViewႲ ᒫ ᶭ81 ଫ̶ ဳ఺ғviewWillLayoutSubviewsݝᚆአࣁViewController᯾ᶎ҅ࣁview᯾ᶎဌํߥ ഘጱളݗԧ̶ڔහ੪Ꭳ᭲ཞᒉ੽ڍ᭗ᬦӤᬿӞӻ else {          // ཞ੽     } }   {           // ᒉ੽ } ==                 UIDeviceOrientationPortraitUpsideDown) if (orientation == UIDeviceOrientationPortrait ||orientation (UIDeviceOrientation)orientation {         -(void)_shouldRotateToOrientation: } [UIApplication sharedApplication].statusBarOrientation];  [self _shouldRotateToOrientation:(UIDeviceOrientation) - (void)viewWillLayoutSubviews  {       viewDidLayoutSubviews̶ හٌ҅Ӿ viewWillLayoutSubviews ޾ڍᔮᕹտߥଫӞԶ҅ײഘጱ෸ڔཞᒉ੽ ᘏํ๢տ݄᯿ෛlayoutᛔ૩ጱݱӻsubview̶ݎ୏҅ײጱ෸ݎcontroller layout᥶ viewWillLayoutSubView֦௛ฎᎣ᭲ጱ̶ 每 CPU每UIButton 经每 touch知setNeddsDisplay • drawRectCore Graphics⽆ ֵአdrawRectํՋԍ୽ߥҘ ᭭ܲັತ̶ײහᕟӾ҅ࣁᵱᥝጱ෸کفೲᰵ෸ਖ਼ೲᰵਂ ୌڠᮎԍݢզ᭗ᬦࣁ҅؀දץ຤ӻೲᰵݸ҅ಅํӨԏݶᔄࣳጱೲᰵ᮷ᥝڋ•    ᒫԫᐿғᅩ ݢ̶ܨදץ֜ೲᰵ҅ፗളࣁࢧ᧣෸҅੪૪ᕪਖ਼ളතߥଫጱೲᰵᕳփᬦ๶ԧ҅ፗള᭗ᬦਙ ද҅ᮎԍӧአ୚አձץਙӧአٌ҅؀ෛਙጱڬ຤ӻೲᰵݸ҅಍տڋ•    ᒫӞᐿғইຎฎᅩ ᬯӻᳯ᷌ํஉग़ᐿොୗ҅ᘒӬӧݶጱֵአ࣋วԞӧӞ໏ጱ̶ྲই᧔ғ ؀දButtonጱץᥝጱbutton๶ ᛔ૩మکဩ๶ತېୌ҂҅ᴻአviewጱtagԏक़҅ᬮݢզ᯻አՋԍڠሾ ԧnӻbuttonҁݢᚆֵአ஗ےত۸ਠླ҅viewӤᶎႲڡӞӻview૪ᕪ mask家⽤ • ᒫ ᶭ82 每 iPhone OS ⼦ Cocoa Touch ⽆ Mac cocoa touch໛ຝ cellForRowAtIndexPath:(NSIndexPath *)indexPath; - (UITableViewCell *)tableView:(UITableView *)tableView *)tableView numberOfRowsInSection:(NSInteger)section; UITableVIewጱData Sourceොဩํ- (NSInteger)tableView:(UITableView UITableViewController̶ ӥᧆ੒᨝ฎ٭talbeviewጱdelegateጱ੒᨝҅ฎᤩᭇᯈ࢏҅Ӟᛱఘ ᦓ҅ଚਖ਼ᛔ᫝ᦡᗝԅܐຽ҅tableviewฎᭇᯈ࢏҅ਫሿUITableViewDelegate ᦓฎፓܐଫአ҅ฎӞӻَࣳጱֵአ঩ಓ๶ਫሿᭇᯈ࢏ཛྷୗٌ҅ӾUITableViewDelegate ጱَࣳګԧय़ᰁ঩ಓٌ҅ӾUITableViewDelegate੪ฎ঩ಓ๢کCocoaTouch໛ຝӾአ UITableVIewጱData Sourceොဩڊ঩ಓොဩጱਫֺ҅ଚӬ᧔ڊᕳ ࣘดᐏ?܄ړᐏ҅ӧݶጱහഝრ ᤒই֜ดڜࢩྌ҅౯ᥧ஑ݢզᦡᗝग़ӻහഝრࠡ҅֕ฎํӻᳯ᷌ฎ֦҅ᬯฎమଗࡶޫ?మᦏ ጱහഝრ̶ىইፘ ᘶӤ҅ොဩݝฎᦏ౯ᬬࢧ໑ഝᛔ૩ጱᵱᥝ݄ᦡᗝىᘶ՜҅՜ெԍىஞই݄֜ىࢩྌ౯ժଚӧ ᘶጱդቘොဩ᯾ਫሿጱ̶ىᘶӤጱٌ҅ਫฎࣁහഝრى౯ժ՗դᎱ๶፡҅හഝრই֜ضᒼғḒ ᘶӷӻӧݶጱහഝრ?֦տெԍ॒ቘ?ىݢզވӞӻtableViewฎ reloadData每 contentsizecellcontentsize每 • UITableViewUIScrollViewcontentSize每tableview ឴ݐᤈṛጱդቘොဩտ᧣አහഝ๵හེҘ ত۸෸ᯈᗝහഝ෸҅ڡUITableViewฎই֜ᦇᓒٖ਻ṛଶጱҘԅՋԍ 每 cell要 每frame要 • idkeycell ই֜ᛔۖᦇᓒcellጱṛଶҘ 每种经种每 种种种 • 每 ᘶӷӻӧݶጱහഝრҘىݢզވӞӻtableViewฎ ᒫ ᶭ83 View 经经 UIView 每 First Responder 经 File’s Owner nib nib 经 ᚆ̶ۑԅߺ3ӻࢶຽҘ᮷ٍํՋԍړxib෈կጱ຅౮ Address Book Core Location Map Kit Store Kit Bonjour WebKit BSD Sockets Core Animation OpenGL ES Quartz 2D Core Data SQLite Core Audio OpenAL Media Library AV Foundation Cocoa Touch ⽆ ⽆ 每 Core Data 每 Core AudioCore Audio 每 Core Animation Core Animation ⼦ C API 每⽆ Cocoa Touch Objective-C ⽆ 每 ⽆ API GPS ⽆ UIKit Cocoa Touch iPhone 每 知好 Cocoa Touch iPhone 著每 UIKit iPhone OS X Foundation ⽆每 UIKit iPhone OS 后 Mac OS ᒫ ᶭ84 * ᚆ᧣ᜓࢶᇆጱݱᐿં௔(੒ྲଶ, ᜋჅ, ᜋ૧ᒵ) Core Image(ᄁ॒᳒ቘ) •    ࢵक़:Niumb •    ࢶ෈Ⴐഭ(ᕍC᧍᥺) ද෈๜ጱ໏ୗץ•    ᵋ఺ CoreText Core Text౲ᘏCore Imageጱ֛ḵ̶ አCore Text౲ᘏCore ImageᒵҘইຎֵአᬦ҅᧗᧨᧨ֵ֦አֵވฎ -[mainViewController viewDidAppear:] -[mainViewController viewDidLayoutSubviews] -[mainViewController viewWillLayoutSubviews] -[mainViewController viewWillAppear:] : -[mainViewController viewDidDisappear:] -[mainViewController viewWillDisappear:] : viewDidAppear:] [mainViewController viewDidLayoutSubviews] -[mainViewController viewWillAppear:] -[mainViewController viewWillLayoutSubviews] - -[mainViewController viewDidLoad] -[mainViewController : 
ViewController -[AppDelegate applicationDidBecomeActive:] -[AppDelegate applicationWillEnterForeground:] : -[AppDelegate applicationDidEnterBackground:] -[AppDelegate applicationWillResignActive:] : -[AppDelegate applicationDidBecomeActive:] -[AppDelegate application:didFinishLaunchingWithOptions:] -[AppDelegate application:willFinishLaunchingWithOptions:] ጱኞ޸ޮ๗? ଫአᑕଧ: ݣ෸ڹکݸݣ෸ጱኞ޸ޮ๗,޾՗ݸݣࢧفᓌᬿଫአᑕଧೲHomeᲫᬰ ᒫ ᶭ85 ੴෙᅩள᭛ਧ֖ᳯ᷌դᎱಅࣁᤈ҅ളතಅํጱ୑ଉق3.    ᦡᗝ 2.    ᦡᗝEnable Zombie Objects ๋ݸӞӻobject ᦢᳯጱڹሿEXECBADACCESSڊکತض1.    ᯿ٟ੒᨝ጱrespondsToSelectorොဩ҅ ᷌ጱྍṈํғ ሿBAD_ACCESSᲙ᧏҅᭗ଉฎᦢᳯԧᰀ೰ᰒ҅ྲইᦢᳯԧ૪ᕪ᯽නԧጱ੒᨝̶ள᭛ਧ֖ᳯڊ ই֜᧣ᦶBAD_ACCESSᲙ᧏Ҙ ၾ௳̵ྒ஗ሾᒵ̶ݎᳯ૪ᕪ᯽න੒᨝ጱ౮ާݒᰁ౲ᘏ ሿBAD_ACCESS̶ܻࢩฎᦢᳯԧᰀ೰ᰒ҅ྲইᦢڊ෸ᕪଉտݎጱ҅ࣁ୏کᬯᐿᳯ᷌ฎᕪଉ᭬ ሿҘڊӥ٭BAD_ACCESSࣁՋԍఘ ◦ ◦ (机) ◦ UI美 • MVC信 UI信信 • Ӿ҅ํߺԶಋ๢ຝ຅Ө௔ᚆ᧣ᦶᕪḵݎ֦ࣁਫᴬ୏ ᦶ᧣ޞҁ11҂ಸᲙᦄ -(void)touchesCanceled:(NSSet)touchedwithEvent:(UIEvent)event; -(void)touchesEnded:(NSSet)touchedwithEvent:(UIEvent)event; -(void)touchesMoved:(NSSet)touched withEvent:(UIEvent)event; -(void)touchesBegan:(NSSet)touchedwithEvent:(UIEvent)event; ᐿಋ۠᭗Ꭳොဩ̵ٟႴ༩ොဩݷҘپํߺ block, target-action ,, ጱ? ؀ොୗ,view޾viewԏᳵฎই֜փ؀ߺԶփํ,ײ෸ݎ֦؉iphone୏ count-- countlabel count == 0 • label三60count timer ᭆݎಋ๢ጱḵᦤᎱ᩻ᬦ60ᑁᰦݸ᯿ෛکᭆݎ҅(ࢶ ຉӞӥֵአಋ๢឴ݐḵᦤᎱဳٙᨴݩጱਫሿ᭦ᬋ(ᕳԧӞӻᐏֺړ ᒫ ᶭ86 Objective-C ੒᨝//po [self view] ڊ•    po አԭᬌ च๜ᔄࣳ//p (int)[[[self view] subviews] count]ڊ•    p ᬌ lldbҁgdb҂ଉአጱ᧣ᦶ޸եҘ • ,Crash • • • ⼰ ํߺԶଉᥠጱ Crash ࣋วҘ crash每每 - (void)doesNotRecognizeSelector:(SEL)aSelector每 • - (void)forwardInvocation:(NSInvocation *)anInvocation (void)forwardInvocation:(NSInvocation *)anInvocationanInvocation • - 每每 *)methodSignatureForSelector:(SEL)aSelectornil • nil- (NSMethodSignature 每每 selector每self每nil (id)forwardingTargetForSelector:(SEL)aSelector • NO- 每 NOYESclass_addMethod做 • + (BOOL)resolveInstanceMethod:(SEL)sel每 • (reciever) isa • [person say] objc_msgSend(person, @selector(say)) • objective-c objc_msgSend(reciver, selector) ”crash unrecognized selector • ⼒被“ տಸ unrecognized selector ୑ଉҘײՋԍ෸ 5. analyzeԞᤈҁӧӞਧᓕአ҂ ᦡᗝ ᚆғAddress Sanitizer҅ӨྍṈ2Ӟ໏ۑXcode7૪ᕪᵞ౮ԧBAD_ACCESSഔ឴    .4 ᒫ ᶭ87 什⼤什 • UUIDUniversally Unique Identifier每 • UUID + keychain每 ឴ݐӞݣᦡ॓ࠔӞຽᦩጱොဩํߺԶҘ Კԏ̶॒୮ᆐ҅ࢫᴚٖဋ᭗ᥴ٬ฎ๋অጱ̶ ڊૡٍ๶༄ၥݢᚆىሿጱૄმ౲ᘏහഝดᐏӧྋଉ҅ᮎ੪ᵱᥝ໑ഝᕪḵ౲ᘏፘڊӾݎ੒ԭ୏ ᵱᥝᴅ᧛դᎱӞྍྍັ፡᭦ᬋߺ᯾ٟᲙ̶ڞinstruments๶༄ၥ̵හഝดᐏᲙ᧏ጱbug҅ ᐿ॒ቘොୗ҅ྲইૄმጱbugݢզ᭗ᬦپړ໑ഝbugᔄࣳڞঅ॒ቘҔᝑ෫ဩፗᥡਧ֖҅ڞ Კԏ॒҅ڊՈާ፡๋҅অฎݢզbug॔ሿ̶ᥴ٬bug෸҅ᝑᚆ໑ഝൈᬿፗളਧ֖bugݎᕳ୏ ൉bugՈ҅඙֢کፗളತڞḇጱbugൈᬿ҅ᝑ᧍ԎӧႴศ҅ݍ•    ၥᦶBugғ໑ഝၥᦶಅ ඪᵞ౮҅ᆐݸᵞ౮ၥᦶٚӤᕚ̶ړӤᕚጱ ඪӨٌ՜ࢫᴚ๋ᬪᥝړݢզਖ਼fix bug҅ݎԆଗ҅ᆐݸӤᕚ̶ᝑฎग़ࢫᴚ୏کݸ҅ٚݳଚ ඪ҅ᥴ٬bugଚၥᦶ᭗ᬦړbugૄმԏ̶॒ᥴ٬ᕚӤbugᵱᥝ՗Ԇଗ೉Ӟӻෛጱړय़᮱ک •    ᕚӤBugғᶱፓֵአԧ݋ፑᕹᦇ҅ࢩྌտํૄმ෭ப҅᭗ᬦᥴຉdYSMݢզፗളਧ֖ ԅၥᦶӾጱBug޾ᕚӤጱBugғړBug ݇ᘍᒼໜғ զٌ݊ᥴ٬ᳯ᷌ጱ௏ᖌ̶҅ێ॒ቘbugጱᚆ ᬯӻଫᘷᘏጱڊᬯӻᳯ᷌፡᩸๶உᒱᕹ݈҅֕Ӟᰒᥠᤅ̶᭗ᬦଫᘷᘏጱࢧᒼ҅ݢஉፗᥡࣈ፡ ֦Ӟᛱฎই֜᧣ᦶBugጱҘ Ṉ1̵2҂ හᬬࢧᕮຎฎྋᏟጱٌ҅ਫ੪ฎӞӻ᭓୭ጱᬦᑕҁྍڍඪಅ᧣አጱړහӾྯӻڍ3.    ༄ၥ ၥ݇හጱྋᏟ௔ฎஉ᯿ᥝጱ̶ ୑ଉ̶ࢩྌ҅አෙ᥺༄ڊᦤ஠փ݇හӧᚆԅᑮ҅ᝑԅᑮଫᧆಲכහጱ݇හ҅ڍ2.    ༄ၥ ጱྋᏟጱ ඪಗᤈጱᕮຎړӻྯכඪ҅Ꮯړࣁ᧍ဩӤਂࣁݢᚆᗌ੝๵կጱᳯ̶᷌ಅզ҅༄ັಅํጱވฎ ඪ҅ړහӾጱಅํڍຉړᲙଚӧฎૄმ҅ࢩྌဌํᲙ᧏෭பݢ፡̶ᒫӞྍ੪ฎڊ1.    ࢩ Კԏ॒ғڊᚆ ຉݢړሿ๶ڊᲙԏ̶॒՗զӥ᥯ଶڊ՗ᳯ᷌ൈᬿݢᎣ҅bugӧտ஠ሿጱ҅ࢩྌ෫ဩፗളਧ֖ ݇ᘍᒼໜғ ຉӞӥ̶ړൈᬿᳯ᷌๶ ḇᬦ๶ጱbugݍሿጱ᷇ሲവၥ̶ᒟᘏ಩ᬯӻᳯ᷌୮֢ၥᦶ᮱ڊݢզ໑ഝܩԍbug҅֕ฎ౯ժ ๶ฎՋڊຉړ᫾॔๥෸҅᭗ᬦٌ՜ૡٍଚӧᚆྲۓᘒդᎱᰁྲ᫾य़Ӭӱ҅٭ሿᬯ໏ጱఘڊտ ײӾಅԾኞጱbug҅ํጱ෸ݎຉ̶ᬯ໏ጱᳯ᷌Ԟฎஉํ఺Ԏጱ҅ࣁᶱፓ୏ړဌํ՗ग़ොᶎ݄ ጱ҅ܔବই̶֜உग़Ոጱࢧᒼտฎஉᓌۑຉ҅ݢզᎣ᭲ଫᘷᘏጱړᬯ໏ጱᳯ᷌᭗ᬦଫᘷᘏጱ ሿࣁߺ᯾Ҙڊහ10ེӾํ7ེྋᏟ҅3ེᲙ᧏҅ᳯ᷌ݢᚆڍইຎӞӻ ᕮຎғ(int) $0 = 2ڊრդᎱӾ a = 1 Ҕexpr a=2 ᬌ//̶؀දݒᰁጱץ ๶̶ଉአԭࣁ᧣ᦶᬦᑕӾڊܦexpr ݢզࣁ᧣ᦶ෸ۖாಗᤈ೰ਧᤒᬡୗ҅ଚਖ਼ᕮຎ಑    • ᒫ ᶭ88 Ձጱ̶وဳғᬯӻොဩӾaccessGroup:ᬯӻ݇හইຎӞԶAppᦡᗝፘݶጱᦾ҅ฎݢզ }     } (id)kSecValueData];         [keychainItem setObject:[self uuid] forKey:     {     if (strUUID == nil || [strUUID isEqualToString:@""]) (id)kSecValueData];     NSString *strUUID = [keychainItem objectForKey: initWithIdentifier:@"UUID" accessGroup:@"com.xxx.www"];                                          alloc]     KeychainItemWrapper *keychainItem = [[KeychainItemWrapper - (void)saveUuidWithKeyChain { 
 KeychainItemWrapper.h/.m每UUID 每keychainSecurity.frameworkKeychainItemWrapper.h/.m • keychain 每 被每iOSkeychain ⼒FTPSSH Mac OSMac OS X每地 • keychainMac OS每Mac OS 8.6 每 每keychainApp • 美keychainUUID 每keychain每 年UUID • UUID }     return result;     CFRelease(uuidString);     CFRelease(uuid); *)CFBridgingRelease(CFStringCreateCopy( NULL, uuidString));     NSString * result = (NSString     CFStringRef uuidString = CFUUIDCreateString( nil, uuid );     CFUUIDRef uuid = CFUUIDCreate( nil ); - (NSString*)uuid { //឴ݐӞӻUUID 
 每 每UUID 每 UUID每 ᒫ ᶭ89 2.appapp app每 1.app每 iOS App Profile-> Instruments ->Time Profiler ই֜੒iOSᦡ॓ᬰᤈ௔ᚆၥᦶ? • 每 • bug • • bug • ֦Ӟᛱฎই֜᧣ᦶ Bug ጱҘ • Leaks:,⽣ • Allocations:, • Zombies:⼰,, • Time Profiler: • : • , Instruments,, ֦Ӟᛱฎெԍአ Instruments ጱҘ 
 地地每 • keychainUUID每 • 年 }     return strUUID; (id)kSecValueData];     NSString *strUUID = [keychainItem objectForKey: initWithIdentifier:@"UUID" accessGroup:@"com.xxx.www"];                                          alloc]     KeychainItemWrapper *keychainItem = [[KeychainItemWrapper - (NSString *)getKeychain { keychainUUID • ᒫ ᶭ90 • • framework • cocoapods ᵞ౮ӣො໛ຝํߺԶොဩ • Podfile, Podfile⽆ Ҙکې౯మදᇇ๜҅ெԍײአcocoapodsᓕቘᒫӣො໛ຝጱ෸ CocoPodsAFNetworking,$ pod install 
每 • Podfile ◦ 每vim :wq ◦ pod "AFNetworking", "~> 2.0” ◦ platform :ios, '9.3' • Podfile Podfile $ vim Podfile • ⼒cd被vim • CocoaPod⽆每 ҘਙฎՋԍҘCocoaPodsጱܻቘ?ހֵአᬦCocoaPods ҁ12҂ᒫӣො໛ຝٌ݊ᓕቘ 10.IOS 9.给 8.app 7. app给? 6.app? 5.app 4.(10%50%95%)app app.3 ᒫ ᶭ91 NSInvocationOperation 每 • SDImageCache 每 • downloadDelegates 每 每 • imageDownloader:didFinishWithImage: SDWebImageManager imageDecoder:didFinishDecodingImage:userInfo: SDWebImageDownloader每 • notifyDelegateOnMainThreadWithInfo: 每 • NSOperationQueue UI每 每 • connectionDidFinishLoading: SDWebImageDecoder • connection:didReceiveData: ImageIO 每 每 • NSURLConnection delegate 要信 • SDWebImageDownloader 每 imageCache:didNotFindImageForKey:userInfo:每 • , imageCache:didFindImage:forKey:userInfo:每每 被每SDImageCacheDelegate • ⼒ notifyDelegate:每 • URLKey 每 NSOperation 每 • NSInvocationOperation UIImageView+WebCache 每 • SDWebImageManagerDelegate webImageManager:didFinishWithImage: SDWebImageManager每 SDImageCacheDelegate imageCache:didFindImage:forKey:userInfo: • queryDiskCacheForKey:delegate:userInfo:. SDImageCache • SDWebImageManager-downloadWithURL:delegate:options:userInfo: SDWebImageManager URL 每 • setImageWithURL:placeholderImage:options: placeholderImage image image image image image image image image image image image image image image image SDWebImage ጱᳯ᷌?ܜই֜ᥴ٬TableView҅ګSDWebImageጱܻቘਫሿ๢ ᒫ ᶭ92 : • AFNetworkingNSURLSessionNSURLCollection⼒iOS9.0被, ຉ̶ړ(AFNetworking)ҘAFNବ੶ܻቘ ဌํ՚ᕡᎸ᧛ᬦਙժጱრᎱํײֵአᒫӣො໛ຝጱ෸ ◦ ◦ ◦ , , HTTP Range ◦ ◦ • : Ҙހֵአ AFNetworking؉ᬦෙᅩᖅփ • ⽆, AFN,SDWebimage,FMDB, MBProgressHUD, Masonry每 ֦አᬦߺԶᒫӣො໛ຝҘ , . , tableView cell , 不(Cache) , , • ,,, , . , , , , tableView cell要 ,, 能, • tableView, , (UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { } • cell,- (UITableViewCell )tableView: • , , , , tableViewController: ጱҘګSDWebImageெ໏ਫሿࢶᇆጱᖨਂ๢ . , . tableView cell, cell, , • tableView每, • SDWebImagePrefetcher 每 • SDWI UIButton+WebCache MKAnnotationView+WebCache每 每 SDImageCache • ᒫ ᶭ93 හഝᓕቘ         AVFoundation          Media Library          OpenAL          Core Audio ᶪ᷇޾ᥤ᷇ ᔄ:ړ3> ໛ຝ 4.MBProgressHUD 3.masonry 2.SDWebImage 1.AFNetWoring 2> ᒫӣොପ: CoreAudio.framework MediaPlayer.framework, UIKit.framework, CoreGraphics.framework, Foundation.framework, 1> iOS-sdk: 5ӻզӤ֦ಅᆧఀጱiOS sdkପํߺԶ޾ᒫӣොପํߺԶ?ڊԈ •AFN60s. AFNἕᦊ᩻෸෸ᳩฎग़੝ࠡ? • AFXMLParserResponseSerializer; XML; .. • AFHTTPResponseSerializer; ; JSONXML, • AFJSONResponseSerializer; JSON,. • AFURLResponseSerialization :;.: (AFJSONRequestSerializer).. • AFURLRequestSerialization :,.JSON • AFSecurityPolicy :, HTTPS . ,. • AFNetworkReachabilityManager :. ,. • AFHTTPRequestOperationManager AFHTTPSessionManager : API() . • AFHTTPSessionManager : NSUrlSession ,, .⼒3.0被 AFHTTPRequestOperationManager : NSUrlConnection,, • ᒫ ᶭ94 UIKit OC⼦⼒NSObject被信 Foundation ໛ຝҘݎᓌᬿӥ᝘ຎጱ୏ ฃᖌಷ҅ӧਂࣁٞ֟APIכ•    Ꮯ ׁᩢ҂ Ӥӧᚆํक़᮱ڞପጱᕍ၄ҁܻولᦤכဌํक़᮱ׁᩢ౲ᘏׁᩢᥝੱݢᚆጱ੝҅զכ•    Ꮯ APIฃಘ઀҅ݢզᘍᡤᶼኸ݇හכ•    Ꮯ ᦤᷚ໒ᕹӞ̶כAPIᖫᎱᥢ᝜҅כ•    Ꮯ ᦤํᧇᕡጱ१෈կဳ᯽᧔ก̶כӬ҅ܔक़᮱᧣አᓌכ•    Ꮯ ໛ຝғول๶௏ᘍ޾ᦡᦇݎڊ՗զӥ᥯ଶ ໛ຝ̶ य़༷ᵱᥝই֜؉̵ᵱᥝဳ఺ߺԶᳯ᷌҅զֵՈՈๅ਻ฃࣈֵአ֦ጱڊ ጱᕪḵҔইຎဌํ҅᧗ᦡమ޾ᦡᦇ໛ຝጱpublicጱAPI҅ଚ೰ײପ෸ ՜ՈֵአԍҘইຎํ҅᧗᧨Ӟ᧨຅ୌ໛ຝ౲ᘏ׀ਫሿᬦ໛ຝ౲ᘏପզ 就每 • API,github⽆API, 就 ᒫӣොAPIฎெԍአጱҘ         Store Kit         Map Kit         Core Location         Address Book አಁଫአ         BSD Sockets         WebKit         Bonjour ᗑᕶ         Quartz 2D         OpenGL ES         Core Animation ࢶᇆ޾ۖኮ         SQLite Core Data         ᒫ ᶭ95 每每 removedOnComletion=NO toValue每fillMode=kCAFillModeForwards • durationkeyPathfromValue • toValuekeyPath • fromValuekeyPath • : • CABasicAnimationCAPropertyAnimation @”position”keyPathCALayerposition CALayer每 • keyPathCALayerkeyPath(NSString) CABasicAnimationCAKeyframeAnimation • CAPropertyAnimationCAAnimation CAAnimationጱ੶ᕆᕮ຅ ҁ13҂ᕲࢶӨۖኮ GPSWIFI CoreLocation Unicode strings信XML信URL CoreFoundation HTTP信FTPBonjour Services CFNetwork API AVFoundation SystemConfiguration 2DCAPI CoreGraphics QuartzCore CALayerposition(0,0)CABasicAnimationfromValue(10,10)toValue (100,100)(100,100)position (0,0) • CAKeyframeAnimationCApropertyAnimationCABasicAnimation CABasicAnimation(fromValue)(toValue) CAKeyframeAnimationNSArray • • valuesNSArray每””(keyframe)每 (duration)values • pathCGPathRef\CGMutablePathRef,每path CALayeranchorPointposition每pathvalues • keyTimes,01.0,keyTimes values.keyTimes, • CABasicAnimation2CAKeyframeAnimation • CAAnimationGroupCAAnimation CAAnimationGroup • • animationsNSArray
 beginTime • CATransitionCAAnimation 每iOSMac OS X • UINavigationControllerCATransition • : • type成 • subtype成 • startProgress() • endProgress() • UIView • UIKitUIViewUIView 
 UIView [UIView beginAnimations:nil context:nil][UIView commitAnimations] ᒫ ᶭ96 ᒫ ᶭ97 
 http://blog.csdn.net/mangosnow/article/details/37054765 
http://www.tuicool.com/articles/jIJzMf 
每 
⼒Context被每 • 2D • 2D也: , , , , 信每 Core Graphics信信信 • Core Graphics信每 UIKitCore Graphics每 drawRect每 • 信drawRect 每 Core Graphics 320*480每 Core Graphics 每什640 960 
• 320 480 retainretain320 480信640 960 • Core Graphics做CG每 • Core GraphicsUIViewUIKit每 ◦ Quartz Core Core Animation信API ◦ Quart 2D APICore GraphicAPI 信信信每 ◦ quartz过IOSMAC OS X ZHONG • Core Graphics Quartz 2D • Core GraphicsCAPI ᧨᧨֦੒Core Graphic ᕲࢶጱԧᥴ? PNG PNG PNG PNG PNG PNG PNG PNG PNG PNG PNG PNG PNG PNG PNG PNG PNG 
 • Block • ᒫ ᶭ98 (void (^)(BOOL finished))completion; duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion: 
+(void)transitionFromView:(UIView )fromView toView:(UIView)toView 
• : (^)(BOOL finished))completion; (UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void +(void)transitionWithView:(UIView* )view duration:(NSTimeInterval)duration options: 
• : හ, ਫሿ᫨࣋ۖኮڍֵአUIViewጱۖኮ 是每 • Cocoa Touch 4 Core Animation 成他信信 ᐿCore AnimationᬦჁᔄࣳҘپԧߺ׀Cocoa Touch൉ . UINavigationControllerCATransition 每iOSMac OS X. • CATransition-, CAAnimation ᫨࣋ۖኮ? 
 ◦ CALayerremoveAnimationForKey:CALayer CALayer ◦ CALayeraddAnimation:forKey:CAAnimation ◦ CAAnimation QuartzCore.h>(iOS7.0+ ) ◦ QuartzCore.framework⽆2.3ྯӻNSManagedObjectContext੒᨝ਫֺ᮷ݢզֵአݶӞӻ NSManagedObjectContext 2.2ইຎమᥝग़ᕚᑕᦢᳯCoreDataጱᦾ๋҅অጱොဩฎӞӻᕚᑕӞӻ< ق>2.1  CoreDataӾጱNSManagedObjectContextࣁग़ᕚᑕӾӧਞ ᳯ᷌.ᳯ᷌ࣁԭ ጱຝ຅ಅզࣁग़ᕚᑕӾਫሿCore dataտํقਞݎ3>    Core data๜᫝ଚӧฎӞӻଚ Ӿ) ٬ਧහഝਂؙጱ֖ᗝ (SQLite/XML/ٌਙ෈կ :NSPersistentStoreCoordinator දັ ڢNSManagedObjectContext: አԭ඙֢හഝପ, ݝᥝํᔄਙ੪ᚆ੒හഝପጱᤒᬰᤈी ӾጱӞ๵හഝ ๶ጱ੒᨝,᮷ฎᧆᔄ੒ଫጱᤒڊୌڠӻᖀಥԭᧆᔄጱᔄ੪੒ଫӞୟᤒ. ྯӞӻ᭗ᬦᖀಥᧆᔄ ୌӞୟӨԏ੒ଫጱᤒ, Ԟ੪ฎӞڠNSManagedObject :ݝᥝਧԎӞӻᔄᖀಥԭᧆᔄ੪տ 2>    coreDataӾํӣӻ੒᨝ฎ஠ᶳഩൎጱ, 1>    CoreDataฎ੒SQLiteහഝପጱ੗ᤰ ԍ໏ጱᒽኼ๶ਫሿጱҘ ୌ౲ᘏփ᭓Ҙ֦ฎአՋڠNSManagedObjectӾጱߺԶᵱᥝࣁᕚᑕӾ NSPersistentStoreCoordinator҅NSManagedObjectContext޾ ֦ਫሿᬦग़ᕚᑕጱCore DataԍҘ Core DateNSManagedObjcet每 NSManagedObjcetNSObjectCore Date每 ՋԍฎNSManagedObjectཛྷࣳҘ ’著“/” ' -> '' 每keyWord = keyWord.replace("/","//"); ቘොဩ̶॒کᇙྛਁᒧጱොဩ޾ളතفsqliteӾൊ ҁ14҂හഝਂؙ ᒫ ᶭ102 经 ◦ ⼒信⼀信被sqlite3_exec()做 ◦ SQLSQL每 每 每sqlite3 ◦ sqlite3_open() 被 • iOSSQLite⼒libsqlite3⽆ ◦ ⼒被 被 ⼒ ◦ SQLite libqlite3⽆C被 ◦ iOSC信⼒ObjC ◦ C iOSSQLite每SQLite 又SQLiteSQL 每SQLiteSQLSQL • 信信SQL • SQLite每 活每 •SQLite活信 ᧔Ӟ᧔֦੒SQLiteጱᦊᦩ 3. DBcore DataFMDB 2. Fileplist,Archiver,Stream 1. NSUserDefault,KeyChain,File,DB. iOSӾଉአጱහഝਂؙොୗํߺԶҘ NSDate • NSCoding OCӾਫሿ॔๥੒᨝ጱਂؙ • • • 
 ۸҅አ๶؉Ջԍڜଧݍ۸޾ڜՋԍฎଧ ᒫ ᶭ103 ⼒SQLite3被每 每Core Data 更NSManagedObjectContext 
->每 ->-> 
 • 更 Core DataSQLite3API ᧔Ӟ᧔֦੒Core Dataጱᦊᦩ 每 beginTransaction信commit信rollback信 每FMDBFMDatabase 每Core Data信⼀信 transaction;”“commit transaction;”“rollback transaction;” FMDBSQLite被sql“begin libsqlite3⼒ sql每 ◦ FMDBFMDBFMDB 每 FMDatabaseQueueFMDatabase 每 ◦ libsqlite3 “?”“%@”信每 每sql 每 FMDatabaseexecuteUpdate:executeQuery: ◦ KCDbManagerFMDB 每 FMDBMFDatabase 每 ◦ FMDBlibsqlite3⽆ 每FMDB •FMDB⽆⽆sqlite⽆ ᧔Ӟ᧔֦੒FMDBጱᦊᦩ 每每 sqlite3_column_() 被sqlite3_step() sqlite3_prepare_v2()sql⼒ ◦ ᒫ ᶭ104 ? sqlitecore data? , , ? ? sqlite 
每 ,,, :Key,,,,就每 ◦ : CoreData,CoreData每 ◦ CoreData:CoreData, 每 每,,CoreData 能,每 ,CoreData ,每⽆, CoreData, 每每就 ◦ CoreData,SQLite信XML 每 ,信Timeline SQL DML每 ,每, ◦ SQLiteNSUserDefaults,⼦ , 每 ◦ NSUserDefaults:, • . ◦ CoreData, ◦ SQLite, ◦ NSUserDefaults, OC:• ?ڦ܄OCӾํߺԶහഝਂؙොୗ,ݱํՋԍ 每 
 • ⼀每 ⼀deleteObject⼀每 
• ⼀ 每 每信⼀信 过NSEntityDescription 
 • 每 Core Data每 
 • ᒫ ᶭ105 • C做\SQL • SQLite#import SQLiteහഝਂؙฎெԍአҘ • ALTER TABLE RENAME COLUMN TO ; • ⼀ALTER TABLE DROP COLUMN ; • ALTER TABLE ADD COLUMN ; • SQL ޫҘ හഝପӾጱਁྦྷெԍਫሿ҅ইຎӧֵአCoreDataےইຎݸ๗ᵱᥝी 
 • Core Data每Core Data信每 • Core DataSQLite, SQLite每 • Core Data,(RDBMS)每 • coredata⽆,sqlite,sqlAPI每 每,sqlite 活sql每 • mac os xsqlite,,活 每 • coredataapp ,core data就, 每 • coredata ,,今 • coredataapp每 每 • coredata,,coredatasqlite 每 • coredata⼦,,,今,最app 每 • coredataapp, iOS: 信就信SQLite3Core Data• ?ހᔮࣳහഝପىᔮ?coredataฎӞӻ iOSଘݣெԍ؉හഝጱ೮ԋ۸?coredata޾sqliteํ෫஠ᆐᘶ ᒫ ᶭ106 ▪ PreferenceiCloud ▪ Caches,SDWebImage ◦ Library ◦ DocumentsiCloud,, ◦ Application 1. iOS ጱဉፋፓ୯ᕮ຅ฎெ໏ጱҘ App Bundle ᯾ᶎ᮷ํՋԍҘ 
 : http://www.2cto.com/database/201407/317367.html 被12⼒3×4被 ⼒3 • ڦ܄᧔᧔හഝପጱૢᬳള޾ݦᬳളጱ : http://blog.csdn.net/wscqqlucy/article/details/8464398 FMDBጱֵአ޾੒ग़ୟᤒጱ॒ቘ : http://blog.csdn.net/jasonblog/article/details/17842535 Core Dataහഝᬢᑏ NSManagedObjectContextNSPersistentStoreCoordinator • NSManagedObjectContextNSPersistentStoreCoordinator NSManagedObjectContext • CoreData • CoreDataNSManagedObjectContext • CoreDataSQLite ԍ໏ጱᒽኼ๶ਫሿጱҘ ୌ౲ᘏփ᭓Ҙ֦ฎአՋڠNSManagedObjectӾጱߺԶᵱᥝࣁᕚᑕӾ NSPersistentStoreCoordinator҅NSManagedObjectContext޾ ֦ਫሿᬦग़ᕚᑕጱCore DataԍҘ • ⼒信信被 • • (\) • • • 信信 Ҙګൈᬿӥਮಁᒒጱᖨਂ๢ܔᓌ ᒫ ᶭ107 id ret = nil; +(id)load:(NSString *)service { } NULL); SecItemAdd((__bridge_retained CFDictionaryRef)keychainQuery, Ԁۺ// ັᧃᰬ id)kSecValueData]; archivedDataWithRootObject:data]     forKey:(__bridge_transfer [keychainQuery setObject:[NSKeyedArchiver ᒧԀਁکෛጱ੒᨝ے// Ⴒ SecItemDelete((__bridge_retained CFDictionaryRef)keychainQuery); ᴻ෯ጱڢෛጱے// Ⴒ getKeychainQuery:service]; NSMutableDictionary *keychainQuery = [self // ឴஑൤ᔱਁَ +(void)save:(NSString *)service data:(id)data { }         nil]; id)kSecAttrAccessible, id)kSecAttrAccessibleAfterFirstUnlock,    (__bridge_transfer         (__bridge_transfer         service, (__bridge_transfer id)kSecAttrAccount,         service, (__bridge_transfer id)kSecAttrService, (__bridge_transfer     id)kSecClass,         (__bridge_transfer id)kSecClassGenericPassword, return [NSMutableDictionary dictionaryWithObjectsAndKeys: +(NSMutableDictionary *)getKeychainQuery:(NSString *)service { @implementation YCKKeyChain #import ᛔਧԎӞӻkeychainጱᔄ keychain,地,keychainSecurity⽆ ইጭ୯ጱ token҅௳מ֦տই֜ਂؙአಁጱӞԶභఽ ◦ :活 ◦ :, ◦ :target ◦ Info.plist:. 2. App Bundle tmp ◦ NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; // ᯈᗝ൤ᔱᦡᗝ [keychainQuery setObject:(id)kCFBooleanTrue forKey: (__bridge_transfer     id)kSecReturnData]; [keychainQuery setObject:(__bridge_transfer id)kSecMatchLimitOne forKey:    (__bridge_transfer id)kSecMatchLimit]; CFDataRef keyData = NULL; if (SecItemCopyMatching((__bridge_retained CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) {     @try {         ret = [NSKeyedUnarchiver unarchiveObjectWithData: (__bridge_transfer NSData *)keyData];     } @catch (NSException *e) {         NSLog(@"Unarchive of %@ failed: %@", service, e);     } @finally {     } } return ret; } +(void)delete:(NSString *)service { NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; SecItemDelete((__bridge_retained CFDictionaryRef)keychainQuery); } ,,⼀
 // 地
 static NSString const KEY_IN_KEYCHAIN = @"com.yck.app.allinfo";
 // 
 static NSString const KEY_PASSWORD = @"com.yck.app.password"; +(void)savePassWord:(NSString *)password { NSMutableDictionary *passwordDict = [NSMutableDictionary dictionary]; [passwordDict setObject:password forKey:KEY_PASSWORD]; [YCKKeyChain save:KEY_IN_KEYCHAIN data:passwordDict]; } +(id)readPassWord { NSMutableDictionary *passwordDict = (NSMutableDictionary *) [YCKKeyChain     load:KEY_IN_KEYCHAIN]; return [passwordDict objectForKey:KEY_PASSWORD]; } +(void)deletePassWord { ᒫ ᶭ108 ᒫ ᶭ109 每Core Datagraph modelSQLite 每SQLiteCore Data每 • SQLite Core Data每 • NSCoding每 每SAX每 •XML就 • NSUserDefaultsnice着 • Core Data • SQLiteSQL • NSCoding就 • XML, JSON, plist • NSUerDefaults • ୮ਂؙय़ࣘහഝฎெԍ؉Ҙ 每 每idplist • 信 plist每plist每 • plistiOS每NSUserDefaults plist෈կฎአ๶؉Ջԍጱ̶Ӟᛱአਙ๶॒ቘӞԶՋԍොᶎጱᳯ̶᷌ ᥴੂ̶/ੂےᚆ෸҅᭗ଉտਖ਼හഝᬰᤈbase64ۑ ጱىፘੂےݪӤփࢶᇆ᯻አጱฎਖ਼ࢶᇆ᫨ഘ౮base64ਁᒧԀ҅ٚӤփ̶ࣁ؉لӾ҅ํጱݎ ෈̶ࣁ୏ܻکᓒဩ҅ฎݢᭋጱ҅ᕪᬦencodeݸ҅ݢզdecode஑ੂے•    Base64ғંԭ ഖ̶ࣕވ᭗ᬦኞ౮෈կጱ൹ᥝ҅አԭḵᦤ෈կฎ ኞ౮൹ᥝ҅ᬯ໏ݢզᴠᓫද̶݈ই҅ӥ᫹෈կ෸҅ڞᒒ᯻አݶ໏ጱᥢۓ౮൹ᥝ҅ਮಁᒒ޾๐ ኞ౮32֖൹ᥝ҅አԭḵᦤහഝጱํප௔̶ྲই҅ࣁᗑᕶ᧗࿢ളݗӾ҅᭗ᬦਖ਼ಅํጱ݇හኞ ෈̶ଉአጱฎܻک•    MD5ғฎӞᐿӧݢᭋጱ൹ᥝᓒဩ҅አԭኞ౮൹ᥝ҅෫ဩᭋ፳Ꮘᥴ஑ ጱ̶ Ӿฎ๋ଉአݎMD5޾Base64҅ਙժӷᘏࣁਫᴬ୏کԒ᮷տֵአپᚆጱ҅ۑጱىፘੂے؉ᬦ ฎՋԍ҅ݱᛔֵአ࣋วฎՋԍҘڦ܄MD5޾Base64ጱ { NSLog(@"ဌํᦡᗝ"); } if([[NSUserDefaults standardUserDefaults] objectForKey:ID] == nil) ӧᎣ᭲ฎ፥ጱ NO ᬮฎဌํᦡᗝᬦ) Ҙ(ྲইᬬࢧ NO҅؀ֵአ NSUserDefaults ෸҅ই॒֜ቘ૲ਫ਼ጱἕᦊ } YCKKeyChain delete:KEY_IN_KEYCHAIN];] ᒫ ᶭ110 • Core FoundationCFRunLoopRef • FoundationNSRunLoop iOS2APIRunLoop Runloop੒᨝ 
 cpu每 • app每runloop Sources1)信TimerRunLoop • RunLoopModeModeSource(Sources0信 ⼒run被 • RunLoopRunLoopRunLoop • do-while每 • 每 Ջԍฎ RunloopҘ ҁ15҂Runloop ᲁፗളᬬࢧک୮ms<=0෸҅Ⴔᴻbusy handle҅ኩ᧗ӧ ඙֢ᬬࢧsqlite_BUSYڹᵱᥝጱᲁ҅୮کইຎ᩻ᬦmsྺᑁ҅Ֆᆐኩ᧗ӧ ඙֢ڹᬡᧆྺᑁහ෸҅sqliteտsleepଚ᯿ᦶ୮کਧԎӞӻྺᑁහ҅୮๚ int sqlite3_busy_timeout(sqlite3*, 60); 2>    ᦡਧᲁਧ෸ጱᒵஇ෸ᳵ ඙֢ᬬࢧSQLITE_BUSYڹ୮ڞ඙֢҅ᬬࢧ҉ڹහᬬࢧᶋ҉,හഝପտ᯿ᦶ୮ڍ᧣ࢧ හጱེහڍහտᤩփ᭓ԅᧆኧྌེ஬Ԫկ᧣አᧆڍහጱᒫԫӻڍ᧣ࢧ ᲁፗളᬬࢧکහԅҧҮҥҥ෸҅Ⴔᴻbusy handle҅ኩ᧗ӧڍ᧣୮ࢧ හڍሿහഝପ஬෸҅sqliteտ᧣አᧆڊහ҅୮ڍ᧣හݢզਧԎӞӻࢧڍ ;(*int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void හڍ1>    ᦡᗝහഝପᲁਧጱ॒ቘ ெԍᥴ٬sqliteᲁਧጱᳯ᷌ SQLiteC API GitHub.com/ccgus/fmdb)SQLite SQLite每SQLiteFMDB(https:// DBMS每AppleCore Data ᒫ ᶭ111 ԅғړᕆጱ҅ضmodeԆᥝฎአ๶೰ਧԪկࣁᬩᤈ஗ሾӾጱս ᵍ୏ӧݶᕟጱSource/Timer/Observer҅ᦏٌ԰ӧ୽ߥړᬯ໏؉Ԇᥝฎԅԧ فLoop҅ٚ᯿ෛ೰ਧӞӻModeᬰڊഘMode҅ݝᚆᭅڔইຎᵱᥝ ෸҅ݝᚆ೰ਧٌӾӞӻ Mode҅ᬯӻModeᤩᑍ֢CurrentModeۖސྯེRunLoop (array)Observer ᝑଗӻ(set)Source/(array)Timer/ތᝑଗӻMode҅ྯӻMode݈۱ތӞӻRunLoop۱ CFRunLoopModeRefդᤒRunLoopጱᬩᤈཛྷୗ̶ CFRunLoopModeRef CFRunLoopObserverRef CFRunLoopTimerRef CFRunLoopSourceRef CFRunLoopModeRef CFRunLoopRef ԭRunLoopጱ5ӻᔄىCore FoundationӾ ᔄىRunLoopፘ CFRunLoopGetMain(); // RunLoop CFRunLoopGetCurrent(); // RunLoop • Core Foundation [NSRunLoop mainRunLoop]; // RunLoop [NSRunLoop currentRunLoop]; // RunLoop • Foundation ឴஑RunLoop੒᨝ 
 • RunLoop • RunLoopRunLoop • RunLoop RunloopӨᕚᑕ 
 CFRunLoopRefAPI每 • NSRunLoopCFRunLoopRefOCRunLoop NSRunLoopCFRunLoopRefRunLoop • ᒫ ᶭ112 ◦ kcfRunLoopExit(loop)//128 ◦ kcfRunLoopAfterWaiting()//64 ◦ kcfRunLoopBeforeWaiting()//32 ◦ kcfRunLoopBeforeSources(source)//4 ◦ kcfRunLoopBeforeTimers(timer)//2 ◦ kcfRunLoopEntry(loop)//1 • • CFRunLoopObserverRefRunLoop CFRunLoopObserverRef ᔮᕹԪկݎړളත̵҅מSource1ғचԭPortጱ҅᭗ᬦٖ໐޾ٌ՜ᕚᑕ᭗ Source0ғᶋचԭPortጱ ᔄړහ᧣አ຾҅Sourceጱڍೲᆙ Cocoa Perform Selector Sources Custom Input Sources Port-Based Sources ᔄړೲᆙਥො෈໩҅Sourceጱ რ҂فCFRunLoopSourceRefฎԪկრҁᬌ CFRunLoopSourceRef 
 • GCDRunLoopMode • CFRunLoopTimerRefNSTimerRunLoopMode • CFRunLoopTimerRef CFRunLoopTimerRef •    NSRunLoopCommonModesҁkCFRunLoopCommonModes҂ •    NSDefaultRunLoopModeҁkCFRunLoopDefaultMode҂ ጱModeํӷӻғ׀୏൉ل᝘ຎ •    NSRunLoopCommonModesҁkCFRunLoopCommonModes҂ғModeᵞݳ ᧆmodeکഘڔ෸҅տۖސ•    UIInitializationRunLoopModeғrun loop ᧆModeکഘڔ•    UITrackingRunLoopModeғScrollViewჶۖ෸տ NSDefaultRunLoopModeҁkCFRunLoopDefaultMode҂ғἕᦊ҅ᑮᳳᇫா    • ᒫ ᶭ113 ◦ 有每 ◦ Runloop每更2. • ⼒9被 • Observer⼒8被 ◦ Runloop ◦ RunLooptimer ◦ timer ◦ Source0(port)每 • ⼒7被 • Observer⼒6被 • Source09⼒5被 • Source0⼒4被 • ObserverSource0⼒3被 • ObserverTimer⼒2被 • Observer:Loop⼒1被 RunLoop॒ቘ᭦ᬋ CFRelease(observer); // ᯽නObserver kCFRunLoopDefaultMode); CFRunLoopAddObserver(CFRunLoopGetCurrent(), observer, RunLoopጱᇫாލᥡ੊ᘏғፊے// Ⴒ }); ኞදݒ---%zd", activity);ݎRunLoopᇫாکލ    NSLog(@"----ፊ CFRunLoopActivity activity) { kCFRunLoopAllActivities, YES, 0, ^(CFRunLoopObserverRef observer, CFRunLoopObserverCreateWithHandler(CFAllocatorGetDefault(),      CFRunLoopObserverRef observer = 
 Observer • ᒫ ᶭ114 UIApplicationMain()做main threadNSRunLoop 
} 
} 
return UIApplicationMain(argc, argv, , NSStringFromClass([AppDelegate class])); 
@autoreleasepool { 
( argc, * argv[]) { 
iOSmain()做 
• run loop每 ᔮҘىrunloop޾ᕚᑕํՋԍ 
 能runloop每Runloop runloop每runloop每 • 要runloop每runloop • runloop每runloop每 • runloop美每 ࣁग़ᕚᑕӾইֵ֜አ݊,ګNSRunLoopጱਫሿ๢ • 有 • 有每 source被 • Runloop⼒input source被⼒timer http://www.jianshu.com/p/335a9b19adab image image image image image image image image image image image რفrunloopਧ෸რ޾ᬌ • • 在 • PerformSelector • ImageView •NSTimer Runloopጱଫአ • ObserverLoop RunLoppRunLoop更2. ◦ ᒫ ᶭ115 ጱModeํӷӻғ׀୏൉ل᝘ຎ •    NSRunLoopCommonModesҁkCFRunLoopCommonModes҂ғModeᵞݳ ᧆmodeکഘڔ෸҅տۖސ•    UIInitializationRunLoopModeғrun loop ᧆModeکഘڔ•    UITrackingRunLoopModeғScrollViewჶۖ෸տ •    NSDefaultRunLoopModeҁkCFRunLoopDefaultMode҂ғἕᦊ҅ᑮᳳᇫா ԅғړᕆጱ҅ضmodeԆᥝฎአ๶೰ਧԪկࣁᬩᤈ஗ሾӾጱս runloopጱmode֢አฎՋԍҘ 每 RunLoop每NSRunLoopNSTimer 每 RunLoop 每 • RunLoop每 • C runloopӾکےD ݢզਖ਼NSTimerႲ አRunLoopސᇿጱᕚᑕӾဌํ஠ᥝ݄ܔC ࣁӞӻ B ἕᦊᶋԆᕚᑕጱRunLoopฎဌํᬩᤈጱ A ྯӞӻᕚᑕ᮷ํٌ੒ଫጱRunLoop ੒ԭrunloopጱቘᥴӧྋᏟጱฎ • kCFRunLoopExit(128):runloopautorelease autorelease • kCFRunLoopBeforeWaiting(32):autorelease, • kCFRunLoopEntry(1):autorelease • :autoreleasepool,Autorelease runloop ⽽ • autoreleasepool, • ӥտᤩ᯽නҘ٭autorelease ੒᨝ࣁՋԍఘ 
NSRunLoop *runloop = [NSRunLoop currentRunLoop]; 
loop 每 • Cocoa run 每 • runlooprunloop 每 ᒫ ᶭ116 • ᤒ෸҅timerտฮਧࢧ᧣҅ԅՋԍҘই֜ᥴ٬ҘڜࣁჶۖᶭᶎӤጱ forMode:NSRunLoopCommonModes];     [[NSRunLoop currentRunLoop] addTimer:timer selector:@selector(timerTick:) userInfo: repeats:];    NSTimer *timer = [NSTimer timerWithTimeInterval: target: NSRunLoopCommonModes᯾کے  //ᆐݸٚႲ selector:@selector(timerTick:) userInfo: repeats:]; [NSTimer scheduledTimerWithTimeInterval: target: NSDefaultRunLoopModeӾکے //ਖ਼timerႲ runloopmode,),UI • 2,modeNSRunLoopCommonModes( ԅՋԍ UIScrollView ጱ჻ۖտ੕ᛘ NSTimer ०පҘ տࢧ᧣̶ CommonModesӥ҅ࢩԅฎNSDefaultRunLoopMode҅ݝํࣁᑮᳳᇫாӥ಍کفtimerන ෛ҅ᮎԍᥝਖ਼ڬ޾ӤӞ᷌Ӟ໏ጱ௏᪠҅ইຎᥝcell჻ۖᬦᑕӾਧ෸࢏ྋଉࢧ᧣҅UIྋଉ ෛ҅ԅՋԍҘڬވಋ೰჻ۖcellᬦᑕӾ҅labelฎ UITableViewCellӤํӻUILabel҅ดᐏNSTimerਫሿጱᑁᤒ෸ᳵ҅ න ᯽ک஑ӧڞވ•    ဳ఺timerࣁӧᵱᥝ෸҅Ӟਧᥝ᧣አinvalidateොဩֵਧ෸࢏०ප҅ runloop෸ଫᧆᦡᗝԅՋԍmodeکے•    ဳ఺timerႲ ݇ᘍᒼໜғ տݶ෸ਂࣁग़ӻtimerጱਫֺࣁٖਂӾ̶ڞ᯽න҅کጱӧᚆ஑ڹԏڞེ҅ ୌӞڠ๶̶ ݚक़੒ԭᥝ࿢஠ᶳᲀྪtimerጱ᭦ᬋ॒ቘ҅๚ਖ਼timerᗝԅ०ප҅ᝑྯེ᮷ ڊአٖਂᘒӧտ᯽න̶᭜౮᭦ᬋӤጱٖਂအᄋ̶ᧆအᄋӧᚆአxcode݊instrumentsၥܛ timer੪Ӟፗڞވਖ਼timerᗝԅ०ප҅ض஠ᶳڞ௏᪠޾ӤӞ᷌Ӟ໏҅ইຎమᥝᲀྪtimer҅ ݢ҂ܨNSTimerֵአ෸ጱဳ఺Ԫᶱҁӷᶱڊ᧗ٟ mode̶ ੪ଫᧆֵአἕᦊཛྷୗ̶֕ฎ҅ইຎ૶๕ࣁ჻ۖ෸҅ਧ෸࢏Ԟᥝࢧ᧣҅ᮎ੪ଫᧆֵአcommon Ԟ૶๕ӧ᧣ଶ҅ᮎ҅ײഘ҅ᘒ੕ᛘNSTimerਖ਼ӧٚᤩ᧣ଶ̶୮౯ժ჻ۖጱ෸ڔࢩԅmodeጱ ScrollView჻ۖᬦᑕӾտ ,ײԆᬩᤈ஗ሾӾጱ෸کےҁkCFRunLoopDefaultMode҂Ⴒ ইຎ౯ժ಩ӞӻNSTimer੒᨝զNSDefaultRunLoopMode •    NSRunLoopCommonModesҁkCFRunLoopCommonModes҂ NSDefaultRunLoopModeҁkCFRunLoopDefaultMode҂    • ᒫ ᶭ117 
 •GET/POST每 ⼀4每 HTTPGETPOSTPUTDELETE • URL过URL过 ࢏Ի԰ጱӧݶොဩ๋҅च๜ጱොဩํҘۓHttpਧԎԧӨ๐ 每 HEAD每 每 www.sina.com.cn?username=""&password=""URL GETURL URL每 POSTURL 每 HTTP3POST信GET信HEAD每POSTGET http᧗࿢ොୗҘ ҁ16҂ᗑᕶ 
 被 • ObserverRunLoop⼒ • ⼒信被 • • • 被 • 在⼒ Ӿইֵ֜አRunLoopҘՋԍଫአ࣋วҘݎࣁ୏ ᒫ ᶭ118 3> 
 2> 
 1> ই֜ᥴ٬Ҙ ԧ֘ܜ࢏ۓᭆ᧗࿢҅֕ฎ๐ݎ࢏ۓ᫹᩻य़ᰁጱහഝ҅ᕳ๐ےAppᵱᥝ JSONKit信SBJson信TouchJSON⼒,被 ?ڦ܄JSONKit̵SBJson̵TouchJSON޾ܻኞጱ 能每 能cpu410能 4,http4,cpu, cpu,cpu,.4cpu : ->⼒被-> Objective-C Mac OS X and iPhone . ASIHTTPRequest,CFNetwork API . asihttp 1Asyncsocket 4(closesocket()/WSACleanup())每 
 3(send()/recv())经 
 2(connect())经 
 1(WSAStartup()/socket())经 更 TCP/IPsocket每 信信每 recv做每每 ⼈IP/ sendtoIP/经 Socket 被每IP每 A看B⼒C信D信E信F…… TCP/IPSocket socketᖫᑕᓌᬿ ᒫ ᶭ119 GET POST Өᘶᔮ҅ਫ᪢Ӿই֜ᭌೠਙժҘڦ܄http ጱpostӨget 
ጱ෈կݷ҂ਂכ           suggestedFilenameҁୌᦓ 
 ▪ expectedContentLength ⼒被 ▪ ▪ 过信过 ▪ HTTP信信 ◦ OCNSURLRespose ◦ ◦ Date: Mon, 23 Jun 2014 12:54:52 GMT // ◦ Content-Length: 56811 // ◦ Content-Type: image/jpeg // ◦ Server: Apache-Coyote/1.1 // ◦ 过信过 ◦ HTTP信信 HTTP/1.1 200 OK ◦ ◦ ◦ 60s ◦ ◦ 过信 ◦ 信信HTTP ◦ ◦ OCNSURLRequest ◦ ◦ Accept-Encoding: gzip // ◦ Accept-Language: zh-cn // ◦ Accept: text/html, / // // 
◦ User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9) Firefox/30.0 ◦ Host: 192.168.1.105:8080 // 3. 过信 GET /XXServer/resources/images/1.jpg HTTP/1.1 
2. 信信HTTP 1. ሿጱҘ ߺԶٖ਻ҘOCӾฎெ໏ਫތᭆ᧗࿢̵ളතߥଫ ۱ݎ ጱמHTTPጱ᭗ ᒫ ᶭ120 qq ⼒ ) ⼒被 64k ⼒被 ⼒被 TCP UDP GET POST URL 1024 Request.QueryString Request.Form ◦ 每 ◦ ◦ 每 • ◦ 每 每 ◦ + ◦ ◦ • ՋԍฎӣེൎಋӨࢥེഀಋҘ http ftp telnet • TCP: :, , •UDP: : , Ҙڦ܄ԭUDP/TCPጱىҘ᧔᧔ހᎣ᭲TCP/UDP ᒫ ᶭ121 ,,,每 ,web()每 http ◦ httphttp,http,⼈ 1. httpscoket: ᐿଉአොୗ?پဩ,HTTPጱ ପ,TCP,UDPጱᬳളොىsocketᬳളፘ?ڦ܄ጱמhttp޾scoket᭗ 每 著著 1. () 每 tag每就,SAX 还 ◦ SAX , ,每 ◦ SAX XML 就,tag, 每 ◦ DOM XML 就, ◦ DOM XML 就,每 ◦ DOM XML 就, SAX 每 ◦ XML:DOMSAX每 3. XML: 每 ,博json,,, ,{} ,[], : ◦ ,著,{},[], : 2. JSON: ◦ :jsonxml ◦ 过:xml过 ◦ :jsonJavaScript,, ◦ :jsonxml,,有 ◦ :json,xml ◦ ::JSON ◦ 还:还 ◦ :,xml 1. Jsonxml: json̵xmlᥴຉොୗጱବ੶ฎই॒֜ቘጱ??ڦ܄ຉjson̵xmlጱړ 每每 ◦ ᒫ ᶭ122 Application ->all all people seem to need date processing 被每 • OSI每⼒信 每每 ⼒EBCDIC被⼒ASCII被 PC还 • 每 MAC被 ⼒IP • ⼒被每 每 每 QQ被每 被UDP⼒TCP很很 ⼒ ◦ ⼒WWW80被TCP 每 每Internet ◦ 每每 ◦ 被每每 ,1信0 每⼒1信0 ◦ 信起信 信信信信每 •OSIOSI信信 ବ੶ܻቘҁOSIӠ੶ཛྷࣳ҂מ᭗ 每CFSocketRef每 ,,每 ◦ scoketsocket“”, NSUrlConnection每 http)每iphone) Presentation ->people Session ->seem Transport ->to Network ->need Data ->date Physical ->processing ᦡᦇӞॺय़෈կҁইӤጯMጱᥤ᷇҂ӥ᫹ොໜ • NSURLSession • • NSURLSessionDownloadDelegate • NSURLSession不tmp • ⼒tmp不⼀ 被cache不 • 更 ◦ task 
 @property (nonatomic, strong) NSURLSessionDownloadTask *task; ▪ NSURLSession 
 NSURLSession *session = [NSURLSession sessionWithConfiguration: [NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc] init]]; ▪ 
 self.task = [session downloadTaskWithURL:⼒ URL被]; ▪ 
 /* /
 -(void)URLSession:(NSURLSession )session downloadTask: (NSURLSessionDownloadTask )downloadTask didWriteData: (int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
 { 
 // ᦇᓒӥ᫹ᬰଶ ▪ CGFloat progress = 1.0 * totalBytesWritten / totalBytesExpectedToWrite;
 } 
 /*/
 -(void)URLSession:(NSURLSession )session downloadTask: (NSURLSessionDownloadTask )downloadTask didResumeAtOffset: ᒫ ᶭ123 ᒫ ᶭ124 C HTTP B TCP A UDP ෸ᘱॠAppӧտ᯻አጱᗑᕶփᬌොୗܨ ᕟ౮ғᇫாᤈ̵ၾ௳ಸ१̵ߥଫྋ෈̶ړ- HTTPߥଫಸ෈ғኧӣ᮱ ᕟ౮̶ړ- HTTP᧗࿢ಸ෈ғӞӻHTTP᧗࿢ಸ෈ኧ᧗࿢ᤈ̵᧗࿢१᮱̵ᑮᤈ޾᧗࿢හഝ4᮱ ޾ߥଫಸ෈̶ ᦓ҅HTTPํӷᔄಸ෈ғ᧗࿢ಸ෈ܐଫԏݸ҅᱾ളෙ୏̶HTTPฎӞӻંԭଫአ੶ᶎݻ੒᨝ጱ ࢏ߥۓߥଫ҅๐ڊ࢏؉ۓᭆ᧗࿢҅๐ݎᦓ҅ฎᎨᬳള҅ฎਮಁᒒԆۖܐ- HTTP᩻෈๜փᬌ ᦓጱᇙᅩ:ܐHTTP ?ڦ܄ԭHTTP᧗࿢GET޾POSTጱىᦓጱᇙᅩ҅ܐHTTP 
 [self.task suspend]; 
/*/ 
 [self.task resume]; 
/*// 
 ▪ 
 } 
fileURLWithPath:file] error:nil]; ▪ [fileManager moveItemAtURL:location toURL:[NSURL ጱ᪠ஆਂכ෈կᳩ๗کڔۄ▪ //᭗ᬦ෈կݙຢ҅ਖ਼෈կ defaultManager]; ▪ NSFileManager *fileManager = [NSFileManager ▪ //឴ݐ෈կݙຢ e.suggestedFilename]; stringByAppendingPathComponent:downloadTask.respons tory, NSUserDomainMask, YES) lastObject] [[NSSearchPathForDirectoriesInDomains(NSCachesDirec ▪ NSString *file = ጱ᪠ஆਂכ //ኞ౮෈կᳩ๗ 
 { 
didFinishDownloadingToURL:(NSURL *)location (NSURLSessionDownloadTask )downloadTask -(void)URLSession:(NSURLSession )session downloadTask: 
/*不/ 
 { } 
didCompleteWithError:(NSError *)error -(void)URLSession:(NSURLSession )session task:(NSURLSessionTask )task 
/*error有/ 
 } 
Ӿྊ෸ጱ؇ᑏᰁۓ //fileOffsetғӥ᫹ձ 
 { 
int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes) ᒫ ᶭ125 ፳,ଚํහզጯӡᦇጱՈժֵአXMPPਫ෸փᦔ᫫կ̶ ࢏ᬩ֢ۓՔ෭ጱ԰ᘶᗑӤํහզӡᦇጱXMPP๐ ̶ێ ᘏԅXMPPದ๞ᘒۘݎහզጯᦇጱ୏ ጱ,ሿࣁ૪ᕪፘ୮ᑞਧ;ݎᒫӞӻJabber(ሿࣁXMPP)ದ๞ฎJeremie Millerࣁ1998ଙ୏ ᦓӥ,᮷ݢӨGoogle Talkਫሿᬳള̶ ᦤਫݢአ:ܐଫࠟࣁ᭽஗XMPP׀3921 ̶ ձ֜IM Presenceದ๞̶ ᘒXMPPጱದ๞ᥢ໒૪ᤩਧԎࣁRFC 3920݊RFC݊מݢጱਫ෸᭗ ԅᦊڜᦓզXMPPԏݷ,ྋୗܐ԰ᘶᗑૡᑕૡ֢ੜᕟ( IETF )૪ᕪਖ਼Jabberጱ໐ஞXMLၞ :ٵრᎱପᒵොᶎ,᮷૪ᕪݱᛔํग़ᐿਫሿ̶ ຽ ࢏ ̵ ᕟկ ̵ۓ୏ጱ,ଚӬฃԭԧᥴ̶ ᘒӬࣁਮಁᒒ ̵ ๐لᦓฎᛔኧ̵୏න̵ܐXMPP ୏න: ᦓ̶ սᅩܐୌᒈݸٚփӳᥜ,ᘒXMPP੪ฎᥢਧ֦փጱӳᥜጱ໒ୗ̶XMPPฎचԭXMLጱ ᦓ,Ӟᐿᥢਧ̶੪ฎ᧔,ࣁᗑᕶӤփ ӳᥜ,ᥝୌᒈᬳള,TCP/IPᬳള,ܐ᧔,XMPP੪ฎӞᐿ ጱܔᓌ̶ٵᦓ,ฎ ᕪኧ԰ᘶᗑૡᑕૡ֢ੜᕟ(IETF)᭗ᬦጱ԰ᘶᗑຽܐמᏐጱ୏නୗਫ෸᭗ ᑍ)ฎӞᐿզXMLԅचڹ,XMPP(Extensible Messaging and Presence Protocol ?ހՕᕨӞӥXMPP?ํՋԍսᗌᅩ ጱսᅩ̶ ݗ҅ݢᵋ෸ๅද҅ӧአๅෛᇇ๜੪ݢզӤᕚ҅ᬯฎ๋य़فᚆۑጱڦفH5ݢզਫሿ્فےiOS H5ߥଫྲܻኞᥝౌஉग़֛҅ḵӧॡঅ҅ᬯฎᗌᅩ̶فےiOS սᗌᅩғ Ѻމ ਮ൤ᔱܗݢզ᭗ᬦWebViewJavascriptBridge๶ਫሿ̶ٍ֛ইֵ֜አ҅᧗य़ਹٌ݄ਙ Swift JavaScriptCoreӨJSԻ԰ WKWebViewෛᇙ௔݊JSԻ԰ OC JavaScriptCoreӨjsԻ԰ ᘒᬯӻ੒᨝੒ଫԭ౯ժiOSጱ຤ӻᔄጱਫ̶ֺๅᧇᕡ᧗ᴅ᧛ғ ੒᨝҅فࣁiOS7զݸ҅ݢզፗള᭗ᬦJavaScripteCoreᬯӻପ๶ਫሿ҅᭗ᬦஃJS DOMဳ (UIWebViewNavigationType)navigationType; (NSURLRequest *)request navigationType: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest: API๶ਫሿғىፘ ฎᕅਧঅጱ҅ᆐݸiOS᧣አ๜ࣈވෙschemeฎڣ᭗ᬦਫሿUIWebViewጱդቘොဩ๶ೝ౼҅ ᐿਫሿොဩғپզӥ ࣁiOSӾ҅᭗ଉฎአUIWebView๶ਫሿ҅୮ᆐࣁiOS8զݸݢզֵአWKWebView๶ਫሿ.ํ սᗌᅩฎՋԍҘ Appই֜ਫሿጱ̶ࣁAppӾֵአHTML5ጱݎࣁAppӾႰݳHTML5୏ ᦓ҅੒ଫԭଫአ੶҅ᘒHTTPฎचԭTCPጱ̶ܐᦓҔHTTPฎ᩻෈๜փᬌܐ ҔTCPฎᶎݻᬳളጱ҅ݢᶌጱփᬌ੶کӧᓕතӧත஑҅ݎᦓ҅හഝփᬌฎӧݢᶌጱ҅ਙݝᓕ ܐ෸ᘱॠֵአጱҔUDPฎᶎݻ෫ᬳളጱփᬌ੶ܨ԰ᘶᗑӤ෈կጱ݌ݻփᬌ҅ࢩྌӞਧӧտฎ ګᦓ҅ฎFile Transfer Protocolጱᓌᑍ҅ਙጱ֢አฎአԭഴܐቘኧғFTPฎ෈կփᬌ ݇ᘍᒼໜғD D FTP ᒫ ᶭ126 ,! • ,,,! ! • : ,!, . • : ,,,能 ◦ ,! ◦ ,! • NSURLConnection : 美! • NSURLConnectionDataDelegate !, ! • NSURLConnectionDownloadDelegate :!, ӻଉአጱդቘ?پNSURLConnectionጱ ୗֵአፘݶጱොဩ̶فconversations)౲ࢶ୵ࢶຽ(graphic icons)զ્ տᦾ (encryptedੂےහഝګᬌጱಅํහഝֵአጱBase64 ̶ ᛗԭٌ՜ԫᬰ ԧଃᖫᎱጱ෈կփ׀ᦓᬮ൉ܐXMPP,عᦓӞ໏ֵአक़᮱ጱ HTTP̶ ইຎӧݢ᭿ܐ෈կփᬌ හഝ̶ ࢩྌ,ګදԫᬰץ׀ӞጱᳩጱXML෈կ,ࢩྌ෫ဩ൉ܔᦓጱොୗᤩᖫᎱԅӞӻܐXMPP හഝ:ګဌํԫᬰ Ӟᳯ̶᷌ ᫷ᬯٺᕳग़ӻතկՈ̶ ෛጱᦓਧԡྋࣁᎸᑪ,զ׀೜ํӞӻय़ࣳຝᑮӾਂࣁጱ හഝ൉ڹፓ ᦓܐXMPP,ݎ࢏ጱහഝၞᰁጱਂࣁ޾ᬪ60%ጱᤩ᯿॔᫨ۓᦓጱ๐ܐᵋ፳᭗ଉ᩻ᬦ70%ጱXMPP හഝᨮ᫹ॡ᯿: ᗌᅩ ᫫կ,ᩒრ݊ඪ೮ጱ ๶რฎग़໏ጱ,ֵ஑ֵ֦ӧտᵅԭᤩ“ᕬຝ”ጱࢯह̶ݎXMPPದ๞୏ ૲ࣁݱᐿᶾऒ;አړښݪ݊୏නრդᎱᦇلጱۓᦓ๶ୌ᭜݊૲ᗟਫ෸ଫአᑕଧ݊๐ܐአXMPP Ձ̵჋౭̵ᬱᑕᔮᕹፊഴᒵ̶ ग़໏௔: وݶૡ̵ٍ෈կܐᑤ̵׀ጱଫአᑕଧ,ᬮᚆአࣁᗑᕶᓕቘ̵ٖ਻מXMPPᴻԧݢአࣁਫ෸᭗ चᰂտ ̶ ୨௔֯:ٵଉᥠጱಘ઀ኧXMPPຽ ᚆ;ԅԧᖌ೮᭗᭐௔,ۑ۸ጱګᦓጱचᏐӤୌ᭜ਧܐݢֵձ֜Ոࣁ໐ஞێXML ޸ݷᑮᳵጱশ ݢಘ઀: ௔,૪ᛔ ଃԭ໐ஞXMPPದ๞ᥢ໒Ӿ̶قTLSᒵದ๞ጱݢᶌਞ ռXMPPᗑᕶ(ֺইࣁմӱٖ᮱ᗑᕶӾ),ᘒֵአSASL݊ل࢏ݢզᇿᒈԭۓᦓጱ๐ܐձ֜XMPP :قਞ Ո݊ᕟᕢᚆड़ഩഴ՜ժጱਫ෸փᦔ֛ḵ̶ ࢏,ֵӻۓ࢏̶ ձ֜Ո᮷ݢզᬩᤈᛔ૩ጱXMPP๐ۓզTCPփ᭓XMLහഝၞ,ဌํ Ӿ।Ԇ๐ ୌӞӻstream,XMPPڠضොୗฎמᦓ᭗ܐXMPP໐ஞ;؟ፘړ܈XMPPᗑᕶጱຝ຅޾ኪৼᮒկ වୗ:ړ ᒫ ᶭ127 3>    ಅ᧲VOIP҅੪ฎᗑᕶኪᦾ҅ፗളአ԰ᘶᗑ಑ኪᦾ҅ӧአᘙಋ๢ᦾᩇ ᕢ ۸ᕟٵቖ԰ᘶᗑٍ๋๦শጱದ๞ຽقIETFฎ҅ٵ2>    SIPฎୌᒈVOIPᬳളጱ IETF ຽ ᦓܐ᩸ݎ1>    SIPҁSession Initiation Protocol҂҅տᦾ sipฎՋԍҘ ⼒keyvalue被 ᗑᕶࢶᇆ॒ቘᳯ᷌Ӿெԍᥴ٬Ӟӻፘݶጱᗑᕶࣈ࣎᯿॔᧗࿢ጱᳯ᷌Ҙ 经HTMLXML ,每 •XMLHTMLHTMLXML 每 •XMLHTMLXML每HTML ◦ 每 ◦ 每 每 this is asamplestring每 ◦ 活出 每 情⼒/被每XML ◦ 每 ◦ 每 XML •XMLSGML⼒被每 每 XMLXML XMLWindows,Mac OS,Linux XMLXML• ?ڦ܄XMLฎՋԍ? XMLӨHTMLጱ ◦ 信 ◦ block ◦ session ◦ ◦ 信信 NSOperation ◦ ◦ NSURLSession: NSURLConnection NSURLConnection , NSURLConnection iOS 9.0 iOS • ?ڦ܄NSURLConnection&NSURLSessionጱ ᒫ ᶭ128     [webView stringByEvaluatingJavaScriptFromString:str3];                        "change.innerHTML = 'অ֦ጱ߶!';"; document.getElementsByClassName('change')[0];"     NSString *str3 = @"var change = 3. ๅද     [webView  stringByEvaluatingJavaScriptFromString:str2];     [webView  stringByEvaluatingJavaScriptFromString:str1];     NSString *str2 = @"word.remove();"; document.getElementById('word');";     NSString *str1 = @"var word = ᴻڢ . 2     [self.webView loadRequest:request];     NSURLRequest *request = [NSURLRequest requestWithURL:url]; withExtension:@"html"];     NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" ᫹ᗑᶭے . 1 iOSӾ᧣አHTML ҁ17҂WebViewӨJSԻ԰ 
 Line被每 • ⼒Ethernet信Serial ⼒被⼒IP被每 • 每 ⼒UDP被TCPUDP • ⼒TCP被信 ⼒FTP被信⼒Telnet被每 • ⼒SMTP被信 (OSI)每 IP(OSI)TCP • TCP/IPTCP/IP每TCP/IP TCP/IPࢥ੶ཛྷࣳ ᒫ ᶭ129 UIImagePickerControllerSourceTypePhotoLibrary;     pickerImg.sourceType = alloc]init];     UIImagePickerController *pickerImg = [[UIImagePickerController - (void)getImage{ // ᦢᳯፘٙ }     return YES;     }         [self performSelector:sel];         SEL sel = NSSelectorFromString(method); + range.length];         NSString *method = [str substringFromIndex:range.location     if (range.location != NSNotFound) {     NSRange range = [str rangeOfString:@"ZJY://"];     NSString *str = request.URL.absoluteString; (UIWebViewNavigationType)navigationType{ (NSURLRequest *)request navigationType: -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest: ࣁHTMLӾ᧣አOC     NSLog(@"%@", html); stringByEvaluatingJavaScriptFromString:str3];     NSString *html = [webView     NSString *str3 = @"document.body.outerHTML"; ಅํጱᗑᶭٖ਻ڊ7. ೭     [webView stringByEvaluatingJavaScriptFromString:str2]; =@"document.getElementById('footer').remove();";     NSString *str2 ᴻੲ᮱ڢ .6     [webView stringByEvaluatingJavaScriptFromString:str1];                         "h1.innerHTML='ᓌԡࠡࠡࠡࠡ';"; document.getElementsByTagName('h1')[0];"     NSString *str1 = @"var h1 = 5. දݒຽ᷌     [webView stringByEvaluatingJavaScriptFromString:str4];                      "document.body.appendChild(img);";                      "img.height = '80';"                      "img.width = '160';"                      "img.src = 'img_01.jpg';" NSString *str4 =@"var img = document.createElement('img');"     فൊ  .4 ᒫ ᶭ130 Class (3) Constructor object (3) id (2) Wrapper object (2) NSBlock (1) Function object (1) NSDate Date object NSArray Array object NSDictionary Object object NSNumber number, boolean NSString string NSNull null nil undefined Objective-C type JavaScript type ⽣每JSManagedValueJSValue每 JSOC每 • JSManagedValue:JSOC点每JS都想 
 每JSValuecontext每OCJS • JSValue:JSJSVirtualMachineHybird每JS JSValueJSContextcontext每 • JSContext:JSJSVirtualMachine #import "JSExport.h" #import "JSVirtualMachine.h" #import "JSManagedValue.h" #import "JSValue.h" #import "JSContext.h" 每 每WebViewJavascriptBridgeEasyJSWebView stringByEvaluatingJavaScriptFromStringJSOCURL⼿天 js每iOS7JSwebview做 iOS7iPhonejs每webview • JavaScriptCorewebkitJS每 JavaScriptCore ֵአ } completion:nil]; self presentViewController:pickerImg animated:YES]     ᒫ ᶭ131 ᦓොဩܐ//ਫሿ @synthesize sum = _sum; @implementation JSProtocolObj @end @interface JSProtocolObj : NSObject ᦓғܐ//ୌӞӻ੒᨝݄ਫሿᬯӻ @end @property (nonatomic, assign) NSInteger sum; - (NSInteger)add:(NSInteger)a b:(NSInteger)b; @protocol JSExportTest //ਧԎӞӻJSExport protocol • JSExport protocol: ᆐݸ౯ժፗളಗᤈᬯӻfunction҅᧣አጱ੪ฎ౯ժጱblock᯾ᶎጱٖ਻ԧ̶ context᯾ᶎٌ҅ਫ੪ฎ᫨ഘ౮ԧJSጱfunction̶کਂכ    ౯ժਧԎӞӻblock҅ᆐݸ     [self.context evaluateScript:@"add(2,3)"];     };         NSLog(@"---%@", @(a + b));     self.context[@"add"] = ^(NSInteger a, NSInteger b) {     self.context = [[JSContext alloc] init]; • block(JS function): • JavaScript -> Objective-C.JSOCblockJSExport protocol每     NSLog(@"---%@", @([n toInt32]));//---5 @3]];     JSValue *n = [self.context[@"add"] callWithArguments:@[@2,     [self.context evaluateScript:js];     NSString *js = @"function add(a,b) {return a+b}";     self.context = [[JSContext alloc] init]; 
 • Objective-C -> JavaScript JSExport每 • JSExport:JSOCOC JSVirtualMachine:JS没都想每 • ᒫ ᶭ132 JS都想每 • :OCARCJS都想 හݷਁ̶ڍJSExportAsᬯӻਡ᫨ഘ౮JSጱ ᦓӾਧԎጱฎadd: b:҅֕ฎJS᯾ᶎොဩݷਁฎaddB(a,b)̶ݢզ᭗ᬦܐᳯ̶᷌ڞ හ޸ݷᥢڍහ޸ݷ޾JSڍsum̶ࠔӞᥝဳ఺ጱฎOCጱ؀᧣አᬯӻ੒᨝ጱොဩ҅ଚਖ਼ᕮຎᩙ ᕮຎጱݒᰁ̶ࣁJSӾᬰᤈਂכጱොဩ҅ᬮํӞӻےᬮฎਧԎԧӞӻӷӻහፘ҅ܔdemoஉᓌ }     [self.context evaluateScript:@"OCObj.sum = OCObj.addB(2,3)"]; ᕳObjጱsumં௔؀    //JS᯾ᶎ᧣አObjොဩ҅ଚਖ਼ᕮຎᩙ     self.context[@"OCObj"] = self.obj; contextӾکے    //ਖ਼objႲ     };         NSLog(@"exception:%@",exception);         [JSContext currentContext].exception = exception; *exception) {     self.context.exceptionHandler = ^(JSContext *context, JSValue     //ᦡᗝ୑ଉ॒ቘ     self.context = [[JSContext alloc] init]; ୌcontextڠ//     ;[    [super viewDidLoad - (void)viewDidLoad { @implementation ViewController @end @property (nonatomic, strong) JSContext *context; @property (nonatomic, strong) JSProtocolObj *obj; @interface ViewController () //ࣁVCӾᬰᤈၥᦶ @end }     _sum = sum;     NSLog(@"--%@", @(sum)); { void)setSum:(NSInteger)sum) - ҅௳מܦ//᯿ٟsetterොဩො׎಑ }     return a+b; { NSInteger)add:(NSInteger)a b:(NSInteger)b) - ᒫ ᶭ133 @end @synthesize jsValue = _jsValue; @implementation JSProtocolObj @end @interface JSProtocolObj : NSObject ᦓғܐ//ୌӞӻ੒᨝݄ਫሿᬯӻ @end @property (nonatomic, strong) JSvalue *jsValue; JSጱ੒᨝ਂכ//አ๶ @protocol JSExportTest //ਧԎӞӻJSExport protocol ፡ӻdemo҅಩Ӥᶎጱᐏֺදӥғ JSValue੒᨝҅ࢩԅᬯ໏ॡ਻ฃ஗ሾ୚አԧ̶ਂכ2̵OC੒᨝ӧᥝአં௔ፗള     };         NSLog(@"%@",str); self.context[@"log"] = ^(NSString *str){ //ྋᏟጱ؉ဩ҅str੒᨝ฎJSᮎᬟփ᭓ᬦ๶̶ አ̶ᬯӻvalueᤩblockಅഔ឴҅ᬯᬟݶ໏Ԟտٖਂအᶂ҅contextฎᲀྪӧധጱ̶ ᬯӻฎblock᯾ᶎֵአԧक़᮱ጱvalue҅value੒context޾ਙᓕቘጱJS੒᨝᮷ฎ୩୚     };         NSLog(@"%@",value);     self.context[@"log"] = ^(){ inContext:self.context];      JSValue *value = [JSValue valueWithObject:@"ssss" //Ӟӻྲ᫾ᵌᠰጱ ๶ԧ̶ڊ ᬯӻդᎱ҅ӧአᛔ૩፡ԧ҅ᖫᦲ࢏᮷տ൉ᐏ֦ጱ̶ᬯӻblock᯾ᶎֵአself҅உ਻ฃ੪፡ }; inContext:self.context];      JSValue *value = [JSValue valueWithObject:@"aaa" self.context[@"block"] = ^(){ //Კ᧏դᎱғ 1̵ӧᥝࣁblock᯾ᶎፗളֵአcontext҅౲ᘏֵአक़᮱ጱJSValue੒᨝̶ 每每 JavaScriptCoreAPIOCJS ᒫ ᶭ134 JSVirtualMachine determines reachability. Manually adding or removing the managed reference in the The owner of the managed reference is reachable in Objective-C. The JSManagedValue's JavaScript value is reachable from JavaScript ӷӻ๵կҁӧᘉᦲԧ҅ᘉᦲԧௗௗጱѺ҂ғ collection weak reference̶֕ฎਙଆۗ౯ժ೮ํJSValue੒᨝஠ᶳݶ෸ჿ᪃Ӟӥ JSManagedValue ๜᫝੪ฎ౯ժᵱᥝጱ୧୚አ̶አਥොጱᦾ๶᧔ݞgarbage ᧔ጱٖਂᓕቘᬀۗ੒᨝JSManagedValue̶ڹӾጱweak̶ᘒฎԏ ݢ̶୮ᆐ҅ӧฎ౯ժOCܨெԍᥴ٬ᬯӻᳯ᷌Ҙ౯ժݝᵱᥝ಑Ꮘobj੒JSValue੒᨝ጱ୚አ ኸԧJSጱࢧ᧣̶ᬯ໏੪୵౮ԧ஗ሾ୚አ̶כobjᬯᬟԞ ԧobj҅ᘒӬਂכᕳԧobj҅ො׎objӥེࢧ᧣ᕳJSҔኧԭJSᮎᬟ؀૩ጱࢧ᧣callbackᩙ ኸԧփᬰ๶ጱobj๋҅ݸ҅JSਖ਼ᛔכJS੒᨝҅؀አJSොဩ҅ᬰᤈᩙ᧣҅ܔӤᶎጱֺৼஉᓌ }    [self.context[@"setObj"] callWithArguments:@[self.obj]];     //᧣አJSොဩ }"];     obj.jsValue=callback;     this.obj = obj;     function setObj(obj) {    @"function callback (){};    [self.context evaluateScript: contextӾک᫹JSդᎱے//    ;{     ;(        NSLog(@"exception:%@",exception         [JSContext currentContext].exception = exception; *exception) {     self.context.exceptionHandler = ^(JSContext *context, JSValue     //ᦡᗝ୑ଉ॒ቘ     self.context = [[JSContext alloc] init]; ୌcontextڠ//     ;[    [super viewDidLoad - (void)viewDidLoad { @implementation ViewController @end @property (nonatomic, strong) JSContext *context; @property (nonatomic, strong) JSProtocolObj *obj; @interface ViewController () ࣁVCӾᬰᤈၥᦶ// ᒫ ᶭ135 @property (nonatomic, strong) JSProtocolObj *obj; @interface ViewController () //ࣁVCӾᬰᤈၥᦶ @end }     withOwner:self]; addManagedReference:_managedValue     [[[JSContext currentContext] virtualMachine] managedValueWithValue:jsValue];     _managedValue = [JSManagedValue { - (void)setJsValue:(JSValue *)jsValue //᯿ٟsetterොဩ @synthesize jsValue = _jsValue; @implementation JSProtocolObj @end @property (nonatomic, strong) JSManagedValue *managedValue; JSValueਂכӞӻJSManagedValueአ๶ے//Ⴒ @interface JSProtocolObj : NSObject ᦓғܐ//ୌӞӻ੒᨝݄ਫሿᬯӻ @end @property (nonatomic, strong) JSValue *jsValue; JSጱ੒᨝ਂכ//አ๶ @protocol JSExportTest //ਧԎӞӻJSExport protocol ጱդᎱදӥғڟڟ಩ (id)owner``` ๶ಋۖᑏᴻ՜ժԏᳵጱᘶᔮ̶ ᔮ̶᭗ᬦ- (void)removeManagedReference:(id)object withOwner:ى୚አ (void)addManagedReference:(id)object withOwner:(id)owner๶ୌᒈᬯӻ୧ ୌJSManagedValue੒᨝̶᭗ᬦJSVirtualMachineጱොဩ-ڠ(id)owner (JSManagedValue )managedValueWithValue:(JSValue )value andOwner: ဩ``` + (JSManagedValue )managedValueWithValue:(JSValue )value; ጱӷӻො׀Ӿਂࣁ҅ݶ෸ JSManagedValue ጱownerࣁOCӾԞਂࣁ̶౯ժݢզ᭗ᬦਙ൉ ጱJS੒᨝஠ᶳࣁJSਂכJSValue҅ᮎ᯾ᶎਂכJSManagedValue ଆۗ౯ժ҅ܔ఺௏உᓌ ᒫ ᶭ136 context҅ᆐݸᬰᤈ੒JS඙̶֢ UIWebView ᬰᤈ඙֢҅౯ժӧٚ᭗ᬦURLೝ౼҅౯ժፗളݐ UIWebView ጱ ӥᶎ౯ժ፡፡ই֜੒̶מ᭗ᬦӤᶎጱdemo҅ଫᧆ૧ӧग़ԧᥴOCই֜޾JSᬰᤈ᭗ • UIWebView 每 JSVirtualMachine每JSVirtualMachine • :JavaScriptCore contextlock ᔮԧ҅ݢᚆտ୚᩸୑ଉ̶ى࣯࣍ࢧත੪ӧᎣ᭲՜ժԏᳵጱ҅؀ ฎဌᳯ᷌ጱ̶֕ฎইຎࣁӧݶጱ JSVirtualMachineփ؀࣍ࢧතӥ҅ಅզፘ԰ԏᳵփ Ӟӻ JSVirtualMachineݢզᬩᤈग़ӻcontext҅ኧԭ᮷ฎࣁݶӞӻञٖਂ޾ݶӞӻ࣯ 3̵ӧᥝࣁӧݶጱ JSVirtualMachine ԏᳵᬰᤈփ᭓JS੒᨝̶ JSValue̶ ਂכොဩ̶ਫᴬӧտٟᬯԍൡጱ঵̶̶̶۠ଫᧆ໑ഝࢧ᧣ොဩփᬰ๶݇හ҅ᬰᤈ JSValue҅ಅզ᯿ٟԧ setter ਂכአ JSManagedValue๶ڊဳғզӤդᎱݝฎԅԧᑱ }    [self.context[@"setObj"] callWithArguments:@[self.obj]];     //᧣አJSොဩ    }"];    obj.jsValue=callback;    this.obj = obj;    function setObj(obj) {    @"function callback (){};    [self.context evaluateScript: contextӾک᫹JSդᎱے//    ;{     ;(        NSLog(@"exception:%@",exception         [JSContext currentContext].exception = exception; *exception) {     self.context.exceptionHandler = ^(JSContext *context, JSValue     //ᦡᗝ୑ଉ॒ቘ     self.context = [[JSContext alloc] init]; ୌcontextڠ//     ;[    [super viewDidLoad - (void)viewDidLoad { @implementation ViewController @end property (nonatomic, strong) JSContext *context;@ ᒫ ᶭ137 NSOperationQueue 才:每GCD 每Instruments :⽅:GCDNSOperationQueueGCD 话:NSOperationQueueKVO每 每GCD每 ⼒-被NSOperationQueue 每GCD每 才:GCDFIFONSOperationQueue NSOpertaionQueueGCDGCD!,:⽅ : ?ހ໏؉ጱቘኧ ᦫ౯՜ժᬯޞሿࢵक़ጱय़ᇍ՜ժग़ᕚᑕ᮷ฎአNSOperation? ֦ᚆݎ ֦ժᶱፓӾԅՋԍग़ᕚᑕአGCDᘒӧአNSOperationޫ? ֦ํဌํ ҁ18҂ग़ᕚᑕ ᧗ဳ఺ᕚᑕฎӧฎԆᕚᑕ̶҅ײ context҅֕ฎ᮷ฎݶӞӻJSVirtualMachine̶ইຎJS᧣አOCොဩᬰᤈ඙֢UIጱ෸ ᫹ਠ᮷ฎӞӻෛጱےӤᶎአԧᐺํં௔҅ݢᚆտᤩ᝘ຎᕳ೏ԧ̶ᬯᬟᥝဳ఺ጱฎྯӻᶭᶎ } "]; valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext     self.context = [webView { - (void)webViewDidFinishLoad:(UIWebView *)webView ࣁUIWebViewጱfinishጱࢧ᧣Ӿᬰᤈ឴ݐ ᒫ ᶭ138 ,每 ,,,能 • 友,, • 每 • ,时, 每 • 每 每 • , • 每 ޾ᘶᔮ?ڦ܄ᕚᑕӨᬰᑕጱ 
 ◦ 信信信 ◦ 4信信⾥信 ◦ 新 ◦ 有⼦ • ⼼ • IPC 有 • 有 ▪ 每 经p1 ◦ :() • • UNIX ҘמunixӤᬰᑕெԍ᭗ ᧇᥴGCDྒᲁ GCD每 每每”Instruments :两“97% 每GCD 话:UI说NSOperationQueue ᒫ ᶭ139 ṛᕆጱොୗ๶॒ቘ҅ྲইNSSpinLock̵@syncronizedᒵ ጱ඙֢҅ᬮᵱᥝֵአๅقᦤᕚᑕਞכ੒ԭᥝᕷ੒҅قᦤᕷ੒ጱᕚᑕਞכֵአatomicଚӧᚆ ᭇݳٖਂ᫾ੜጱᑏۖᦡ॓҅قnonatomicғᶋᕚᑕਞ ᲁےᵱᥝၾᘙय़ᰁᔮᕹᩒრ๶ԅં௔҅قatomicғᕚᑕਞ ᲁ̶ےnonatomicӧտԅsetterොဩ code } ᲁ̶ ֵٍ֛አ @synchronized(self){//ےatomicܻৼ඙֢҅ᔮᕹտԅsetterොဩ ӧฎጱ̶ ҘހጱقֵአatomicӞਧฎᕚᑕਞ • : UI, • : dispatch_async(dispatch_get_main_queue(), ^{ }); 3. @synchronized每 2. NSLock; 1. POSIX; 每 • : : ⼦每 ᕚᑕࢧ᧣ԆᕚᑕොဩฎՋԍ,ํՋԍ֢አ? ړ?ᐿᥴ٬ොໜ?֜ԅᕚᑕݶྍ,ই֜ਫሿጱپᳯ᷌ጱق᧨᧨ग़ᕚᑕਞ ◦ OCNSOperationNSOperationQueue⼒GCD被 ◦ CGCD⼒被 ◦ OCNSThread ◦ CPOSIX#include • ◦ MachMach Mach ◦ Mach • 信 iOSग़ᕚᑕጱବ੶ਫሿҘ 被A⼒被每) B⼒点被NSMachPort有B⼒点 (A⼒被NSMachPortArunloop每 
• NSMachPort • performSelector:onThread:withObject:waitUntilDone: ҘמiOSᕚᑕᳵெԍ᭗ 
 每 ,, • ᒫ ᶭ140 ◦ ,每 3. ◦ 著每 UI被每 ◦ ⼒ ◦ 每 ◦ 每 2. 1 2 3 4 :,(FIFO/ First In First Out) ◦ != 每!每 ◦ 每 ◦ block每 ◦ CGD CPU每 1. iOS4 NSThread⼒ios2.0被 C⽆ ᧇᕡ᧨᧨GCD I/O⼒AIO被 • ګOCӾ୑ྍֵአጱߺᐿԪկཛྷࣳ,iOSӾ୑ྍਫሿ๢ 4. GCD 3. NSOperation 2. NSThread (SEL)aSelector withObject:(id)arg 1. NSObject // -(void)performSelectornBackground/OnMainThread: • • 每 ◦ 每 ◦ 每 ◦ ,,每 • 每 ◦ 信 ◦ ◦ 知 ◦ • ᐿਫሿग़ᕚᑕጱොဩҘپ ጱቘᥴ(ग़ᕚᑕጱঅ॒҅ग़ᕚᑕጱ֢አ)ҘiosӾํݎ੒ग़ᕚᑕ୏֦᧨᧨ ᒫ ᶭ141 
 dispatch_group_t group = dispatch_group_create(); // 
 . ,.(dispatch_group_t), ◦ ::能;:能 1. 
 // 2... 
 (2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ GCD做:dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) 
 // 2selfrun 
 NSObject :[self performSelector:@selector(run) withObject:nil afterDelay:2.0]; 
 1. ෛ඙֢ڬԆᕚᑕ҅ಗᤈUIک// ࢧ dispatch_async(dispatch_get_main_queue(), ^{ // ಗᤈᘙ෸ጱ୑ྍ඙֢... dispatch_async(dispatch_get_global_queue(0, 0), ^{ ◦ ((能),UI): 每 4. 能⼒被UI ◦ ⼒'''',被 ◦ 动 ◦ 动 ◦ 动 ◦ 动 ◦ 3. ◦ "": '',. ◦ "": '',. 2. """": ◦ '':dispatch_async(dispatch_queue_t queue, <#^(void)block#>) ◦ '':dispatch_sync(<#dispatch_queue_t queue#>, <#^(void)block#>) 1. 做 ◦ 每 release每 ARC,MRC ◦ ᒫ ᶭ142         // ݳଚࢶᇆ dispatch_group_notify(group, dispatch_get_main_queue(), ^{ ᫹ࢶᇆ3 */ });ے*/ }^ ,dispatch_group_async(group, queue ᫹ࢶᇆ2 */ });ے*/ }^ ,dispatch_group_async(group, queue ᫹ࢶᇆ1 */ });ے*/ }^ ,dispatch_group_async(group, queue dispatch_group_t group = dispatch_group_create(); dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ); dispatch_queue_t queue = ླ҅੪տಗᤈMain Dispatch QueueӾጱᕮ๳॒ቘጱblock̶ ᮱ಗᤈਠقGlobal Group Queue,ᬯԶblockইຎکblockےֵአDispatch Group᭄ ࢶᇆ҅ᆐݸࣁ᮷ӥ᫹ਠ౮ݸݳ౮Ӟୟෆࢶ҂ ᫹ग़ୟےই֜አGCDݶྍᝑଗӻ୑ྍ᧣አҘҁই໑ഝᝑଗӻurl୑ྍ ឴ݐ̶ ୌ҅឴ݐොୗ᭗ᬦ᧣አොဩdispatchgetmain_queue๶ڠqueue੪ݢզԧ҅ӧᵱᥝ౯ժ •    ੒ԭmain queue੪ฎࣁԆᕚᑕӾጱ҅ࢩྌӞਧտࣁԆᕚᑕӾಗᤈ̶឴ݐmain main threadӾಗᤈ̶ ୌጱ҅ᮎԍ੪ӧտࣁڠୌጱ҅ᮎԍಅಗᤈጱդᎱ੪ฎࣁԆᕚᑕӾಗᤈ̶ইຎฎࣁৼᕚᑕӾ ڠ•    ੒ԭqueueӾಅಗᤈጱդᎱӧӞਧࣁmain threadӾ̶ইຎqueueฎࣁԆᕚᑕӾ ԍҘ GCDጱqueue̵main queueӾಗᤈጱդᎱӞਧฎࣁmain thread 10) ◦ Dispatch Source (MACH,MACH, ◦ Dispatch Queue block() • GCDDispatch QueueDispatch Source • GCDAPIlibdispatch •iOSOS XXNUGCDXNU GCDٖ᮱ெԍਫሿጱ 
 }); 
// reload Data 
 // 
 dispatch_group_notify(group, dispatch_get_main_queue(), ^{ 
 }); 
 // longTime2 
 dispatch_group_async(group, queue, ^{ // 2 
 }); 
 // longTime1 
 dispatch_group_async(group, queue, ^{// 1 
 dispatch_queue_t queue = dispatch_get_global_queue(0, 0); // ᒫ ᶭ143 • dispatch_get_current_queue每API每 ᝘ຎԅՋԍᥝଳ୒dispatch_get_current_queueҘ });     // ݳଚࢶᇆ dispatch_group_notify(group, dispatch_get_main_queue(), ^{ ᫹ࢶᇆ3 */ });ے*/ }^ ,dispatch_group_async(group, queue ᫹ࢶᇆ2 */ });ے*/ }^ ,dispatch_group_async(group, queue ᫹ࢶᇆ1 */ });ے*/ }^ ,dispatch_group_async(group, queue dispatch_group_t group = dispatch_group_create(); dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_queue_t queue = ֢නࣁdispatch_group_notifyӾਫሿ̶ GroupӾ҅ਖ਼ݳଚ౮य़ࢶጱ඙کف؉ဩғ᭗ᬦdispatch_group_t๶ਫሿ҅ਖ਼ྯӻ᧗࿢න ᮱ӥ᫹ਠ౮ݸ҅಍ᚆݳଚ౮य़ࢶ̶قୟय़ࢶ҅੪ᵱᥝ୑ྍ ᚆ̶ྲই҅ӥ᫹10ࢶᇆݸݳ౮Ӟۑ᮱ਠ౮ݸ҅಍ಗᤈ຤ӞقຉݢᎣ҅10ӻ᧗࿢ᥝړ՗᷌ፓ ਫሿҘ ಅํࢧଫԏݸಗᤈݸᖅ඙֢҅ই֜کᭆ10ӻᗑᕶ᧗࿢҅ᆐݸٚളතݎ Ӿ҅ᛔᆐ੪ฎೲᶲଧ๶୑ྍಗᤈԧڜԀᤈᴚکනۓᥝ࿢ᶲଧಗᤈ҅ᮎԍݢզਖ਼ձ Run loopಗᤈਠླ̶کಗᤈ҅ፗکጱդᎱ஑ӧ run loop̶֕ฎᬯ໏؉տᦏݸᶎڊਠ౮҅ᆐݸࣁrunloopӾᦏٌᒵஇ҅୮ਠ౮෸಍ᭅވฎ ۓ୮ᆐ҅౯ժᬮݢզֵአᶋଉᘌॺጱොဩ๶॒ቘ҅᭗ᬦࢥӻݒᰁ๶ຽᦩa̵b̵c̵dࢥӻձ 11.    }); 10.        // ࣁa̵b̵c̵d୑ྍಗᤈਠ౮ݸ҅տࢧ᧣ᬯ᯾ 9.    dispatch_group_notify(group, dispatch_get_main_queue(), ^{ 8.     d */ });ۓ7.    dispatch_group_async(group, queue, ^{ /*ձ c */ });ۓ6.    dispatch_group_async(group, queue, ^{ /*ձ b */ });ۓ5.    dispatch_group_async(group, queue, ^{ /*ձ a */ });ۓ4.    dispatch_group_async(group, queue, ^{ /*ձ 3.    dispatch_group_t group = dispatch_group_create(); dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 2.    dispatch_queue_t queue = ሿғ ጱොୗ੪ฎ᭗ᬦGCDጱgroup๶ਫܔෙ᮷ಗᤈਠ౮๋ᓌڣ1.    ੒ԭᬯࢥӻ୑ྍ᧗࿢҅ᥝ ຎᵱᥝa̵b̵c̵dᶲଧಗᤈ҅ᧆই֜ਫሿҘ ෙa̵b̵c̵d᮷ਠ౮ಗᤈҘইڣa̵b̵c̵d 4ӻ୑ྍ᧗࿢҅ই֜ํ ;({ ᒫ ᶭ144 • NSOperation每 NSOperation queue? ⼒isExecuted被信⼒isFinished被⼒isCanceld被 ◦ NSOperationQueueKVOoperation . • NSOperationQueue NSOperation • •// op2op1 [op2 addDependency:op1]; •// op3op2 [op3 addDependency:op2]; 每 • NSOperationQueue . • NSBlockOperation start>1动 =1 每 • NSInvocationOperationstart • , Block ,. • : NSInvocationOperation() NSBlockOperation(); • NSOperation: ,,.() ԭNSOperation:ى “”做每 B信Ca. b.A • BC ”被每 • BA⼒“”信“”信“ 每 Ba. b. • AsignalB 每 • Asignal做 每 • ABlock • ABlock每 • 新 • http://www.dreamingwish.com/article/gcd-guide-dispatch-once-2.html⼒被 ইຎᦏ֦๶ਫሿ dispatch_once֦҅տெԍ؉Ҙ ᒫ ᶭ145 每 • scorllView • 每 ҘޫڜԅՋԍᥝݐၾ/௩॔ᴚ • NSThread NSObject • NSThread • GCD // • GCD block , NSThread @selector • ڦ܄GCDӨNSThreadጱ ▪ NSOperation ▪ NSOperation ▪ KVONSOperationoperation每 ▪ . ▪ ▪ ▪ 3. NSOperation 做 2. NSOperation⼒被⼒被 1. NSOperationiOS2.0iOS4.0NSOperation • NSOperation ▪ GCD FIFO经 ▪ ▪ ▪ 3. GCDNSOperation /做每 2. GCD⼒block被⼒信信信被 1. GCDiOS4.0cpuc每 GCD • ڦ܄NSOperationӨGCDጱ ᒫ ᶭ146 每 NSOperationQueueNSOperationNSThread每GCD NSThread每 • UI每GCDBlockblock • B ᯈᕚᑕړᕆضD. GCDݢզ໑ഝӧݶս C. NSOperationQueueฎྲNSthreadๅṛ੶ጱ੗ᤰ ᔰزදUIץB. ݢզࣁৼᕚᑕӾ A. GCDಅአጱ୏ᲀᥝྲNSThreadय़ ԭᕚᑕᓕቘᲙ᧏ጱฎىӥᶎ ੪ݢզԧ̶ڜԆᴚکےࣁԆᕚᑕಗᤈդᎱ҅ݝᥝਖ਼੗ᤰդᎱጱNSOperation੒᨝Ⴒ Ӿ҅ਫሿग़ᕚᑕ̶ ڜୌጱᴚڠNSOperationQueueکےֵአNSOperationጱৼᔄ੗ᤰ඙֢҅ٚਖ਼඙֢Ⴒ NSOperationQueueғ ^{}); dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), NSEC_PER_SEC)), dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * դᎱࣁߺӻᕚᑕಗᤈ҂ғګ୊᬴ಗᤈդᎱҁ୊᬴·ݢզഴ ࣁԆᕚᑕಗᤈդᎱ҅dispatch_async(dispatch_get_main_queue(), ^{}); ୌৼᕚᑕ̶ڠ()හdispatch_asyncڍአ୑ྍڥ GCDғ performSelector:onThread:withObject:waitUntilDone:ොဩҔ ইຎమ୊෸ಗᤈդᎱݢզ᧣አ ࣁԆᕚᑕಗᤈդᎱ҅੪᧣አperformSelectorOnMainThreadොဩ̶ ݸݣᕚᑕ"]; [self performSelectorInBackground:@selector(run:) withObject:@"౯ฎ ๶ጱৼᕚᑕ"];ڊᐶړwithObject:@"౯ฎ [NSThread detachNewThreadSelector:@selector(run:) toTarget:self selector:@selector(run:) object:@"nil"]; NSThread *thread = [[NSThread alloc]initWithTarget:self ୌᕚᑕጱӣᐿොဩғڠNSThread NSOperationQueue;فےNSOperation,ᆐݸਖ਼ٌ ୌ̵ֵአGCDጱdispatch̵ֵአৼᔄ۸ጱڠୌํӣᐿොဩғֵአNSThreadڠᕚᑕ ฎՋԍ?ইຎమ୊෸ಗᤈդᎱ̵ොဩ݈ฎՋԍ? ୌᕚᑕጱොဩฎՋԍ?ইຎࣁԆᕚᑕӾಗᤈդᎱ҅ොဩڠObject CӾ ᒫ ᶭ147 次每 经 AVAudioPlayer 经 AVAudioPlayer 经 更 AVAudioPlayer 经 AVFoundation.framework ֵአAVAudioPlayerᔄ᧣አߺӻ໛ຝ̵ֵአྍṈҘ OpenAL Audio Queue Services AVAudioPlayer SystemSound Services ᐿඎනᶪ᷇ጱොဩҘپԧ׀iPhone OSԆᥝ൉ ҁ19҂ग़ড়֛ ᒫ ᶭ148 1.经 3.controller有context⼒dictionary被context到 2. 1. notification 4.每⼒被⼒被 每 3.controllerdelegatedelegate crash 2.delegatenil每 delegate 1.1.经2.controllerdelegate经3.delegate 8.view⼒被 7.每delegate给controller 6./每 5.delegates 4.经 3.controller 2.delegate/ 1.每delegate对每 delegate ڦ܄ຉDelegate̵Notification̵KVOጱړ՗ᦡᦇཛྷୗጱ᥯ଶ ҁ20҂ᦡᦇཛྷୗ 2.经 3.经 4.controller经 5.controller信UserInfo dictionary keys每 经 6.controller给⼒delegate被每 KVO 1.每modelview经 2. ⼒SKD被经 3.经 4.key paths活经 5.最 6.每 1.strings每经 2.经 3.“IF”每 经 4.每 1. delegateNSNotification每 delegatenotificationdelegate delegate每-windowShouldClose:yesno每 delegate should每delegate 每notification ᒫ ᶭ149 每notification did NSWindowDidResizeNotificationNSWindownotification 每 2信KVONSNotification delegateKVONSNotificationdelegate 1被经2被delegate 每每 3每 KVO对对每 controller每 iOS每 每每Userlnfo dictionarieskeys有 每 每 对controllers 每app每 crash 每 controller有每有 controllers每delegation notification每controller每 每 每 ⼈view model每delegate每 delegateapp每 notification每 Ջԍฎᦡᦇཛྷୗ • 每 每 每 每 ᒫ ᶭ150 ᒫ ᶭ151 image image image image image image image image image image image image ֺጱҘ)ܔᦤכࣁߺ᯾Ҙunlock ޫҘGCD ฎெԍڦ܄ ֺཛྷୗጱᦡᦇғGCD ොୗ޾ݶྍᲁොୗጱܔֺොဩ(౲ᘏܔಋٟӞӥ ◦ 每 ◦ Singleton Singleton 1. 经每 果果经经 1. 每每 每 ֺฎՋԍҘܔ 每上每 “” 
 • ⼒NSWorkspace被每 init... 每 
 • 每 • + (type)className...⼒ className被每 每 
 • 更 ොဩฎՋԍҘܯᔄૡ ()信每 信信⼒Interpreter被信信信 ◦ 信信⽽信信 信每 ◦ 信信信信信 ◦ 信信信信每 • 23每 ᔄړᦡᦇཛྷୗጱ ᒫ ᶭ152 每 每MVC机 ModelController们View Model信View信Controller • MVC每Model-Controller-View • D D դᎱṛපሲ C ᫾֗ጱኞ޸ޮ๗౮๜ B ṛ᯿አ௔޾ݢᭇአ௔ A ֗ᘠݳ௔ MVCսᅩӧྋᏟጱฎ 
 iphone发. ,.QQ⼿天, .,,, • :, • : • ,,, 每 每MVC,MV, MVCModel-View-Controller,M,V,C• ?ހጱᦡᦇཛྷୗڦጱ?֦ᬮᆧఀٌ՜ጱOCᦡᦇཛྷୗ౲ ᧨᧨֦੒MVCጱቘᥴ?ԅՋԍᥝአMVC?ࣁCocoaӾMVCฎெԍਫሿ 
 NotificationCenterNotificationCenter post每 • KVO经Notification • iOSKVONotification每 每 • ⼒Observer被 ᓌᥝൈᬿᥡ੊ᘏཛྷୗ҅ଚᬩአྌཛྷୗᖫٟӞྦྷդᎱҘ ᒫ ᶭ153 ݇ᘍᒼໜғ ᦇཛྷୗٌ݊ࣁᶱፓӾጱଫአ̶ ጱฎᬯԶᦡᦇཛྷୗࣁᶱፓӾই֜ଫአ̶ࢩྌ҅ᒟᘏᦊԅᬯӻᳯ᷌ᵌୗࣈ᧔กԧଫᧆࢧᒼᦡک ލጱӧՐՐฎᦡᦇཛྷୗጱݷਁ҅ๅమکލᶎᦶਥ๋অמᶱፓӾֵአԧஉग़ጱᦡᦇཛྷୗ҅౯ፘ ԧߺԶᦡᦇཛྷୗҘک֦ࣁ֦ጱᶱፓӾአ • View View (View) • 美 Model () • 美 Model (美model) ) • Data Source Protocols (UITableViewUICollectionView ߺԶ᭔ஆݢզᦏ ViewController ጔӥ๶Ҙ • 有 • MVCController • iOS • • RAC做 ReactiveCocoa ̶ګԧӞᐿஉො׎սᵝጱᕬਧ๢׀ReactiveCocoa൉ ٟय़ᰁጱselectorդᎱ̶ iOS҅ဌํॡঅጱහഝᕬਧොဩ҅ݢզֵአKVO҅֕ইຎᵱᥝᕬਧጱં௔ॡग़ጱᦾ҅ᵱᥝᖫ ݢզፗളֵአCoocoa Binding҅੒ԭ҅ݎ੒ԭOS X ୏҅ګMVVMᵱᥝֵአහഝᕬਧ๢ ᗌᅩғ ො׎ၥᦶ ᐶړقդᎱ޾ኴᶎਠ ੝VCጱ॔๥௔ٺ դᎱᓌ၄սᵝ กႴศړے੶ེๅ սᅩғ View每 ModelViewModelView⼈ •MVCControllerModelView经MVVMViewModel成 ViewController 美信信美ViewModel •MVVM⽆MVCC⼒ViewController被 Ꮁ҅ୌᦓ᯻አReactiveCocoaପਫሿҔ ই֜ቘᥴMVVM໛ຝ҅ਙጱսᅩ޾ᗌᅩࣁߺҘᬩአྌ໛ຝᖫٟӞྦྷդ ᒫ ᶭ154 
 • ,, • 之 • :,View , • KVC/KVO:,KVCtabbar,KVO • :,,⽆ • MVC:,MVC • : • ,, ԧߺԶᦡᦇཛྷୗҘک֦ࣁ֦ጱᶱፓӾአ ̶ֺܔአٖਂ҅ࢩྌӧݢᄂአܛտ᯽න҅ᬯտ ୌ҅ෆӻAppֵአᬦᑕ᮷ӧڠֺӞ෮ܔฎਙԞտํդհጱ̶֕҅ڥֺᏟਫᕳ౯ժଃ๶ጱ׎ܔ Ӿ᭗ଉӧտ݄᯿ٟٖਂᓕቘොဩ̶ݎ౮ጱ҅ࢩྌࣁਫᴬ୏חֺฎᕅਧܔ•    ٌེ҅ኧԭ ୌጱ̶ڠֺኞ౮ොဩฎӧտٚܔ ֺ҅ٚ᧣አܔୌӞ̶ེইຎӧੜஞᲀྪԧڠֺ੒᨝ݝտᤩܔᦤכdispatch_once๶ֵአ҅ ጱٟဩ҅ᕮݳقᐿ҅᭗ଉጱٟဩฎचԭᕚᑕਞپֺٟဩํঅܔ҅ض•    Ḓ ݇ᘍᒼໜғ ࢧᒼ̶٭य़ਹ໑ഝᛔ૩ጱఘ ጱᳯ᷌҅ܔՁ౯ժጱහഝ̶ᬯݝฎᓌوੴ᮷ݢقֺࣁᶱፓӾጱฎ஠ӧݢ੝ጱ҅ਙݢզֵ౯ժܔ ֺտํՋԍ୕ᒒҘܔֺ҅ܔই֜ਫሿ ᬮํஉग़ጱᦡᦇཛྷୗ҅ӧᬦٌਙଚӧฎᮎԍଉአ̶҅މ੪᧔ᬯԍग़ አKVC/KVOᦡᦇཛྷୗ੪உො׎ԧ̶ֵײ୮ݒ۸෸҅ᵱᥝๅෛUIดᐏ҅ᬯ෸ ጱݒ۸҅؀modelӾጱ຤ӻં௔ލտֵአKVC/KVOᦡᦇཛྷୗ̶ࣁᶱፓӾ҅౯ᵱᥝፊײᬯ෸ ፘଫጱදݒ҅ڊጱݒ۸ᘒ؉؀຤ӻᔄጱં௔ލᵱᥝፊײ•    KVC/KVOᦡᦇཛྷୗғํጱ෸ ᮱ฎಘ઀ጱᔄොဩ҅ݢᓌ۸உग़ጱդᎱ̶ق᮷૪ᕪ੗ᤰ౮Ӟॺ҅ ฎኞ౮ഴկጱAPI҅ڦᦡᦇཛྷୗ҅ᇙܯᦡᦇཛྷୗғࣁ౯ጱᶱፓӾֵአԧय़ᰁጱૡܯ•    ૡ ᔮֵ҅አ᭗Ꭳๅঅਫሿ̶ىᵱᥝֵአ᭗ᎣҔ੒ԭग़੒ग़ጱ Ӿฎ஠ӧݢ੝ጱ҅੒ԭ᪜ཛྷࣘጱᔄԻ԰҅ݎ•    ᭗Ꭳ(NSNotification)ཛྷୗғ᭗Ꭳࣁ୏ አMVVM̵MVPᒵཛྷୗ̶ ᘏ᯻ݎ୏ړᶱፓ᮷ฎचԭMVCᦡᦇཛྷୗጱ҅ሿࣁํӞ᮱ړ•    MVCᦡᦇཛྷୗғሿࣁᕷय़᮱ ੴֵአ̶قᵱᥝ௳מᔄ҅ࢩྌአಁጱ ֺܔ̶ֺࣁᶱፓӾᕪଉտਖ਼አಁහഝᓕቘ੗ᤰ౮Ӟӻܔጱ׀NSUserDefaults੪ฎ᝘ຎ൉ ֺฎ஠ӧݢ੝ጱ̶ྲইUIApplication̵ܔֺᦡᦇཛྷୗғࣁᶱፓӾ҅ܔ    • ᒫ ᶭ155 ֺܔ- ਠෆ } 
return handle; 
} 
  }       handle = [[DataHadle alloc] init];             @synchronized(self){  if (nil == handle) { 
每 // 每每 
{ 
• (DataHandle *)sharedDataHandle // 中 sharedDataHandle 每 
// 中 每 每 static DataHandle *handle = nil; 
每 // 每友 2信 
 • (DataHandle *)sharedDataHandle; // 每 shared + 1信 
• 中 ֺԡٟܔ , • 
()<#<#SingletonClass static let sharedInstance : <#SingletonClass#> = // Swiftᇇ   }   return sharedInstance;   });   sharedInstance = [[self alloc] init];   dispatch_once(&onceToken, ^{   static dispatch_once_t onceToken;   static id sharedInstance = nil;   {   +(instancetype)sharedInstance OCᇇ //   
 : • ᒫ ᶭ156 } 
return self; 
{ 
• (id)mutableCopy } 
return self; 
{ 
• (id)copy } 
return [DataHandle sharedDataHandle]; 
{ 
• (instancetype)allocWithZone:(struct _NSZone *)zone allocWithZone alloc 每 
回 每 3信 allocWithZone copy mutableCopy copyWithZone 
 return handle; 
} 
•   } • ୌ҅տྒ஗ሾ̶ڠ [෸ ֵአ [[DataHandle alloc] init ֺ੒᨝ܔୌڠֺᔄ᯾ᶎ᯿ٟԧ allocWithZone ොဩ ҅ࣁܔ•       // ইຎ ࣁ ஗ሾྒع•       handle = [[super allocWithZone:nil] init]; // ᭿   if (nil == handle) { 
 @synchronized(self){ 
 2信 
 • (DataHandle *)sharedDataHandle; // 每 shared + 1信 copyWithZone,retain,retainCount,releaseautorelease 
 allocWithZoneallocinit 
nil 
,nil 每 copy mutableCopy copyWithZone 每 
 • (id)copyWithZone:(struct _NSZone *)zone
 {
 return self;
 }
 4信 alloc retain release autorelease retainCount • (instancetype)alloc
 {
 return [DataHandle sharedDataHandle];
 } 
 // 每每 • (instancetype)retain
 {
 return self;
 } • (oneway void)release
 {
 // nothing
 } • (instancetype)autorelease
 {
 return self;
 } • (NSUInteger)retainCount
 {
 return NSUIntegerMax; // 每} ᒫ ᶭ157 ᒫ ᶭ158 MD5MD5 ⼒Salt被MD5 MD5MD5可 ⼒2被来 ⼒1被 MD5: :就 MD5 \ SHA \ DES \ 3DES \ RC2RC4 \ RSA \ IDEA \ DSA \ AES: ?ੂےই֜ᬰᤈහഝ 4>    რդᎱ(Ⴐႝ) 3>    ๜ࣈ෈կਂؙ(჋౭ጱਂ໩) ᦓ, ჋౭դᕞ)ܐᦓጱᳯ᷌(ᛔਧԎܐ    <2 ᭆ)ݎᨴݩ], ӧᚆก෈ܜ1>    ᗑᕶහഝփᬌ(භఽහഝ[ᨴݩ\ੂᎱ\ၾᩇහഝ\ᱷᤈ ௔॒ቘොୗҘقਮಁᒒਞ 每 ⼩⼩⼩每 ⼩APP 
 • ⼩信信每 APP每APP⼩⼩ • APP⾼APPAPP य़༷ฎெ໏ጱҘګiOS ጱᓋݷ๢ 每 MD5MD5 URL每 • POSTGET framework.h每每 • .m⼒.a被 每 • • BA每 • 每 ߺԶํګ๢ق᝘ຎጱਞ ګ๢قҁ21҂ਞ ᒫ ᶭ159 ֺইғ ᦜ੒᨝ᬰᤈᛔ౯༄ັ̶ر҅௳מ    ᬮํӞԶNSObjectጱොဩݢզ՗RuntimeᔮᕹӾ឴ݐ NSObjectጱৼᔄݢզ᯿ෛਫሿ̶ ᑕଧ̶NSObjectᔄଚӧᎣ᭲ৼᔄጱٖ਻҅ಅզਙݝฎᬬࢧᔄጱݷਁ޾੒᨝ጱࣈ࣎҅ Ꮁ̶ֺই - descriptionොဩ҅ᧆොဩᬬࢧᔄٖ਻ጱਁᒧԀᤒᐏ҅ᧆොဩԆᥝአ๶᧣ᦶ ಅᵱᥝጱդ׀ӥ҅NSObject ᔄՐՐਧԎԧਠ౮຤կԪఘጱཛྷ຃҅ଚဌํ൉٭    ӞԶఘ ᤈԅ̶(NSProxy ᔄ෸ӻֺक़҅ਙฎӻು᨝᩻ᔄ) ᔄ᮷ฎ NSObject ᔄጱৼᔄ҅ಅզ᮷ᖀಥԧ NSObject ጱړ    Cocoa ᑕଧӾᕷय़᮱ 2.᭗ᬦ Foundation ໛ຝጱ NSObject ᔄਧԎጱොဩ හ̶ڍOC դᎱ᫨ഘ౮ᬩᤈ෸դᎱ҅ࣁᬩᤈ෸Ꮯਧහഝᕮ຅޾ አොဩ҅ᖫᦲ࢏տਖ਼᧣҅ڔ    ݝᵱᥝᖫٟ OC դᎱ҅Runtime ᔮᕹᛔۖࣁ଒ݸ൥ਧӞ 1.᭗ᬦ Objective-C რդᎱ OC ࣁӣᐿ੶ᶎӤӨ Runtime ᔮᕹᬰᤈԻ԰ғ Runtime ጱ֢አ 
 每 GNU Runtime • Runtime C 每 
 每 • (Runtime system) 
 每 • Objective-C 每 ԅՋԍᵱᥝRuntime objc_msgSend(receiver, selector, arg1, arg2, …) // ବ੶ᬩᤈ෸տᤩᖫᦲ࢏᫨۸ԅғ [receiver message:(id)arg...]; // ইຎٌᬮํ݇හྲইғ objc_msgSend(receiver, selector) // ବ੶ᬩᤈ෸տᤩᖫᦲ࢏᫨۸ԅғ [receiver message]; OC 每 Runtime C API iOS RuntimeฎՋԍ ҁ22҂Runtime ᒫ ᶭ160     Class isa  OBJC_ISA_AVAILABILITY; struct objc_class { Class ٌਫฎ೰ݻ objc_class ᕮ຅֛ጱ೰ᰒ̶objc_class ጱහഝᕮ຅ইӥғ typedef struct objc_class *Class; 3.Class ᨝ጱ isa ೰ᰒ೰ݻӞӻӾᳵᔄᘒӧฎ፥ਫᔄ̶ࣳ ࣳ҅ᥝమᏟਧᔄࣳᬮฎᵱᥝአ੒᨝ጱ -class ොဩ̶PS:KVO ጱਫሿ๢ቘ੪ฎਖ਼ᤩᥡ੊੒ ဳ఺ғisa ೰ᰒࣁդᎱᬩᤈ෸ଚӧ௛೰ݻਫֺ੒᨝ಅંጱᔄࣳ҅ಅզӧᚆׁᶌਙ๶Ꮯਧᔄ ੒᨝ಅંጱᔄ̶ کӞӻ isa ೰ᰒ҅໑ഝ isa ೰ᰒ੪ݢզತތobjc_object ᕮ຅֛۱ کզӤਧԎ҅፡ struct objc_object { Class isa; }; typedef struct objc_object *id; id ฎӞӻ݇හᔄࣳ҅ਙฎ೰ݻ຤ӻᔄጱਫֺጱ೰ᰒ̶ਧԎইӥғ 2.id զӧտ੕ᛘਙժ᧣አොဩਫሿႰԤ̶ ဳ఺ғӧݶᔄӾፘݶݷਁጱොဩಅ੒ଫጱ selector ฎፘݶጱ҅ኧԭݒᰁጱᔄࣳӧݶ҅ಅ ࣳጱොဩᭌೠ࢏̶ හ๶឴ݐӞӻ SEL ᔄڍ @selector() ౲ᘏ Runtime ᔮᕹጱ sel_registerName ොဩጱ C ਁᒧԀ֦҅ݢզ᭗ᬦ Objc ᖫᦲ࢏࢏޸եکਙฎӻฉ੘ڊ౯ժݢզ፡ typedef struct objc_selector *SEL; ጱොဩਫሿ̶ਙጱහഝᕮ຅ฎғ ੒ଫکࣁፘݶጱᔄӾӧտํ޸ݷፘݶጱӷӻොဩ̶selector ੒ොဩݷᬰᤈ۱ᤰ҅զ׎ತ ฎ᧡҅ဳ఺ Objc᧡ڦဩᭌೠ࢏ٌ҅ਫ֢አ੪޾ݷਁӞ໏҅෭ଉኞၚӾ҅౯ժ᭗ᬦՈݷᬙ     ਙฎselectorࣁ Objc Ӿጱᤒᐏ(Swift Ӿฎ Selector ᔄ)̶selector ฎො 1.SEL ๞᧍ىRuntimeጱፘ හ̶ڍ᧍᥺ ᬯԶ CکӨٌ՜᧍᥺ጱ໫ള౲ฎବ੶ጱ debug ૡ֢֦҅ࣁٟ Objc դᎱ෸Ӟᛱӧտአ ᚆ̶ᴻᶋฎٟӞԶ Objcۑහݢզᦏֵ֦አᕍ C դᎱ๶ਫሿ Objc Ӿݶ໏ጱڍ    ᦜग़ ݢ̶ܨobjc/Runtime.h१෈կف፳౯ժֵአ෸ݝᵱᥝ୚ޱፓ୯ӥ҅ᬯ఺ Ձପ̶१෈կਂනԭ/usr/include/objcوളݗጱۖாول    Runtime ᔮᕹฎٍํ හጱፗള᧣አڍ3.᭗ᬦ੒ Runtime ପ     -methodForSelector: ᬬࢧ೰ਧොဩਫሿጱࣈ̶࣎ ᦓᔄጱොဩҔܐਫሿԧ೰ਧވ    -conformsToProtocol:༄ັ੒᨝ฎ ߥଫ೰ਧጱၾ௳Ҕވ    -respondsToSelector: ༄ັ੒᨝ᚆ ᔄጱ౮ާݒᰁ)Ҕڹฎٌৼᔄ౲ᘏᆿᔄ౲ᘏ୮ވጱᖀಥ֛ᔮӾ(ฎ ࣁԭ೰ਧጱᔄਂވ    -isKindOfClass: ޾ -isMemberOfClass: ොဩ༄ັ੒᨝ฎ classොဩᬬࢧ੒᨝ጱᔄҔ-     ᒫ ᶭ161 OBJC2_UNAVAILABLE;     int space                                                #ifdef __LP64__ OBJC2_UNAVAILABLE;     int method_count                                         OBJC2_UNAVAILABLE;     struct objc_method_list *obsolete                        struct objc_method_list { ᤒڜ// ොဩ OBJC2_UNAVAILABLE; }                                                            OBJC2_UNAVAILABLE;     struct objc_ivar ivar_list[1]                                /* variable length structure */ #endif OBJC2_UNAVAILABLE;     int space                                                #ifdef __LP64__ OBJC2_UNAVAILABLE;     int ivar_count                                           struct objc_ivar_list { ᤒڜ// ౮ާݒᰁ ᤒғڜᤒ޾ොဩڜฎ౮ާݒᰁڦړ ٌӾ objc_ivar_list ޾ objc_method_list ᦓ̶ܐဩ̵ᖨਂզ݊ᴫંጱ ᘶԧਙጱᆿᔄ೰ᰒ̵ᔄݷ̵౮ާݒᰁ̵ොىӞӻᬩᤈ෸ᔄӾ҅ک՗ objc_class ݢզ፡ } OBJC2_UNAVAILABLE; #endif OBJC2_UNAVAILABLE;     struct objc_protocol_list *protocols                     OBJC2_UNAVAILABLE;     struct objc_cache *cache                                 OBJC2_UNAVAILABLE;     struct objc_method_list **methodLists                    OBJC2_UNAVAILABLE;     struct objc_ivar_list *ivars                             OBJC2_UNAVAILABLE;     long instance_size                                       OBJC2_UNAVAILABLE;     long info                                                OBJC2_UNAVAILABLE;     long version                                             OBJC2_UNAVAILABLE;     const char *name                                         OBJC2_UNAVAILABLE;     Class super_class                                        if !__OBJC2__# ᒫ ᶭ162 ᔄࣳ؀ොဩᔄࣳ method_types ฎӻ char ೰ᰒ҅ਂؙොဩጱ݇හᔄࣳ޾ᬬࢧ ොဩݷᔄࣳԅ SEL objc_method ਂؙԧොဩݷ҅ොဩᔄࣳ޾ොဩਫሿғ } OBJC2_UNAVAILABLE;     IMP method_imp                                           OBJC2_UNAVAILABLE;     char *method_types                                       OBJC2_UNAVAILABLE;     SEL method_name                                          struct objc_method { typedef struct objc_method *Method; Method դᤒᔄӾ຤ӻොဩጱᔄࣳ Method.4 ̶ک๋ݸ objc_class ӾᬮํӞӻ objc_cache ҅ᖨਂ҅ਙጱ֢አஉ᯿ᥝ҅ݸᶎտ൉ ᔄ੒᨝ಗᤈොဩ᧣አ̶ ԧ҅੪տ੒ᬯӻکᔄӾັತᚆड़ߥଫၾ௳ጱොဩਫሿ҅ইຎತزobjc_msgSend() տ݄ਙ ᬩᤈ෸դᎱ҅ײᭆᕳᔄ੒᨝ጱ෸ݎ௳ಅզ୮ [NSObject alloc] ᬯ๵ၾ ᔄ̶زᔄጱ isa ೰ᰒ๋ᕣ᮷೰ݻ໑زᔄ(Root Meta Class)ጱਫ̶ֺಅํزฎӞӻ໑ ᔄݶ෸Ԟزᔄጱਫֺ҅ᘒᬯӻزԧӞӻᔄ੒᨝(Class Object)҅ᬯӻᔄ੒᨝஠ᶳฎӞӻ ᭆᕳݎᤩ௳Ӟӻᔄ֒ [NSObject alloc](ᔄොဩ) ጱၾ௳෸҅ਫᴬӤ҅ᬯӻၾڊݎ୮֦ ᔄ̶زጱىොဩ̶ྯӻᔄՐํӞӻᔄ੒᨝҅ᘒྯӻᔄ੒᨝ՐํӞӻӨԏፘ ౯ժಅᆧఀጱᔄොဩ҅੪რᛔԭ Meta Class̶౯ժݢզቘᥴԅᔄොဩ੪ฎᔄ੒᨝ጱਫֺ හഝ̶زᔄ̶Meta Class ᤒᬿԧᔄ੒᨝๜᫝ಅٍ॓ጱزᥜ҅ᔄ੒᨝ಅંጱᔄ੪ݞ؉ ᔄ) ጱӳز)ୌԧӞᐿݞ؉ Meta Classڠᔮ҅Runtime ପى᨝̶ԅԧ॒ቘᔄ޾੒᨝ጱ ஑ဳ఺ጱ෸҅objc_class ӾԞํӞӻ isa ೰ᰒ҅ᬯ᧔ก Objc ᔄ๜᫝ԞฎӞӻ੒؀ ኧ objc_method ᕮ຅֛ਂ̶ؙڞ௳מጱ ӻොဩܔᤒ҅ᘒڜҔݶቘ҅objc_method_list ᕮ຅֛ਂؙ፳ොဩහᕟጱ௳מާݒᰁጱ ӻ౮ܔฎਂؙԧڞ ᤒ҅ᘒ objc_ivarڜobjc_ivar_list ᕮ຅֛አ๶ਂؙ౮ާݒᰁጱ ௔ጱܻࢩ̶ંےਫሿጱܻቘ҅ݶ໏ᥴ᯽ԧ Category ӧᚆႲ ౮ާොဩ҅ᬯԞฎ Categoryے๶Ⴒ؀ද *methodList ጱץኧྌݢᥠ҅౯ժݢզۖா } OBJC2_UNAVAILABLE;     struct objc_method method_list[1]                            /* variable length structure */ endif# ᒫ ᶭ163 }; OBJC2_UNAVAILABLE;     Method buckets[1]                                        OBJC2_UNAVAILABLE;     unsigned int occupied                                    OBJC2_UNAVAILABLE;     unsigned int mask /* total = mask + 1 */                 struct objc_cache { typedef struct objc_cache *Cache Cache ਧԎইӥғ 6.Cache ᘒӞӻᏟਧጱොဩԞݝํࠔӞጱӞᕟ id ޾ SEL ݇හ̶ ොဩਫሿᙗਧฎࠔӞጱ҅᭗ᬦӞᕟ id޾ SEL ݇හ੪ᚆᏟਧࠔӞጱොဩਫሿࣈ̶࣎ ᔄ̶ࣳྯӻොဩݷ᮷੒ଫӞӻ SEL ᔄࣳጱොဩᭌೠ࢏҅ᘒྯӻਫֺ੒᨝Ӿጱ SEL ੒ଫጱ id ޾ SEL ތහᔄࣳፘݶ҅݇හ᮷۱ڍ ሿ IMP ೰ݻጱොဩӨ objc_msgSendݎտ֦ ̶کᬯࣁݸᶎ Cache Ӿտ൉ ݗ҅౯ժ੪ݢզᕰ୏ၾ௳փ᭓ᴤྦྷ҅ፗളಗᤈොဩ҅فԧಗᤈ຤ӻਫֺ຤ӻොဩጱکইຎ஑ ሿ̶ හ೰ᰒ੪೰ݻԧᬯӻොဩጱਫڍහ೰ᰒ೰ਧጱ̶ᘒ IMP ᬯӻڍᤈጱᮎྦྷդᎱ҅੪ฎኧᬯӻ ᩸Ӟӻ ObjC ၾ௳ԏݸ๋҅ᕣਙտಗݎහ೰ᰒ҅ᬯฎኧᖫᦲ࢏ኞ౮ጱ̶୮֦ڍਙ੪ฎӞӻ typedef id (*IMP)(id, SEL, ...); IMPࣁobjc.hӾጱਧԎฎғ 5.IMP ٌӾ ivar_offset ฎचࣈ࣎؇ᑏਁᜓ } #endif OBJC2_UNAVAILABLE;     int space                                                #ifdef __LP64__ OBJC2_UNAVAILABLE;     int ivar_offset                                          OBJC2_UNAVAILABLE;     char *ivar_type                                          OBJC2_UNAVAILABLE;     char *ivar_name                                          struct objc_ivar { typedef struct objc_ivar *Ivar; Ivar ฎᤒᐏ౮ާݒᰁጱᔄ̶ࣳ Ivar හ೰ᰒڍmethod_imp ೰ݻԧොဩጱਫሿ҅๜ᨶฎӞӻ ᒫ ᶭ164 test[2321:451525] name--------T@"NSString",&,N,V_name test[2321:451525] 3 ᕮຎইӥғܦ಑     }         NSLog(@"%@--------%@", name, attributes); @(property_getAttributes(properties[i]));         NSString *attributes =         NSString *name = @(property_getName(properties[i]));     for (NSInteger i = 0; i < outCount; i++) {     NSLog(@"%d", outCount); class], &outCount);     objc_property_t *properties = class_copyPropertyList([Person     unsigned int outCount = 0; զӤฎӞӻ Person ᔄ҅ํ3ӻં௔̶ᦏ౯ժአӤᬿොဩ឴ݐᔄጱᬩᤈ෸ં௔̶ @end @property (assign, nonatomic) double weight; /** weight */ @property (assign, nonatomic) int age; /** age */ @property (strong, nonatomic) NSString *name; /** নݷ */ @interface Person : NSObject #import ᔰ᮷ฎӞӻ objc_property_t ೰ᰒزᤒӾྯӻڜᤒ҅ڜᬬࢧጱฎં௔ ဳ఺ғ unsigned int *outCount) objc_property_t *protocol_copyPropertyList(Protocol *proto, *outCount) objc_property_t *class_copyPropertyList(Class cls, unsigned int ᦓӾጱં௔ғܐ޾ ݢզ᭗ᬦclass_copyPropertyList ޾ protocol_copyPropertyList ොဩ឴ݐᔄ typedef struct objc_property *objc_property_t;//ᬯӻๅଉአ typedef struct objc_property *Property; 7.Property ᳯ Cache Ӟ໏̶ ᦢضᦇᓒ๢ᕟ౮ܻቘӾ CPU ᕰᬦԆਂ؟੪տපሲๅṛ̶੪ײݸᬮտᤩ᧣አ҅ӥེັತጱ෸ Cache Ӿ҅ইຎӞӻොဩᤩ᧣አ҅ᮎԍਙํݢᚆՔ کRuntime ᔮᕹտ಩ᤩ᧣አጱොဩਂ ࣁ Cache Ӿັತ̶ضս ᤒӾ᭭ܲັತᚆड़ߥଫጱොဩ҅ࢩԅྯེ᮷ᥝັತපሲॡ֗ԧ҅ᘒฎڜ೰ᰒ೰ݻጱᔄጱොဩ Ӟӻၾ௳෸҅ਙӧտፗളࣁ isaکCache ԅොဩ᧣አጱ௔ᚆᬰᤈս۸҅ྯ୮ਫֺ੒᨝ളත ᒫ ᶭ165 ጱ̶فٌਫ҅ᬯԞฎ Runtime ᔮᕹጱ֢አ҅self ਫࣁොဩᬩᤈ෸ᤩۖாփ ොဩጱ੒᨝ޫҘڹᲫਁ self ҅֕ฎ self ฎই֜឴ݐ୮ىک౯ժᕪଉአ ወᳯғ ොဩӾጱᵌᡐ݇හ stret 做每 有 Super 做 objc_msgSendSuper objc_msgSendSuper_stret 每 • 有 objc_msgSend objc_msgSend_stret 每 
每 ◦ NSObject ◦ cache 每 做每 ◦ IMP cache Crash每 ◦ selector target nilObjc 最 nil retainrelease 做每 ◦ selector 每 Mac OS X 都想 更 每 • objc_msgSend objc_msgSend ⼈每 aren’t bound to method implementations until Runtime每 • Runtime 每就 messages RuntimeӨၾ௳ ં௔ጱ୚አ̶ ᦓӾ឴஑ܐ௔ݷࣁᔄ޾ંڊclass_getProperty ޾ protocol_getProperty ᭗ᬦᕳ *name, BOOL isRequiredProperty, BOOL isInstanceProperty) objc_property_t protocol_getProperty(Protocol *proto, const char objc_property_t class_getProperty(Class cls, const char *name) Ԁ̶ හ೵യં௔ጱ፥ਫݷᑍ޾ @encode ᔄࣳ҅ᬬࢧ c ਁᒧڍ property_getAttributes property_getName አ๶ັತં௔ጱݷᑍ҅ᬬࢧ c ਁᒧԀ̶ test[2321:451525] weight--------Td,N,V_weight test[2321:451525] age--------Ti,N,V_age ᒫ ᶭ166 ۖாොဩᥴຉ ጱ҅ᘒӧฎ Objc ᛔ᫝ጱᇙ௔׀methodForSelector:ොဩฎኧ Runtime ᔮᕹ൉ ဳ఺ғ ᭆာᄂ̶ݎ௳ၾع಍տᭌೠֵአզ҅٭ጱఘ ᡱᆐݢզๅṛපጱ᧣አොဩ҅֕ฎᬯᐿ؉ဩஉ੝አ҅ᴻᶋ෸ᵱᥝ೮ᖅय़ᰁ᯿॔᧣አ຤ӻොဩ ᭆ1000ེ setFilled: ၾ௳տᜰग़ԋ̶ݎ හ֦҅Ԟݢզ੤ᦶᕳ target ڍӤᶎጱֺৼ᧣አԧ1000ེ҅ڊහ᧣አ෸҅ӷӻᵌᡐ݇හԞ஠ᶳกᏟᕳڍ୮ොဩᤩ୮؉     setter(targetList[i], @selector(setFilled:), YES); for ( i = 0 ; i < 1000 ; i++ )     methodForSelector:@selector(setFilled:)]; setter = (void (*)(id, SEL, BOOL))[target int i; void (*setter)(id, SEL, BOOL); ೠ࢏੒ଫጱ IMP ҅Ԉӻֺৼғ NSObject ᔄӾํӞӻਫֺොဩғmethodForSelector֦҅ݢզአਙ๶឴ݐ຤ӻොဩᭌ ឴ݐොဩࣈ࣎ NSLog(@"%@", NSStringFromClass([super class])); ᔄጱᔄࣳݷڹ// ᬯݙᦾଚӧᚆ឴ݐᆿᔄጱᔄࣳ҅ݝᚆ឴ݐ୮ ሿғݎጱ࿞ᬱ᮷ฎ self ጱᔄ̶ࣳࢩྌ֦տکclass] ፘݶ҅ಅզ౯ժ஑ ጱᒫӞӻ݇හฎ೰ݻ self ጱ id ೰ᰒ҅Ө᧣አ [selfف@selector(class))҅փ ᦲ࢏ਖ਼դᎱ᫨ഘԅ objc_msgSend(objc_super->receiver, class ොဩ҅ᆐݸ class ොဩବ੶ᤩ᫨ഘԅ object_getClass()҅ ള፳ବ੶ᖫ ک හ̶ݝํࣁ NSObject ᔄӾ಍ᚆತڍ class ጱ SEL փ᭓ᕳԧ objc_msgSendSuper ժమ᭗ᬦ [super class] ឴ݐᆿᔄ෸҅ᖫᦲ࢏ٌਫฎਖ਼೰ݻ self ጱ id ೰ᰒ޾ ᬯӻᕮ຅֛೰กԧၾ௳ଫᧆᤩփ᭓ᕳᇙਧጱᆿᔄ̶ receiver Ֆᆐฎ self ๜᫝҅୮౯ struct objc_super { id receiver; Class class; }; ୌӞӻ objc_super ᕮ຅֛ғڠ࢏տ ၾ௳෸҅ᖫᦲکᲫਁളතى Ძਁ super ҅ਫᴬӤ superىݚӞӻکᬯ෸౯ժݢᚆտమ ᬯӷӻ݇හӾ҅ selfๅਫአ̶ਙฎࣁොဩਫሿӾᦢᳯၾ௳ളතᘏ੒᨝ጱਫֺݒᰁጱ᭔ஆ̶ ොဩਫሿӾጱ̶ੱᓕᬯԶ݇හဌํᤩกᏟ्ก҅ࣁრդᎱӾ౯ժՖᆐݢզ୚አਙժ̶فൊ ሿᬯӷӻ݇හጱ्ก̶ਙժ෸ࣁդᎱᤩᖫᦲ෸ᤩݎࢩԅࣁრդᎱොဩጱਧԎӾ҅౯ժଚဌํ ොဩጱ SEL ೰ᰒ)ڹොဩᭌೠ࢏(_cmd ೰ݻጱٖ਻҅୮ ොဩጱ੒᨝೰ᰒ)ڹളݑၾ௳ጱ੒᨝(self ಅ೰ݻጱٖ਻҅୮ හ᮷փ᭓ᕳොဩਫሿ҅ݶ෸҅ਙᬮਖ਼փ᭓ӷӻᵌᡐ݇හғ ොဩ੒ଫਫሿ෸҅ਙਖ਼ፗള᧣አᧆොဩਫሿ҅ଚਖ਼ၾ௳Ӿಅํ݇ک୮ objc_msgSend ತ ᒫ ᶭ167     if(aSelector == @selector(mysteriousMethod:)){ { - (id)forwardingTargetForSelector:(SEL)aSelector (id)forwardingTargetForSelector:(SEL)aSelector ොဩ̶ ᦜ౯ժ๊ഘၾ௳ጱളතᘏԅٌ՜੒᨝̶᭗ᬦ -رRuntime ᔮᕹ҅ڹಗᤈګ๢ݎၾ௳᫨ ᯿ਧݻ.1 ݎၾ௳᫨ resolveInstanceMethod: ොဩᬬࢧ NO̶ ੪ᦏ҅ګ๢ݎ᫨ک࢏੒ଫጱ IMP ጱ๢տ̶ইຎ֦మᦏᧆොဩᭌೠ࢏ᤩփᭆ ᧆොဩᭌೠ׀ᕳԨ൉ضಗᤈ҅ۖாොဩᥴຉ࢏ਖ਼տḒڹف׍ګ๢ݎۖாොဩᥴຉտࣁၾ௳᫨ ဳ఺ғ ԎᥠғType Encodingތ ޾݇හ҅ᬯӻᒧݩᤒᐏጱ؀dynamicMethodIMP ොဩӾጱդᎱ̶ٌӾ "v@:" ᤒᐏᬬࢧ ԧਫሿٖ਻҅੪ฎےӤᶎጱֺৼԅ resolveThisMethodDynamically ොဩႲ @end }     return [super resolveInstanceMethod:aSEL];     }           return YES; dynamicMethodIMP, "v@:");           class_addMethod([self class], aSEL, (IMP)     if (aSEL == @selector(resolveThisMethodDynamically)) { { + (BOOL)resolveInstanceMethod:(SEL)aSEL @implementation MyClass }     // implementation .... void dynamicMethodIMP(id self, SEL _cmd) { ᇙਧොဩਫሿጱ඙֢ғ ےහਠ౮ݻᇙਧᔄႲڍ ොဩਫሿጱ๢տ̶౯ժᵱᥝአ class_addMethodےӞེۖாႲ Runtime տ᧣አ resolveInstanceMethod: ౲ resolveClassMethod: ๶ᕳ౯ժ ᥝಗᤈጱොဩ෸҅کᤒ(۱ೡᆿᔄ)Ӿತӧڜ୮ Runtime ᔮᕹࣁ Cache ޾ᔄጱොဩ ਫֺොဩਫሿ޾ᔄොဩਫሿ̶ےresolveClassMethod: ොဩႲ ᯿᫹ resolveInstanceMethod: ޾ڦړᬯ෸҅౯ժݢզ᭗ᬦ dynamic propertyName;@ ̶׀ጱ setter ޾ getter ොဩԧ҅ᵱᥝ౯ժᛔ૩൉ ݐොဩ҅ᖫᦲ࢏ӧտٚἕᦊԅ౯ժኞ౮ᬯӻં௔ਂ׀ӻં௔҅ᤒก౯ժտԅᬯӻં௔ۖா൉ ᷶ӞץᲫਁ @dynamic ࣁᔄጱਫሿ෈կӾىӞӻොဩਫሿ̶ইຎ౯ժֵአ׀ݢզۖா൉֦ ᒫ ᶭ168 ޾ग़ᖀಥݎ᫨ forwardInvocation:ਖ਼ӧݢᚆᤩ᧣አ̶҅ڞވಅ੒ଫጱොဩ̶ ᬯӻ੒᨝ӧᚆํᧆၾ௳ጱכᕳٌ՜੒᨝෸҅ᥝᏟݎզ҅ইຎ౯ժݻஃӞӻ੒᨝ਖ਼Ӟӻၾ௳᫨ forwardInvocation:ොဩݝํࣁၾ௳ളත੒᨝Ӿ෫ဩྋଉߥଫၾ௳෸಍տᤩ᧣አ̶ಅ ဳ఺ғ ᮷ݐ٬ԭොဩጱٍ֛ਫሿ̶ڔጱ“ݰധ”຤Զၾ௳҅ࢩྌဌํߥଫԞӧտಸᲙ̶ᬯӞܔᓌ ᕳݶӞӻ੒᨝҅ٚ౲ᘏਖ਼ၾ௳ᘉᦲ౮ݚक़ጱၾ௳҅Խ౲ᘏݎᕳӧݶጱളත੒᨝҅౲ᘏ᫨ݎ᫨ ጱၾ௳ڦӾஞ҅ਖ਼ᬯԶӧᚆᦩݎړၾ௳ጱڦforwardInvocation: ොဩ੪ฎӞӻӧᚆᦩ ᕳٌ՜੒᨝̶ݎݢզਖ਼ၾ௳᫨ doesNotRecognizeSelector:̶᭗ᬦਫሿᛔ૩ጱ forwardInvocation: ොဩ҅౯ժ ጱ᧣አԧܔොဩ̶֕ฎ҅ NSObject Ӿጱොဩਫሿݝฎᓌ forwardInvocation: ၾ௳᭗Ꭳᧆ੒᨝̶ྯӻ੒᨝᮷ᖀಥԧ forwardInvocation: ୮Ӟӻ੒᨝ኧԭဌํፘଫጱොဩਫሿᘒ෫ဩፘଫ຤ၾ௳෸҅ᬩᤈ෸ᔮᕹਖ਼᭗ᬦ տಲ୑ଉ̶ڞވmethodSignatureForSelector: ොဩ҅ NSInvocation ੒᨝̶ಅզ᯿ٟ forwardInvocation: ጱݶ෸Ԟᥝ᯿ٟ ᬬࢧጱොဩᓋݷአԭኞ౮کmethodSignatureForSelector: ၾ௳҅ଚݐ ᭆݎRuntime ᔮᕹտݻ੒᨝҅ڹᭆݎ௳ࣁ forwardInvocation: ၾ ဳ఺ғ݇හ anInvocation ฎ՗ߺ๶ጱҘ Კ᧏̶ڊᕳٌ՜੒᨝॒ቘ҅ᘒӧಲݎ᫨ ժݢզਫሿ forwardInvocation: ොဩ๶੒ӧᚆ॒ቘጱၾ௳؉ӞԶ॒ቘ̶Ԟݢզਖ਼ၾ௳ ࠔӞ݇හฎӻ NSInvocation ᔄࣳጱ੒᨝҅ᧆ੒᨝੗ᤰԧܻতጱၾ௳޾ၾ௳ጱ݇හ̶౯ }         [super forwardInvocation:anInvocation];     else         [anInvocation invokeWithTarget:someOtherObject];             [anInvocation selector]])     if ([someOtherObject respondsToSelector: { - (void)forwardInvocation:(NSInvocation *)anInvocation ᭦ᬋғݎforwardInvocation: ොဩտᤩಗᤈ҅౯ժݢզ᯿ٟᬯӻොဩ๶ᛔਧԎ౯ժጱ᫨ ᬯ෸̶ګ๢ݎၾ௳᫨ݎտ᥶ڞ୮ۖாොဩᥴຉӧ؉॒ቘᬬࢧ NO ෸҅ ݎ2.᫨ ᭆၾ௳̶ݎਖ਼ݻᬬࢧጱ੒᨝᯿ෛڞ ވ҅(:forwardInvocation)ګ๢ݎၾ௳᫨فտᦇڞইຎྌොဩᬬࢧ nil ౲ᘏ self҅ }     return [super forwardingTargetForSelector:aSelector];     } return alternateObject;         ᒫ ᶭ169 ጱၾ௳̶՗ᘒኞ౮Ӟݎᬿ methodSignatureForSelector:҅ᬯӻොဩտ๋ᕣߥଫᤩ᫨ ᏟጱොဩൈٵӞӻොဩຽᓋ๶ᬬࢧڊਙളݑጱձ֜ᬱᑕၾ௳҅ਙ஑ᕳݎইຎӞӻ੒᨝మᥝ᫨ Ӿ̶ڜᬯӞᤈکفےconformsToProtocol: ݶ໏Ԟᥝ ᦓ҅ܐᓒဩ̶ইຎֵአԧݎinstancesRespondToSelector: ӾԞଫᧆٟӞղ᫨ ᴻԧ respondsToSelector: ޾ isKindOfClass: ԏक़҅ }     return NO;     }          * object can respond to it. Return YES if it can.  */          * be forwarded to another object and whether that  *         /* Here, test whether the aSelector message can     *     else {         return YES;     if ( [super respondsToSelector:aSelector] ) { - (BOOL)respondsToSelector:(SEL)aSelector ᓒဩғݎጱ᫨֦فے᯿ෛਫሿ respondsToSelector: ޾ isKindOfClass: ๶ ԧ Diplomat ጱ negotiate ොဩ֦҅஑کՈզԅ Warrior ᖀಥڦইຎ֦੪ฎమᥝᦏ Diplomat ᔄߥଫၾ௳̶ ၾ௳ᕳݎࢧᒼ୮ᆐฎ NO҅ ੱᓕਙᚆളݑ negotiate ၾ௳ᘒӧಸᲙ҅ࢩԅਙᶌ᫨     ... if ( [aWarrior respondsToSelector:@selector(negotiate)] ) ᚆߥଫ negotiateၾ௳ғވฎک Warrior ੒᨝ᤩᳯ ᱾̶ݎ᫨ respondsToSelector: ޾ isKindOfClass: ᬯᔄොဩݝտᘍᡤᖀಥ֛ᔮ҅ӧտᘍᡤ ؟ᚆ҅֕ฎ NSObject ᬮฎ஠ᶳᤒᶎӤஉӸᨆ҅ۑݢզਫሿᖀಥጱݎᡱᆐ᫨ Өᖀಥݎ᫨ ๥̶ ӻᔄݒ஑ᛎᙠ॔ܔԧࢩԅग़ᖀಥ੕ᛘعୠᤑԧ Objc ӧඪ೮ग़ᖀಥጱ௔ᨶ҅Ԟ᭿ݎၾ௳᫨ Diplomat ݸ҅੪অ֒ Diplomat ฎ Warrior ጱ᩻ᔄӞ໏̶ ᕳԧݎᔮ҅֕ฎ Warrior ਖ਼ negotiate ၾ௳᫨ى޾ Diplomat ဌํᖀಥ ඪӥጱӷӻᔄݢզਫሿ“ᖀಥ”੒ොጱොဩ҅ࣁӤࢶӾ Warriorړᬯֵ஑ࣁӧݶᖀಥ֛ᔮ ਙ಩ݚӞӻ੒᨝Ӿጱොဩളᬦ๶౲ᘏ“ᖀಥ”ᬦ๶Ӟ໏̶؟੪অ݄҅ڊݎ಩ၾ௳᫨ ӥࢶᮎ໏҅Ӟӻ੒᨝؟ӞԶग़ᖀಥጱපຎ̶੪ے޾ᖀಥፘ֒҅ݢአԭԅ Objc ᖫᑕႲݎ᫨ ᒫ ᶭ170 ̶ڥRuntime ᔮᕹଃ๶ጱ׎ کԅᬯֵ஑౯ժݢզՁݑ ᯈᳯ᷌҅ๅฎࢩړ౯ժᦏᛔ૩ጱᔄᖀಥᛔ NSObject ӧՐՐฎࢩԅचᔄํஉग़॔๥ጱٖਂ ௛ᕮ "SomeIvar")) ๶դ̶๊ ivar_getOffset(class_getInstanceVariable([SomeClass class], offsetof(SomeClass, SomeIvar)҅ᘒᥝֵአ class_getInstanceSize([SomeClass class]) դ๊ҔԞӧᥝֵአ  ࣁ؋ौጱਫֺݒᰁӥ҅ӧᥝֵአ siof(SomeClass)҅ᘒฎአ ဳ఺ғ ಷ᩸๶ԧ̶כާݒᰁ੪ᤩ ጱ౮ےጱਫֺݒᰁጱ֖ᑏ҅ᮎ໏֦ٚৼᔄӾෛႲے᯿ݖ෸ਙտ᧣ෆ֦ෛႲړӨᆿᔄํ᮱کၥ Ӟ໏҅֕ฎ୮ Runtime ᔮᕹ༄ڹࣁ؋ौጱਫֺݒᰁӥ҅ᖫᦲ࢏ኞ౮ጱਫֺݒᰁ૲ੴ᪙զ ؋ौጱਫֺݒᰁጱᦾ҅ইӥࢶғ ᰁ(Fragile ivar)ሾहӥ҅ᵱᥝ౯ժ᯿ෛᖫᦲᖀಥᛔ Apple ጱᔄ๶௩ّ॔਻̶ইຎฎ ֕ᬯ໏੕ᛘਙժӧᚆٚ೐઀ਙժጱ໛ຝԧ҅ࢩԅ౮ާݒᰁ૲ੴᤩࢴਧ֘ԧ̶ࣁᚈ୧ጱਫֺݒ ጱ૲ੴ಍ᚆ೤ම౯ժ҅ڹऒ᯿ݖԧ̶ݝํ᝘ຎਖ਼ᆿᔄදԅզ܄ऒ޾ᆿᔄጱ܄౯ժᛔਧԎጱᔄጱ ሿᳯ᷌ғڊᗌᵅ҅੪ฎᗌԓ೐઀௔̶ߺॠ᝘ຎๅෛԧ NSObject ᔄጱᦾ҅੪տ Ӥࢶૢฎ NSObject ᔄጱਫֺݒᰁ૲ੴ̶ݦᬟฎ౯ժٟጱᔄጱ૲ੴ̶ᬯ໏ৼํӞӻஉय़ጱ ᑮᳵᘒԾኞ֖ᑏғ ܛֺݒᰁጱٖਂ૲ੴ੪୵౮ԧ҅ਙᤒกᦢᳯᔄጱਫֺݒᰁጱ֖ᗝ̶ਫֺݒᰁӞེ໑ഝᛔ૩ಅ ࣁ Runtime ጱሿᤈᇇ๜Ӿ๋҅य़ጱᇙᅩ੪ฎ؋ौጱਫֺݒᰁԧ̶୮Ӟӻᔄᤩᖫᦲ෸҅ਫ ؋ौጱਫֺݒᰁ(Non Fragile ivars) }     return signature;     } methodSignatureForSelector:selector];        signature = [surrogate     if (!signature) { methodSignatureForSelector:selector];     NSMethodSignature* signature = [super { - (NSMethodSignature*)methodSignatureForSelector:(SEL)selector ӥᶎᬯ໏ਫሿғ؟ਙᵱᥝ ጱၾ௳̶ݎӻᏟਧጱ NSInvocation ੒᨝ൈᬿၾ௳޾ၾ௳݇හ̶ᬯӻොဩ๋ᕣߥଫᤩ᫨ ᒫ ᶭ171     }     method_exchangeImplementations(description, myLog);     // Իഘොဩࣈ࣎҅ፘ୮ԭԻഘਫሿොୗ     Method myLog = class_getClassMethod(self, @selector(myLog));     // ឴ݐimageWithNameොဩࣈ࣎ @selector(description));     Method description = class_getClassMethod(self,     // ឴ݐimageWithNameොဩࣈ࣎     {     +(void)load አ᧣ײጱ෸ਂٖکᔄړ᫹ے // { ᤈݩ,Ջԍොဩ,ߺӻᔄ᧣አᒵᒵܦ  // ᬯ᯾ٟ಑ { +(NSString *)myLog ,是 runtime每, ᚆҘۑ୯෭பᬯ໏ጱ ᚆդᎱզਫሿᔄ֒ᦕۑᛔ૩ጱےObjective-C ই֜੒૪ํጱොဩ҅Ⴒ • runtime API • runtimeruntime信信 • runtimeOCOC objc_msgSend做⼒OC被 runtimeruntimeC做 • OCruntime • runtimeC • Ҙހጱ१෈կ౲ᘏ຤Զොဩጱݷᑍىֵአጱፘ ฎՋԍ,ெԍአ҅Ӟᛱአԭଗࡶ. ֦ᬮᚆᦕ஑֦ಅګruntimeਫሿጱ๢ ᚆๅ୩य़ጱդᎱ̶ۑڊٟګአၾ௳๢ڥᥴ Runtime ᔮᕹጱᕡᜓֵ஑౯ժݢզ ቘفᭆၾ௳ବ੶ಅ؉ጱ॔๥ጱ඙֢҅֕Ⴎݎጱ᧣አොဩ҅ܔᡱᆐଘ෸౯ժஉ੝տᘍᡤӞݙᓌ ᒫ ᶭ172 • __bridgeARC2 
 • ARC,Foundation Core Foundation 
 • Toll-Free BridgingFoundationCore Foundation, ӥտֵአҘ٭Toll-Free Bridging ฎՋԍҘՋԍఘ } OBJC_ASSOCIATION_RETAIN_NONATOMIC);     objc_setAssociatedObject(self, key, name, ᘶጱᒽኼى:    // ᒫࢥӻ݇හ ᘶጱvalueى    // ᒫӣӻ݇හғ ᘶጱkey҅᭗ᬦᬯӻkey឴ݐى    // ᒫԫӻ݇හғ ᘶىے    // ᒫӞӻ݇හғᕳߺӻ੒᨝Ⴒ { -(void)setName:(NSString *)name } return objc_getAssociatedObject(self, key);    ̶؀ᘶጱىᘶጱkey҅឴ݐى    // ໑ഝ { -(NSString *)name static const char *key = "name"; ᘶጱkeyى// ਧԎ @implementation NSObject (test) .m෈կ @end @property (nonatomic, copy) NSString *name; @interface NSObject (test) १෈կ runtime ই֜ᦏ Category ඪ೮ં௔Ҙ ᒫ ᶭ173 ਫֺݒᰁҔےአ̶ಅզӧᚆݻਂࣁጱᔄӾႲ class_setIvarLayout ౲ class_setWeakIvarLayout ๶॒ቘ strong weak ୚ ᱾ᤒ ޾ instance_size ਫֺݒᰁጱٖਂय़ੜ૪ᕪᏟਧ҅ݶ෸runtime տ᧣አ ࢩԅᖫᦲݸጱᔄ૪ᕪဳٙࣁ runtime Ӿ҅ᔄᕮ຅֛Ӿጱ objc_ivar_list ਫֺݒᰁጱ ᥴ᯽ইӥғ ਫֺݒᰁҔےୌጱᔄӾႲڠ- ᚆݻᬩᤈ෸ ਫֺݒᰁҔےጱᔄӾीک- ӧᚆݻᖫᦲݸ஑ ਫֺݒᰁҘԅՋԍҘے ୌጱᔄӾႲڠݻᬩᤈ෸ވਫֺݒᰁҘᚆےጱᔄӾीکݻᖫᦲݸ஑ވᚆ • selectorIMP • method_setImplementation IMP • class_replaceMethod • method_exchangeImplementations 2IMP 做Method每 • selector我每IMP 每OCselector每 • OCselector 做我每 ——⼒dispatch table被 • Method swizzling每OC Method Swizzle每 • 信 ӥտֵአҘ٭Ջԍฎ Method Swizzleҁἓṹဩ҂҅Ջԍఘ ◦ ,, respondsToSelector: ◦ performSelector:withObject:afterDelay:,要 • ) • ,runtime(Selector ํՋԍဳ఺ԪᶱԍҘ performSelector:withObject:afterDelay: ٖ᮱य़༷ฎெԍਫሿጱ҅ • __bridge_transfer,2 Core Foundation • __bridge,Core Foundation,Foundation, • ARC, Core Foundation Foundation bridge_retainedCore Foundation__ • ᒫ ᶭ174      struct objc_cache *cache OBJC2_UNAVAILABLE; // ොဩਧԎጱ᱾ᤒ          struct objc_method_list **methodLists OBJC2_UNAVAILABLE; // ᧆᔄጱ౮ާݒᰁ᱾ᤒ          struct objc_ivar_list *ivars OBJC2_UNAVAILABLE; // ᧆᔄጱਫֺݒᰁय़ੜ          long instance_size ᬩᤈ๗ֵአጱӞԶ֖ຽᦩ    ׀҅௳מOBJC2_UNAVAILABLE; // ᔄ      long info ἕᦊԅ0    ҅௳מOBJC2_UNAVAILABLE; // ᔄጱᇇ๜      long version OBJC2_UNAVAILABLE; // ᔄݷ          const char *name OBJC2_UNAVAILABLE; // ᆿᔄ      Class super_class #if !__OBJC2__    ᕳԧClass Object    ݎ௳ᭆ[NSObject alloc]ᬯ໏ၾ௳෸҅ਫᴬӤฎ಩ᬯӻၾݎ ᭜ԧMeta Class҅୮ᕳᔄڠᔮ҅runtime੪ىᔄጱ๜᫝ԞฎӞӻObject҅ԅԧ॒ቘᬯӻ Class isa OBJC_ISA_AVAILABILITY; //isa೰ᰒ೰ݻMeta Class҅ࢩԅObjcጱ struct objc_class {    ᶲ׎ᴫӤOCӾӞӻᔄጱහഝᕮ຅ /usr/include/objc/runtime.h ਫሿ̶ ොဩڜදᔄ̵੒᨝޾ਙժጱොဩ̶ݢզֵአruntimeጱӞᔮץୌ҅༄ັ҅ڠࣁᑕଧᬩᤈ෸ ҅ێOC ጱ Runtime ᱹ੪ԧਙۖா᧍᥺ጱᇙ௔҅Objc Runtimeֵ஑Cٍํԧᶎݻ੒᨝ᚆ ๶٬ਧԧ̶٭ኞጱఘݎ੪ᥝ፡ᬩᤈ෸ ᭆmessageᬯ๵ၾ௳҅ᘒreceiveਖ਼ᥝই֜ߥଫᬯ๵ၾ௳҅ᮎݎᦲᴤྦྷᏟਧԧᥝݻളතᘏ ጱොဩ᧣አ̶ࢩԅᬯݝฎࣁᖫܔܔreceiver message]፥ጱӧฎӞӻᓌᓌ]ڊሿࣁݢզ፡ ٖ਻҅ᥝԍ੪ଗᚈሻਠૄმധ̶ ᬯӻselector੒ଫጱਫሿے౲ฎԁ෸ݻളතᘏۖாႲ҅ݎၾ௳ᥝԍᤩ᫨҅ڞވᇙਧොဩҔ ੒ଫጱselector҅ᮎԍ੪ፘ୮ԭፗളಗᤈԧളතᘏᬯӻ੒᨝ጱکইຎၾ௳ጱളතᘏᚆड़ತ objc_msgSend(receiver, selector, arg1, arg2, ...) ԅғڞහ҅݇ํތ௳ইຎၾ objc_msgSend(receiver, selector) [receiver message]տᤩᖫᦲ࢏᫨۸ԅғ Ԏғތᭆၾ௳ጱݎ๶፡፡ெԍቘᥴض ҁ౲ᘏ᧨ӥ੒runtimeጱቘᥴ҂ ၾ௳ݎฎᕳ੒᨝ڞහ᧣አ҅ objective c᯾ڍԅՋԍٌ՜᧍᥺᯾ݞ ࢩݶӤ̶ܻ҅ڹobjc_allocateClassPair ԏݸ҅objc_registerClassPair ԏ හ̶֕ฎ஑ࣁ᧣አڍ ਫֺݒᰁ҅᧣አ class_addIvarےୌጱᔄฎݢզႲڠᬩᤈ෸ ᒫ ᶭ175 •    - (id)delegate { •     •    @property (nonatomic, weak) id delegate; •    // ࢩԅ౯ժ᯿ٟԧgetter/setterොဩ Ძਁݢզӧֵአ҅ىᦡdelegateٌ҅ਫweak؃•    // ्กӞӻweakં௔҅ᬯ᯾ ᘶં௔๶ਫሿғى•    ᭗ᬦ runtimeই֜ਫሿweakં௔Ҙ forwardingTargetForSelectorݎၾ௳᫨ ۖாොဩᥴຉresolveThisMethodDynamically ݸᶎᬮํғ ̶کாොဩᥴຉԧ҅ݸᶎտ൉ۖف੪ᥝ୏তᬰکইຎᬮತӧ NSObjectᔄԅྊ̶کತکᤒ݄ತ҅Ӟፗತ҅ፗݎړ᩻ᔄጱک੪کᤒತӧݎړইຎ ᤒ̶ݎړ੪ತӞӥොဩکইຎ cache ತӧ හ݄ಗᤈ̶ڍ੒ଫጱک᪡ ੪ک՗ cache ᯾ᶎತ҅ਠԧತ஑ضইຎӤᶎӷӻ᮷ᬦԧ҅ᮎ੪୏তັತᬯӻᔄጱ IMP҅ ӻොဩӧտ Crash҅ࢩԅտᤩ஺ኼധ̶ ᦜ੒Ӟӻ nil ੒᨝ಗᤈձ֜Ӟر༄ၥᬯӻ target ฎӧฎ nil ੒᨝̶ObjC ጱᇙ௔ฎ හԧ̶ڍretain,release ᬯԶ ԧ࣯࣍ࢧත੪ӧቘտํ҅ݎ༄ၥᬯӻ selector ฎӧฎᥝ஺ኼጱ̶ྲই Mac OS X ୏ ᭆྍṈғݎ௳ӥၾ ഝٌ҅ਫobjc_msgSend՗ӧᬬࢧහഝᘒฎ֦ጱොဩᤩ᧣አݸᬬࢧԧහഝ̶ӥᶎᧇᕡݓᬿ ฎobjc_msgSendᬬࢧԧහ؟ࣁ୚᥺Ӿ૪ᕪ੒objc_msgSendᬰᤈԧӞᅩՕᕨ҅፡᩸๶ හڍහғobjc_msgSendڍᭆጱݎ௳ᆐݸٚ๶፡፡ၾ objc_objectᕮ຅ᔄࣳጱ೰ᰒ҅ᬯӻᔄࣳጱ੒᨝ᚆड़᫨ഘ౮ձ֜Ӟᐿ੒᨝̶ ᤒ੔ತ੒ଫጱොဩᬩᤈ̶idฎӞӻڜᤒզ݊ᆿᔄොဩڜጱᔄ҅ᆐݸࣁᔄጱොဩ ᬯӻਫֺobjectಅંԭکᭆၾ௳෸҅Runtimeପտ໑ഝobjectጱisa೰ᰒತݎݻobject typedef struct objc_object *id; };      /// A pointer to an instance of a class.      OBJC_ISA_AVAILABILITY;          Class isa  of a class.      struct objc_object {          typedef struct objc_class *Class;      /// Represents an instance OCӾӞӻᔄጱ੒᨝ਫֺጱහഝᕮ຅ҁ/usr/include/objc/objc.h҂: } OBJC2_UNAVAILABLE; #endif ᦓ᱾ᤒ    ܐ // ;OBJC2_UNAVAILABLE     struct objc_protocol_list *protocols አጱපሲ̶     ᬯ෸տࣁmethod       ListsӾ᭭ܲ҅ইຎcacheԧ҅ଉአጱොဩ᧣አ෸੪ᚆड़൉ṛ᧣ Ӟӻၾ௳տ໑ഝisa೰ᰒັತၾ௳੒᨝҅کOBJC2_UNAVAILABLE; // ොဩᖨਂ҅੒᨝ള ᒫ ᶭ176 දߥଫ੒᨝ᒵץදਫሿොဩ҅ץᬦanInvocation੒᨝؉உग़॒ቘ҅ྲই (void)forwardInvocation:(NSInvocation *)anInvocationොဩ҅౯ժݢզ᭗ •    ᒫࢥྍғ୮ᒫӣྍᬬࢧොဩොဩᓋݷݸ҅੪տ᧣አ- ӥӞྍ̶فտᬰڞᤒᐏӧ॒ቘ̶ᝑᬬࢧොဩᓋݷ҅ ڞ*)methodSignatureForSelector:(SEL)aSelector೰ਧොဩᓋݷ҅ᝑᬬࢧnil҅ ᥝ᭗ᬦ- (NSMethodSignatureض౯ժḒڞ•    ᒫӣྍғᝑᒫԫྍᬬࢧጱฎnil҅ տ᧣አᧆ੒᨝ጱොဩ̶ڞᒫӣྍ̶ᝑᬬࢧ຤ӻ੒᨝҅فտᬰڞဌํߥଫᘏ҅ ᒫԫེ๢տ҅አԭ೰ਧߺӻ੒᨝ߥଫᬯӻselector̶ӧᚆ೰ਧԅself̶ᝑᬬࢧnil҅ᤒᐏ id)forwardingTargetForSelector:(SEL)aSelectorොဩ҅ᬯฎᬩᤈ෸ᕳ౯ժጱ) -ف•    ᒫԫྍғࣁᒫӞྍᬬࢧጱฎNO෸҅੪տᬰ ቘ҅ྌၞᑕਠླ̶॒کොဩ҅ၾ௳஑ےࣈႲ හۖாڍ᭗ᬦclass_addMethodڞӥӞྍ҅ᝑᬬࢧYES҅فᬰڞොဩ̶ᝑᬬࢧNO҅ےாႲ ۖވ•    ᒫӞྍғ+ (BOOL)resolveInstanceMethod:(SEL)selਫሿොဩ҅೰ਧฎ ইӥၞᑕғف ᬰ҅”ݎၾ௳᫨“ݎইຎಋۖ᧣አobjcmsgForward҅ਖ਼᪡ᬦັತIMPጱᬦᑕ҅ᘒฎፗള᥶ IMP msgForward =  _objc_msgForward; ̶ݎobjc_msgForwardտ੤ᦶ؉ၾ௳᫨_҅ײဌํਫሿጱ෸ ᭆӞ๵ၾ௳҅֕ਙଚݎጱғ୮ݻӞӻ੒᨝ݎ_objc_msgForwardฎIMPᔄࣳ҅አԭၾ௳᫨ ኞՋԍҘݎහฎ؉Ջԍጱ҅ፗള᧣አਙਖ਼տڍobjc_msgForward IMP • selectorIMPselector ੒ଫጱIMPࣈ࣎Ҙکruntimeই֜᭗ᬦselectorತ ࢩԅᬯ᯾ӧᕡ᧔ԧ̶ Ոᬯԍֵአᬦ҅ํکԒဌํ᭬پහ๶ਫሿ҅ӧᬦᬯᐿොୗڍ•    ᭗ᬦobjc_storeWeak •    } delegate, OBJC_ASSOCIATION_ASSIGN); •      objc_setAssociatedObject(self, @"__delegate__key", •    - (void)setDelegate:(id)delegate { •    // Ԟ੪ฎ᧔੒ԭ੒᨝ᔄࣳ҅੪ฎweakԧ •    // Specifies a weak reference to the associated object. •    // ೰ਧֵአOBJC_ASSOCIATION_ASSIGN҅ਥොဳ᯽ฎғ •     •    } return objc_getAssociatedObject(self, @"__delegate__key");      • ᒫ ᶭ177 ⼈ Objective-C ⼈每 ⼈每 每isa 每⼈ 每⼈每 ⼈ • ,⼈每 ۖாᕬਧ ጱ҂قᭆၾ௳ฎਞݎฎnilҁࣁObjective-CӾݻnil؀᷶ጱ೰ᰒἕᦊץweak ՗ᘒᦡᗝԅnil̶ ಅํզaԅᲫጱweak੒᨝҅کਂࣈ࣎ฎa҅ᮎԍ੪տզaԅᲫ҅ࣁᬯӻ weak ᤒӾ൤ᔱ҅ತ ইweak೰ݻጱ੒᨝ٖ؃տdealloc̶ײ᨝ٖਂࣈ֢࣎ԅkey҅୮ྌ੒᨝ጱ୚አᦇහԅ0ጱ෸ ӞӻhashᤒӾ̶ አweak೰ݻጱ੒فruntime੒ဳٙጱᔄտᬰᤈ૲ੴ҅੒ԭweak੒᨝տන runtimeই֜ਫሿweakݒᰁጱᛔۖᗝnilҘ ྌ҅ۖாᥴຉጱၞᑕ੪ᕮ๳ԧ̶کߥଫጱොဩ̶کဩ҅ᮎԍ੪տcrash҅ᆐݸ൉ᐏ಑ӧ void)doesNotRecognizeSelector:(SEL)aSelectorොဩ̶ᝑ౯ժဌํਫሿᬯӻො) -ف*)anInvocationොဩ҅ᮎԍտᬰ ᒫԲྍғᝑဌํਫሿ- (void)forwardInvocation:(NSInvocation    • ᒫ ᶭ178 
 viewUIScrollViewapp每 ◦ viewCPU能活 1. (lazy load) Views Ӿᕆ 
 ⽆每 iOSNSURLConnectiongzipAFNetworking 
gzip每每 每就app 3. gzip每app ◦ Sets: 每/⼀每 ◦ Dictionaries: 每 每 ⼀每 ◦ Arrays: 每indexlookupvalue lookup / 2. Collection每 
 background threadUIImageView每 UIImageView活UIScrollView每 UIImageView每能 1. Image Views每UIImageViewbundle 
 5. 
 4. XIB 
 3. views 
 2. reuseIdentifier 
 1. ARC ᳪᕆف ҁ23҂ ௔ᚆս۸ ◦ UITableViewUICollectionView: subview 每views 每 
 2. Cache, Cache, Cache! ◦ 每 ◦ UITableView每 ◦ NSCacheNSDictionary⼀ 每 3. 会.bundle每 
 4. .objectobjectsstrong references. 
 5. 
 6. objectsNSDateFormatterNSCalendar每 JSONXML每吧 class每 7. .每 
 8. .JSONXMLJSON每 iOS5JSON deserialization 每XMLXML SAX XMLjson 就每 能每 
 9. ◦ viewUIImageViewView 
 ◦ viewUIColorcolorWithPatternImage 
 ᒫ ᶭ179 10. Web每HTML每 javascript⽆每js每 scriptjavascript每 每 11. Shadow Path 每Core Animation 每shadowPath每shadow pathiOS 每path Viewviewframeupdate shadow path. 
 12. Table View ◦ reuseIdentifiercells ◦ view opaquecell ◦ ◦ ◦ cellweb ◦ shadowPath ◦ subviews ◦ cellForRowAtIndexPath: ◦ ◦ rowHeight, sectionFooterHeight sectionHeaderHeight delegate 13. ◦ NSUserDefaultsnice着 ◦ XML就 每SAX每 ◦ NSCoding每 ◦ SQLite Core Data每 每 ◦ SQLiteCore Data每 每 
 ◦ Core Datagraph modelSQLiteDBMS每 
 ◦ AppleCore Data SQLite每 
 ᒫ ᶭ180 ᒫ ᶭ181 ,没MacMacCPUiOS 能. • Time Profiler. 
 
image imageimageimageimageimageimageimageimageimageimageimageimage 
 
Xcode让Product->Profile,: • Analyze Profile ଘ෸֦ฎই֜੒դᎱᬰᤈ௔ᚆս۸ጱҘ 每 现javascript每dateFromUnixTimestamp1000 Cweb API 
  }   return[NSDate dateWithTimeIntervalSince1970:timestamp]; - (NSDate*)dateFromUnixTimestamp:(NSTimeInterval)timestamp { 
NSDate: Unix现每现 每NSDateFormatters啊每 4. 每NSDateFormatter 
 imageNamedimageWithContentsOfFile每 3. 每bundle 
 @autoreleasepool每 UIKitautorelease poolmemory每 release每 UIKit每每 2. Autorelease Pool每NSAutoreleasePool`blockautoreleased objects每 StoryboardsXcode 每XIB每 每 1. 每appapp ṛᕆ SQLiteC API每 SQLiteFMDBSQLite ◦ ᒫ ᶭ182 每 nibnib View ControllerviewXIB, ◦ XIBControllerXIB 每 YES每views每IB ◦ viewsViewsopaque UITableViewCell每 tableView:cellForRowAtIndexPath:rowscells ◦ reuseIdentifiertable view 每 每 view 经 view ◦ viewWillAppear viewWillAppear: view . • UIimage . • imageWithContentsOfFile,CPU • imageWithContentsOfFile,. . ., • imageNamed, • imageWithContentsOfFile • imagedNamed ᫹ࢶᇆ௔ᚆᳯ᷌ےUIImage delegate • rowHeight, sectionFooterHeight sectionHeaderHeight • cellForRowAtIndexPath: • subviews • cellweb • view opaquecell • reuseIdentifiercells ս۸Table View 0x8badf00d每 “”每crashlog ”每“”每 • iOS“ 
 每 ᒫ ᶭ183 3. 2.UDP 1. ෸ᳵս۸ۖސfacebook ᚆݝฎٌӾӞӻtemplate҅᯿ᅩᬮฎቘᥴӤᶎᳯ᷌୮ӾCPU GPUই֜ᯈݳૡ֢ጱᎣᦩ̶ network҅thread҅cpu҅gpuᒵᒵ҅ᶲᡕൾኈ݄਍ԟ҅ฎӞᒟ૤य़ጱᎣᦩᨰ੄̶ۖኮ௔ ᆧఀ̶֕ᬯ᯾ᶎٌਫ႗ፍԧᶋଉਠෆጱᦇᓒ๢चᏐቘᦞᎣᦩ֛ᔮ҅memory҅disk҅ ᘏ੒instrumentӧெԍݎ᪃ጱ෸ᳵ๶؉ս۸҅੕ᛘӧ੝୏شݪ᮷ࣁ᩷feature҅ଚဌํ لԧݱᐿtemplate݄ս۸app௔ᚆ޾ਧ֖ᳯ̶᷌உग़׀ᘏ൉ݎAppleጱinstrumentԅ୏ Instrument҂ ᳯ౯Ջԍฎڦҁމᦖᦖ֦አInstrumentս۸ۖኮ௔ᚆጱᕪܲ 
 UIImageView每能. UIImageViewbundle 
◦ Image Views 
 }); 
}); 
// UI 
dispatch_async(dispatch_get_main_queue(), ^{ 
// 能 
AULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEF 
每 appI/O ,国 每UIKit ◦ ᒫ ᶭ184 • :,APP • ,, Push Notification ฎই֜ૡ֢ጱҘ iOS, APNS,APNS ., • , ,. ,., • , ๜ࣈ᭗Ꭳ޾ᬱᑕവᭆ᭗Ꭳ੒च๜༷ஷ޾አဩҘ , • APNS,APNS • 最 ⼀每 每 • , • ڦ܄ݸݣ,ᬱᑕവᭆጱفധ޾ᑕଧᬰى಩ᑕଧᛔ૩ A.16  B.32  C.64  D.128 ᦜ๋ᬪ๜ࣈ᭗Ꭳහ๋य़ฎग़੝ҁc҂رiOS ଧ APNS,ٚኧAPNS಩ၾ௳വᭆᛗᦡ॓Ӥጱᑕکᭆݎ࢏Ӥጱᑕଧۓᘒᬱᑕ᭗Ꭳኧᬱᑕ๐ ,ڊݎ ᦡ॓ӤጱiOSڹࣁԭ๜ࣈ᭗Ꭳኧ๜ଫአᨮᨱ᧣አ,ݝᚆ՗୮ڦ܄ݣᬩᤈ.ԫᘏጱڹଫአᑕଧࣁ ๜ࣈ᭗Ꭳ޾ᬱᑕവᭆ᭗Ꭳጱच๜ፓጱ᮷ฎᦏଫአᑕଧᚆड़᭗Ꭳአಁ຤ԶԪఘ, ᘒӬӧᵱᥝ ౲ଫአᑕଧࢶຽӤጱஙᒍ.௳מޞපຎፘݶ,᮷ݢᚆดᐏԅӞྦྷᦄ ࢏ጱෛහഝ.ӧᓕฎ๜ࣈ᭗Ꭳᬮฎᬱᑕ᭗Ꭳ,՜ժࣁᑕଧኴᶎጱดᐏۓኞጱԪկ,Ԟݢᚆฎ๐ ݎਖ਼ܨᭆၾ௳,ᬯᐿၾ௳෬ݢᚆฎݎݣᬩᤈጱଫአڹ๜ࣈ᭗Ꭳ޾ᬱᑕവᭆ᭗Ꭳ᮷ݢզݻӧࣁ image image image image image image image image image image image 
 ๜ࣈ᭗Ꭳ޾ᬱᑕവᭆ᭗Ꭳ੒च๜༷ஷ޾አဩҘ ҁ24҂ ᭗ᎣӨവᭆ ᒫ ᶭ185 • 能 • 能经 ݢզ಩ྲ᫾ᘙ෸ጱ඙֢නࣁNSNotificationCenterӾވฎ remove • remove:,remove,机, • ,,时. remove? ԅՋԍ NotificationCenter ᥝ removeObserver? ই֜ਫሿᛔۖ APP,APPFdeviceToken ,APP,APP deviceToken,deviceToken ,,deviceToken, ,deviceTokenAPP,deviceToken uuidBundle idenidentifier,deviceToken APNS,,: • ᒫ ᶭ186 ෛUI Ӟӻٌ՜ᕚᑕ๶ᦇᓒ1+1 ଚӬ಩ᕮຎአԆᕚᑕดᐏࣁlabelӤๅސ୏ ՋԍฎOpenGL?ֵٍ֛አ 
 ᶱ᱾ᤒᭋଧܔٟӞӻ 每 • coreImageIOS5Objective-c⽆ አᬦcoreImage޾coreText?ইຎֵአᬦ҅᧔᧔֦ጱ֛ḵֵވฎ ୟپ᧗ᳯᖖᜋຽᓋํ Ոೌഩ҅ᒫԫེ҅ᒫӣེԞݶ໏ဌํՈೌഩ҅ᒫࢥེํӞӻՈೌഩԧ҅ ፲჋౭҅य़ਹᥧ஑ᛔ૩१Ӥฎᖖᜋຽᓋ੪ೌӞӥಋഩ҅ᒫӞེᳮ፲ဌ ᛔ૩१Ӥጱຽᓋ҅ᆐݸ୏তᳮکՈ१Ӥጱຽᓋ҅፡ӧڦکय़ਹ᮷ᚆ፡ ӞໟৼՈ҅ྯӻՈ᷐१Ӥ᮷ᩂํຽᓋ҅ᖖᜋ޾ᕁᜋ҅ᖖᜋᛗ੝1ӻ҅ ظ150 ޾ظ౮270ړጱᔥظጱᎾᎱ҅ெ໏ᑍᰁӣེਖ਼420ظ޾21ظํӞӻ6 ෸ᳵ॔๥ଶڊ դᎱਫሿӞӻଚٟܔጱහਁӾഭଧጱᓒဩํߺԶ҅ᓌڜ՗1-nӻԲଧ ᦇ҅ᗦ๞ᦡᦇกጮᬯӻၞᑕԍҘ තᨵݸ҅PݻB՞֦ྃ҅ᚆ੤ᦶ຤ᐿᤒᐏොୗ๶ᦏᑕଧާ҅Ծߝᦡ AᏟᦊکP஑Ӿᳵᨴಁ҅ᒵک՞ྃض᭦ᬋฎᵱᥝAۓࠓ҅Pଘݣጱӱڊ ሿBአಁํӳᥜݎইຎᦡᦇӞӻԻฃଘݣ҅ၞᑕইӥғAአಁࣁଘݣP • 每 每 每UML信 • ⼒UMLUnifiedModelingLanguage被 UML شᤑ——— ᒫ ᶭ187 经[b release]/self.b = nilb⼒release baddcba 2.removeFromSuperViewab 
每 retain/addSubViewa每delegateretainassign 1.aretain/addSubviewbb 
⽣ 
被每 被dealloc⼒dealloc 每每init⼒ dealloc 
• ⽣ ⽣每 0⽣0 ⽣每 
• instruments⽣ 每 ⽣⽣每 • Ҙހ٭ᔮᕹٖਂֵአఘڹํොဩັ፡୮ Ҙڊኞٖਂအᄋ޾ٖਂფݎӥտ٭Ջԍఘ ሿٖਂအᶂٖ҅ਂအᶂݸெԍᥴ٬ڊjsonᥴຉعই֜᭿ ෈կ҂ ᫹ጱjsے෈կ҅឴ݐxml෈կӾጱහഝٖ਻ଚดᐏ̶ҁݢᭌғhtmlӾ ᫹Ӟӻ๜ࣈxmlےwebview҅᧛ݐ๜ࣈጱhtml෈կ҅Html෈կӾտ ഘ҅ᒫԫ੽ํӞӻڔٟӞӻiphoneᑕଧ҅ํ2੽҅ݢզ᭗ᬦჶۖ ᔄࣳ؀զ“http://”҂҅නࢧBOOLވෙਁᒧԀฎ ڣܨฎUrlࣈ࣎ҁވෙਁᒧԀฎڣԅNSStringಘ઀Ӟӻොဩ҅ොဩᚆ ՋԍฎOOPҘ ҁ᧍ဩ҂Ҙڦ܄init޾initwithobject ᶉா᱾ളପ ffmpeg໛ຝ ᒫ ᶭ188 හਁҘۃெԍᬦᄁӞྦྷ෬ํਁᒧԀ݈ํහਁጱ҅ᦏ՜ݝ ᦡᦇӞӻ஺ኼय़ੜٟྲ᫾ӷӻਁᒧԀጱᓒဩҘ ತᓒဩҘັړἕٟԫ uikitचԭՋԍҘ ᫹ᘒአහഝପҘےNSFileManager/NSFileHandleԅՋԍӧአ෈կ ጱ̶ ӣᖌۖኮጱ෤᫨ጱܻቘҘବ੶ெԍਫሿҘᅩӨᅩ አ᪗ᴣݒഘਫሿ Ҙڦ܄᭦ᬋᬩᓒ᪙֖ᬩᓒጱ CFNetworkचԭࠨҘ ᠗ᇌ idฎᖫᦲ෸ᬮฎᬩᤈ෸ አᬦ1.0ҘވOAuth2.0ദ๦ጱᬦᑕ҅ฎ 
 • NSPredictxibUIview • NSMange Object Context • NSuserDefault ݪلெԍአӥᶎጱᔄҘ۹Ղߝᑀᜏᑀದํᴴ ᕳӞӻහᕟ[1̵3̵2̵4̵8]ഭଧݸ[1̵2̵3̵4̵8]Ҙ ฎӞᛘጱҘֺই12321޾4444ވෙ՗ૢ᧛޾՗ݦ᧛ฎڣᕳӞӻහਁ҅ ᔰҘزզ๋ளጱ᭛ଶັತ຤ӻ ᴻ҅զ݊ই֜ڢ҅ے᧗ٟӞӻᔄ֒ԭNSMutableArrayጱᔄ҅ݢզႲ ٟӞӻᨸݰᢐጱᓒဩ removeFromSuperView]每 subView1被经[b retainCount1,[super dealloc]subViewretainCount1,ba ᒫ ᶭ189 每 “Healthkit ”iPhoneiPad 201462分 HealthKitฎՋԍҘ autolayoutҘsizeclass 
 
 
 
 每每⽆ • iOS每- 
 • VPN SSL WAP/WAP2wifi 
 • 每256AES每 
 信 : • ګ๢ق᝘ຎெԍਫሿਞ ڦ܄ᬱᑕവᭆҔ๜ࣈၾ௳޾ܻࣈവᭆጱ C++ᑕଧ҅ᧇᕡٟӥ๶فࣁiPhoneӾெԍٟ Ջԍฎၾ௳വᭆҘ } 
return min + (max – min) *rand()/RAND_MAX; 
{ 
//⼒做int getRand⼒int minint max被被 =ํӻӧፘݶጱහ҅՗Ӿᵋ๢ݐNӻහ҅ᥝ࿢Nӻහ԰ӧፘݶ̶ Xݝኞᇔ҅࿢Tଙԏݸኞᇔጱ௛හฎग़੝Ҙํڡٟᑕଧ᩸ ᦡ຤ӞӻኞᇔྯBଙᔺྠӞེ҅ӞེᔺྠNӻݝ҅੖޸ฎMଙ҅ᖫ؃ Ձ ಸᲙړ݋ፑ ඪ՞ ඪ՞ਪඪ՞מᚆ̶ஙۑඪ՞ ᒫ ᶭ190 每 CoreDatasqlite sqlite3sqlCoreData每sqlite3CoreData CoreData:CoCoa⼈每 CoreData Match信Mobile Me :信信Documents in the Cloud信Photo Stream⼒被信iTunes 每 信信每 每iCloud 信每每 信就每每 ,5GB每信信信 iCloud信信,iCloud ⼒WWDC被iCloud, iOS 5 OS X Lion. iCloud201166微⼒Steve Jobs被 ҘۓԧߺԶದ๞Ө๐ތiCloudฎՋԍ۱ 每HomeKit 每 iCloudiOS每HomeKit 被Siri每HomeKitiOS 么每action⼒ HomeKit Accessory Protocol每HomeKit HomeKit2014每HomeKit HomeKitฎՋԍҘ HealthKitiPad每HealthKit⽆还每 每 每信信⼀每 HealthKit每HealthKit HealthKit每 HealthKit每M7每 
能好 HealthKit每iOS8.0么 每 每 HealthKit⽆每HealthKit ᒫ ᶭ191 每iPhoneiPadiPhoneiPad每 HandoffiOS 8.0 3.activity有每 2.activity每 1.activity每 Handoff ⼒TeamID被每 HandoffXcode iCloud每activity activity HandoffiCloud每 iCloud ⼒被Handoff每 NSUserActivity每 activity每activity Handoffactivity MacHand OffMaciPhone每 iPhoneiPhoneMaciPhone Yosemite“HandOff”MaciPad HandoffCDMA每OSX 10.10 ܖ೰ݎአ԰᭗ጱ ୏ ᧗ᥴ᯽ӞӥHandoffฎՋԍ҅ଚᓌᬿਙฎই֜ਫሿiOS̵Mac/ᗑᶭଫ context NSManagedObjectContextDidSaveNotificationNSManagedObjectContext 每 :CoreData 能 2.manager contextpersistent store coordinator 1.manager context persistent store coordinator 每coredatamanager context thread CoreDataӨग़ᕚᑕ඙֢:
还剩190页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 10 金币 [ 分享pdf获得金币 ] 8 人已下载

下载pdf

pdf贡献者

wenyang51

贡献于2017-07-25

下载需要 10 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf