Error building 32-bit OS X app?

2019-02-21 16:13发布

问题:

I'm working on my first Mac OS X app. My project was set-up with XCode defaults and I haven't touched any Build Settings. When building for Mac 64-bit, the app runs fine. However, when building for Mac 32-bit, I get a seemingly arbitrary error that says:

Semantic issue: Synthesized property 'myProperty' must either be named the same as a compatible ivar or must explicitly name an ivar.

What kind of things can I check for?

回答1:

It sounds like you have found the error but I think I can answer your question just in case someone else later finds it.

Apple has made a lot of changes in the 64 bit Objective-C runtime which they couldn't do before since it would break binary compatibility. One of the things that is different is that in the 32 bit runtime synthesized properties have to be backed by instance variables. On the 64-bit runtime synthesized properties sill needs that but they are created automatically for you. By default the name of the instance variable should be the same as the name of the property.

So in case you need to support 32 bit then make sure that you create instance variables for all your properties. If you only support 64 bit then you can still do that so that your code can be built for both 32 bit and 64 bit at the same time but you don't have to.



回答2:

You can set the NS_BUILD_32_LIKE_64 preprocessor macro in Xcode for the the 32bit build target. This will save you the trouble of maintaining separate code for 32bit and 64bit versions.