简体   繁体   中英

Casting the return of objectAtIndex on NSArray

Trying to cast the return of objectAtIndex.

(MyClass *)[myArray objectAtIndex:1].name;

Can you cast inline like this in Objective-C?

是的你可以:

((MyClass *)[myArray objectAtIndex:1]).name

您可以通过使用常规方法调用语法替换访问属性的点语法来完全避免强制转换:

[[myArray objectAtIndex:1] name]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM