Synthesized Properties and ivar error

£可爱£侵袭症+ 提交于 2021-02-07 18:11:09

问题


I've been building my program in the "Debug X86-64" mode (Xcode 3.6) and everything works flawlessly. However, I just tried switching to "Release X86-64" mode and upon compiling received the following errors for each of my properties:

Synthesized property 'x' must either be named the same as a compatible ivar or must
explicitly name an ivar.

Where 'x' is one of my properties, the first being 'company' (I received 51 errors of this type.). In my .h interface file, I've listed the items this way:

@property (copy) NSString   *company,
                        *address1,
                        *address2,
                        *city,
                        *usState,
                        *zip,
                        *phone,
                        *fax,
                        *email,
                        *web; // etc, etc.

In my .M implementation file, I've synthesized them as so:

@synthesize company,
        address1,
        address2,
        city,
        usState,
        zip,
        phone,
        fax,
        email,
        web; // etc, etc.

My understanding was that the instance variables are automatically created for these properties... in fact, they seem to be working perfectly, up until I try to compile in "release" mode.

I couldn't find anything in the books I have to explain this. Am I doing something wrong, or more specifically, what should I include to fix this for "release" compiles?

Thanks!


回答1:


I believe I have answered my own question here. I have done two things to correct these errors:

First, I've added instance variable declarations in the interface file. Second, I changed the @Synthesize directives to this:

@synthesize company = company;
@synthesize address1 = address1;
etc...

This has fixed all of the errors and everything compiles correctly in both build and release modes.




回答2:


There is another quick solution: also add those properties in the delegate definition

    @interface YourAppDelegate : NSObject <NSApplicationDelegate> {
      NSTextField * company;
      NSSlider * company;
         ...
     }

    @property (copy) NSString   *company,
                                *address1,
                                ... ;



回答3:


Disable 32-bit architecture in the build settings if you just want to release, but don't want to bother with "old" runtime limitations. (Actually what "new" runtime has finally got, was implemented in IBM SOM since 1991, so "old" and "new" are very relative when it comes to Objective-C runtime, but that's another story.)



来源:https://stackoverflow.com/questions/10476385/synthesized-properties-and-ivar-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!