2011-05-16 83 views
1

這裏是我的程序的一些背景:[self.channels]是一個Channel對象的數組。每個Channel對象都有一個稱爲channelId的合成字符串。請求會員在一些不是結構或工會

編譯

Channel *channel = [self.channels objectAtIndex:indexPath.row]; 
NSString *channelId = channel.channelId; 

不編譯

NSString *channelId = [self.channels objectAtIndex:indexPath.row].channelId; 
// Request for member 'channelId' in something not a structure or union 

爲什麼我不能連鎖我的命令,以獲得channelId財產?我的代碼的兩個版本看起來是一樣的...

+0

的可能的複製:[目的C:在一些要求會員XXX不是一個結構或聯合(http://stackoverflow.com/questions/5534105您可以通過鑄造返回的值更改此/ ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * – 2011-05-16 08:13:03

回答

3

在您的第一個版本中,編譯器知道您正在使用哪種對象,因爲它使用Channel *變量來引用數據成員。在你的第二個版本中,編譯器只知道一個NSObject可能被返回,但沒有立即知道返回的對象是屬於某個類的。

NSString *channelId = ((Channel*)[self.channels objectAtIndex:indexPath.row]).channelId;