Initialising a static variable in Objective-C category

后端 未结 5 701
南笙
南笙 2020-12-23 18:10

I was trying to create a static variable to store a dictionary of images. Unfortunately, the best way I could find to initialise it was to check in each function that used t

5条回答
  •  别那么骄傲
    2020-12-23 19:06

    __attribute__((constructor))
    static void initialize_navigationBarImages() {
      navigationBarImages = [[NSMutableDictionary alloc] init];
    }
    
    __attribute__((destructor))
    static void destroy_navigationBarImages() {
      [navigationBarImages release];
    }
    

    These function will be called automatically when the program starts and ends.

提交回复
热议问题