关于 Objective-C 中的指针
我偶然发现了以下内容,似乎无法弄清楚为什么会这样。请您解释一下为什么我不需要在 range
之前使用指针?
NSString *d = @"The quick brown fox";
NSRange range = [d rangeOfString:@"brown"];
I stumbled across the following and can't seem to work out why this works. Please can you explain why I don't need to use a pointer before range
?
NSString *d = @"The quick brown fox";
NSRange range = [d rangeOfString:@"brown"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSString
是一种对象类型。所有对象类型都是指针,不能在堆栈上创建。NSRange
是一个 C 结构体。结构可以在堆栈上创建,因此不一定都是指针。没有一个好的指南来了解哪些是对象,哪些是结构。您只需在继续操作时检查每种类型即可。
NSString
is an object type. All object types are pointers and can't be created on the stack.NSRange
is a C-struct. Structs can be created on the stack, and thus aren't necessarily all pointers.There isn't a good guide to know which ones are objects, and which are structs. You'll just have to check for each type as you move forward.