According to the search on Google, looks like it doesn't officially have value/reference type. If it doesn't have, what's the counterparts? What's it called? Is it called 'Obj-C class and non Objc-C class' or 'static type and dynamic type'?
However, to me, a NSString object in obj-c 'works' like a reference type in C#. It'll lead to a compiling error "statically allocated instance of Objective-C class ..." if to define it without '*'
NSString * pstr = [[[NSString alloc] init] autorelease];
Some native types, like NSInteger or C struct, which can be created without '*', can I say it 'works' like a value type in C#?
NSInteger i = 0;
There are many kinds of value types in Swift, such as struct , enum , and tuples. You might not realize that Objective-C also uses value types in number literals like NSInteger or even C structures like CGPoint .
Use a value type when you want copies to have an independent state, and the data will be used in code across multiple threads. In Swift, Array , String , and Dictionary are all value types.
In Objc string, array and dictionary are all reference types, while in Swift they are all value types.
Variables of reference types store references to their data (objects), while variables of value types directly contain their data. With reference types, two variables can reference the same object; therefore, operations on one variable can affect the object referenced by the other variable.
All Objective-C objects are accessed by a pointer. In that sense they are all reference types.
Some Objective-C types define object equality (the -isEqual: method) as something other than pointer equality. These types behave as value-like types. Such types include NSString and NSNumber.
Types that are not Objective-C classes can be true value types in the C# sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With