Objective-c----NSLog ()

Source: Internet
Author: User

Concept

NSLog () can use the%@ format specifier to output an object. When NSLog () processes the%@ specifier, it asks the corresponding object in the argument list to get a description of the object. Technically, NSLog () sends a description message to the object, and then the description method of the object generates a NSString and returns it. NSLog () will include this string in the output result. The description method is provided in the class to customize how the NSLog () outputs the object.
In the custom description method, you can choose to return a literal nsstring, such as @ "Gkejlkgjlkghkehgl", or you can construct a string that describes the various types of information about the object. In cocoa, the Nsarray class manages a collection of objects, and its description method provides information about the array itself, such as the number of objects in the array and the description that each object contains. Of course, the description of an object is obtained by sending an description message to an object in the array separately.

Note:%@ just invokes the description method for each object and displays the result.

Example code

. h file:

#import "Person.h"@interface Test : Person@end

. m File:

#import "Test.h"@implementation Test- (NSString *)description {   return (@"1234567890");}@end

In the main () function:

new@"%@", _oneTest );

Output Result:

Objective-c----NSLog ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.