NSLog an object's memory address in overridden description method

前端 未结 2 1438
情话喂你
情话喂你 2020-12-22 21:51

I am overriding an object\'s description method. I need to know how to print the object\'s memory address to replace {???} in the code below:

-(NSSt         


        
2条回答
  •  北海茫月
    2020-12-22 22:07

    To print address use %p format specifier and self pointer:

    -(NSString *) description {
        return [NSString stringWithFormat:@"\nparmeterOne: %@\nparameterTwo: %@",
                self, self.parameterOne, self.paramterTwo];
    }
    

提交回复
热议问题