In objective-c, why 'typedef NSString * MyString' is preferred over 'typedef NSString MyString'?

Viewed 848

Option 1: typedef NSString MyString

Option 2: typedef NSString * MyString


Question

In Objective-C, both statement are valid, but from what I've seen people overwhelmingly choose option 2 over option 1. Is there a technical reason to that, or is it more of a convention?


Why I preferred option 1

Option 2 hides the fact that MyString is a pointer. This might be the intention, but in objective-c it's more often than not that you do want to know whether you're dealing with a primitive type or a reference type.

In C, at least the convention is to give it a name like MyStringRef to emphasize that it's a pointer, but I don't think I ever seen anyone does that in objective-c.


But option 1 doesn't play nicely with Swift

And then there's Swift. Both option 1 and option 2 works perfectly fine when bridged to swift, but if I try to mark option1 as a enum- typedef NSString MyString NS_STRING_ENUM; FOUNDATION_EXPORT MyString * const MyStringOne;

the compiler starts to freak out. Syntax highlight and auto-completion breaks all the time. And something like var x = MyString.one chokes the compiler straight out, leaving only the Segmentation fault: 11 error.

1 Answers
Related