How to find the size of any object in iOS?

前端 未结 5 1855
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 12:45

I was optimizing my app and wanted to know that how much is the size of the object, so that I can also show it in log.

suppose I have

NSDictionary *t         


        
5条回答
  •  無奈伤痛
    2020-12-23 13:01

    In objective- C:

    NSString *sampleString = @"iOS Programming";
     NSLog(@"size of object: %zd", malloc_size((__bridge const void *)(sampleString)));
    
    You need to include:
    #import
    

    In Swift:

    var name: String = "Hello World!"
    
    sizeofValue(name)
    
    var someValue: Double = 10.5
    
    sizeofValue(someValue)
    

提交回复
热议问题