[問題] self and [self class]

看板MacDev作者 (電腦真耗錢)時間14年前 (2010/06/07 11:44), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
最近在看書, 看到下面一段function, 心中有點疑問: - (id) copyWithZone: (NSZone *) zone { Engine *engineCopy; engineCopy = [[[self class] allocWithZone: zone] init]; return (engineCopy); } // copyWithZone 這個function 是在implement NSCopying的protocol 當中的 [self class] 和 self有什麼不同?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.219.26.209

06/07 11:51, , 1F
self指向自己的pointer~ [self class] 回傳自己class
06/07 11:51, 1F

06/07 11:52, , 2F
self不知道自己是什麼class..除非用self class
06/07 11:52, 2F

06/07 12:02, , 3F
恍然大悟! 我這笨蛋~ 感謝感謝~~
06/07 12:02, 3F
文章代碼(AID): #1C36iGzS (MacDev)