Objective-C: static field and implementing singleton pattern
问题 Good day, friends. Once again stupid question about Obj-C from newbie :) I'm trying to implement singleton design pattern in Obj-C: @interface SampleSingleton : NSObject { @private static SampleSingleton* instance; } +(SampleSingleton*) getInstance; Compiler returns error: "expected specifier-qualifier-list before 'static'". 回答1: Please find below the Objective-C code snippet I am using, for proper thread-safe singleton implementation header file : /* * * Singleton interface that match Cocoa