Using same name for Core Data object as a Private Framework Object
I've got a core data-based app for iPhone and I'm getting the following w开发者_Python百科arning:
objc[2472]: Class Property is implemented in both /System/Library/PrivateFrameworks/Notes.framework/Notes and /var/mobile/Applications/B69194FF-448F-48AD-A78D-DDB8935F/AmcCalc.app/AmcCalc. One of the two will be used. Which one is undefined.
When I started working on this app back with SDK 3.0 I didn't get this error, so how do I deal with this?
Thanks! Bjorn
This is a naming collision.
The flexibility provided by runtime binding requires a global name space. This means that the name of any symbol in the app can collide with any other symbol. The symbol for class attributes have the class as part of their internal name so they rarely collide. More often you have two classes with the same name.
In this case you have a class in the app's source with the same name as a class in the Notes framework. It's most likely a class named "Property" if I recall the error format correctly. (It could also be saying that you have a property of a class that is defined twice.)
As good practice, you should name your classes with a suffix or prefix unique to your company or person. For example, if you release software under Bjorn Geez Software, you could use "BGS". So:
@interface PropertyBGS : ...//new style
@interface BGSProperty : ...//old style
Better yet, make your class names more descriptive and avoid any names that are related to reserved words or common programing terminology.
For example, if you were writing a real estate app, you would be tempted to use "Property" as the name of a class to model an actual building but "property" itself shows up in code so you should make the name more unique and descriptive such as:
@interface RealEstatePropertyBGS : ...//new style
@interface BGSRealEstateProperty : ...//old style
This not only prevents naming collisions but makes the code more readable and self documenting.
精彩评论