Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[NSObject description]

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?

like image 793
Michael C Avatar asked Aug 07 '12 20:08

Michael C


People also ask

What is an NSObject?

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.

What is the use of NSObject in Swift?

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.

What is an NSString?

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.


1 Answers

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

like image 157
gsach Avatar answered Oct 23 '22 03:10

gsach