Using static keyword in objective-c when defining a cached variable

后端 未结 3 1909
悲&欢浪女
悲&欢浪女 2020-12-07 18:53

I\'m looking at the following apple example source code:

    /*
 Cache the formatter. Normally you would use one of the date formatter styles (such as NSDate         


        
3条回答
  •  太阳男子
    2020-12-07 19:24

    "static" functionally means "don't evaluate the stuff on the right side of the equals sign every time through, use its previous value instead" in this case.

    Use this great power with great responsibility: you run the risk of using a whole ton of memory, since these are objects that never go away. It's rarely appropriate except for in cases like this one with NSDateFormatter.

提交回复
热议问题