Is there a way to log all the property values of an Objective-C instance

前端 未结 5 1652
庸人自扰
庸人自扰 2021-02-04 03:22

I was just wondering if there is a quick and easy way of printing out to the log all of the various values of the properties to my class for debugging purposes. Like I would lik

5条回答
  •  一向
    一向 (楼主)
    2021-02-04 03:47

    The quick and dirty would be to override debugDescription:

    -(NSString*)debugDescription {
        NSString *str = [[NSString alloc] initWithFormat:@"My BOOL 1: %d, My Float: %f", self.myBool, self.myFoat];
        return str;
    }
    

    Of course, if your object is complex, this could be time consuming.

提交回复
热议问题