Objective C override %@ for custom objects

前端 未结 2 668
予麋鹿
予麋鹿 2021-01-04 00:25

I\'d like to override the default print function in NSLog for custom objects;

For example:

MyObject *myObject = [[MyObject alloc] init];
NSLog(@\"Thi         


        
相关标签:
2条回答
  • 2021-01-04 00:55

    Just implement the description method.

    - (NSString *)description {
         return @"MyCustomDescription";
    }
    

    This is the method used to print an instance.

    0 讨论(0)
  • 2021-01-04 00:55

    Override -description in your custom class.

    0 讨论(0)
提交回复
热议问题