我想知道ARC在哪裏獲取方法簽名信息來完成其工作。 在下面的代碼中,我向這個對象的父對象發送一條消息,而沒有指定它的類。 如果我不註釋父級伊娃,編譯器會發出警告。 如果我將它轉換爲id,那麼該程序將工作,並且不會發出警告。同樣是真實 如果我使用performSelector:withObject:
ARC併發送消息給對象而無需在編譯時指定類
如果父方法是userSelected:
不同的,那麼,工程 的唯一事情是performSelector
(同時發出警告)。
據我所知,ARC正在從調用self.parent的對象中獲取方法簽名。它是否正確?如果方法簽名存在於發送消息的對象中,您是否可以避免告訴ARC對象是什麼類?
- (void)userSelected:(id)sender
{
if ([self.parent respondsToSelector:@selector(userSelected:)]) {
//1: This fails with error (no visible interface).
[self.parent userSelected:self];
//2: This line works without warnings.
[(id)self.parent userSelected:self];
//3: This line also works
[self.parent performSelector:@selector(userSelected:)
withObject:self];
}
什麼是警告? –