Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

Viewed 80482

I'm currently using the iOS 5 SDK trying to develop my app. I'm trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before with no issues). Now, I came across this: "Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects."

This is my code: .h

@interface ViewController : UIViewController {
     NSString *newTitle;
}
@property (strong, nonatomic) NSString *newTitle;

.m

@synthesize newTitle;

Does anyone have a clue how I could fix this? Thanks!!

10 Answers

In CoreData if you use "new..." in attribute (compile normally) it will crash randomly with a "bad access" exception.

There is no crash log and the line shown with the "All Exceptions Breakpoint" will not help you at all.

NS_RETURNS_NOT_RETAINED is used to solve the naming problem.

@property (nonatomic, copy) NSString *newTitle NS_RETURNS_NOT_RETAINED;

We can find its definition as follows:

#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))

The 'ns_returns_not_retained' attribute is the complement of 'ns_returns_retained'. Where a function or method may appear to obey the Cocoa conventions and return a retained Cocoa object, this attribute can be used to indicate that the object reference returned should not be considered as an "owning" reference being returned to the caller. The Foundation framework defines a macro NS_RETURNS_NOT_RETAINED that is functionally equivalent to the one shown below.

Related