Cannot declare variable inside @interface or @protocol

前端 未结 4 1672
时光说笑
时光说笑 2021-01-31 18:19

I have an iOS app built since the beginning with an error in it. Since the source was began constructed from the template, its appdelegate.h looks like:

@interfa         


        
4条回答
  •  自闭症患者
    2021-01-31 19:00

    They can't go there. You can put them inside the curly braces {} like this:

    @interface myAppDelegate : NSObject  {
        UIWindow *window;
        myViewController *viewController;
    BOOL       myBool;     // intended to be globally accessible
    NSString   *myString;  // intended to be globally accessible
    }
    
    @end
    

    And that makes them global to the implementation class. But if you want them global to every class in your app then you should drop them in your App-Prefix.pch file:

    //
    // Prefix header for all source files of the ... project
    //
    #import 
    BOOL       myBool;     // intended to be globally accessible
    NSString   *myString;  // intended to be globally accessible
    #ifndef __IPHONE_3_0
    

提交回复
热议问题