iOS override description method, custom console (log) information

Source: Internet
Author: User

Description is a method that all classes have.

We override this method to customize the information for the instance output.

For example, we create a person class:

Add two properties to the. h file:

#import <Foundation/Foundation.h>@interface*int age ; @end

Override the description method in the. m file:

#import " Person.h " @implementation Person-(NSString *) description{    return [nsstring stringWithFormat:@ "  <%p>-Name:%@, Age:%d", Self, _name, _age];} @end

Let's call it:

Person *person =@ "xiaoming"; NSLog (@ "person–%@", person);

The console will then output:

Person-<0x7fa20bc18d10

This is the custom output method in my description.

If we do not override the description method, the result of the console output is:

0x7fccd1e1c5f0>

To summarize:

That is, when we output all the properties of the class to the console, we can rewrite the description method so that we can observe the properties of the class at any time.

PS: When you do not override the description method, only the printed class name and the memory address of the class are displayed by default.

iOS override description method, custom console (log) information

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.