what is this weird code notation mean

前端 未结 3 824
迷失自我
迷失自我 2021-01-29 02:27

what\'s this line mean when using the second NSDictionay beside the message body:

NSDictionary *item = (NSDictionary *) [self.content objectAtIndex:indexPath.row];

相关标签:
3条回答
  • 2021-01-29 02:31

    This is a cast, as in C.

    In your case, "self.content" seems to be an NSArray. So [self.content objectAtIndex:indexPath.row] would be an NSObject. Except that here, for some reason, you know it's an NSDictionary. So you explicitly cast it in order to avoid a compiler warning (that would tell you "hey, you're assigning an NSObject to an NSDictionary variable)

    0 讨论(0)
  • 2021-01-29 02:43

    self.content is a property of type NSArray (I guess!)

    This line returns you the Object (which seams to be a NSDictionary) at Index indexPath.row. (NSDictionary*) casts the object to NSDictionary.

    0 讨论(0)
  • 2021-01-29 02:44

    (NSDictionary *) a type cast. It tells the compiler to assume that the object returned by the objectAtIndex: method is of the type NSDictionary * even though the return type of the method is different.

    0 讨论(0)
提交回复
热议问题