Hello can you give me an example of the usage of this method
+(NSString *)description
Do I use description with an instance of a NSObject (any kind of object) or NSString?
or do I use without an instance, directly using NSObject (any kind of object) or NSString?
The NSObject defines all things that are shared between all classes that extend from it: NSObject is the root class of most Objective-C class hierarchies. Through NSObject, objects inherit a basic interface to the runtime system and the ability to behave as Objective-C objects.
Subclassing NSObject in Swift gets you Objective-C runtime flexibility but also Objective-C performance. Avoiding NSObject can improve performance if you don't need Objective-C's flexibility.
NSString is the abstract base class for a cluster of classes representing strings. Its interface does not include any methods to change the string contents after initialization. NSMutableString is the abstract base class for a cluster of classes representing strings whose contents can be changed.
The description of the instance gives you information about the specific instance you have created.
- (NSString *)description;
NSString *string = [NSString alloc] initwithString:@"aString"]];
[string description];
Gives you information about this instance (location in memory etc)
On the other side:
+ (NSString *)description;
[NSString description];
Gives you information about the class NSString.
The same rules apply to all NSObject subclasses and other classes that conform to NSObject protocol such NSArray, NSDictionary *NSProxy* etc
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