Reputation: 20115
Here's some background on my program: [self.channels
] is an array of Channel
objects. Each Channel
object has a synthesized string called channelId
.
Compiles
Channel *channel = [self.channels objectAtIndex:indexPath.row];
NSString *channelId = channel.channelId;
Does not compile
NSString *channelId = [self.channels objectAtIndex:indexPath.row].channelId;
// Request for member 'channelId' in something not a structure or union
Why couldn't I chain my commands to get the channelId
property? The two versions of my code look the same...
Upvotes: 1
Views: 1382
Reputation: 157
In your first version the compiler knows what kind of object you are working with since it is using a Channel* variable to reference the data member. In your second version the compiler only knows that an NSObject may be returned but has no immediate knowledge that the returned object will be of a certain class. You can change this by casting the returned value:
NSString *channelId = ((Channel*)[self.channels objectAtIndex:indexPath.row]).channelId;
Upvotes: 3