xcode: property 'title' 'copy' attribute does not match super class 'UIViewController' property - iphone

Hi I'm currently getting this error message. and by the love of banana, I cannot figure out what I am not doing right.
Its just an
IBOutlet UILabel *title;
and
#property(nonatomic, retain) IBOutlet UILabel *title;
I've made which is connected to my xib file connected to a UILabel because I dynamically change the title during run time.
Classes/../taskViewController.h:44: warning: property 'title' 'copy' attribute does not match super class 'UIViewController' property
I dont understand what it means.
Normally i am able to get rid of warning messages. But this one... I dont have a clue whats going on.
Can someone please guide me and explain what is happening here.

Your problem is that UIViewController already defines a title property and you are using a different memory manangement option than it does. To fix this, change the name of your property. ex: #property (nonatomic, copy) UILabel *titleLabel;. If you want the instance variable to have the same name, and you use #synthesize, use #synthesize titleLabel=title;.
As an aside, why are you copying a UILabel? Normally you would use retain so that it is the same object.

It means:
you have a subclass of UIViewController
it contains a property named "title"
you have declared the property with the "copy" attribute
the parent class (UIViewController) already has "title" property with a conflicting definition (i.e., not "copy")

Well i want to just clarify that title is a predefined object in the UIViewController so you cannot create your own objects with that same name, change the with some thing else and see that it wont give you that error.

Related

issue with custom delegate and datasource

I have a custom delegate and datasource. But I have several problems with it when I try to initialize it. In my .h file if have it like this.
#property (nonatomic, assign) id<UITableViewDelegate> delegate;
#property (nonatomic, assign) id<KalDataSource> dataSource;
This has as an result that in the synthesize in the .m file I get the following error.
Existing ivar 'dataSource' for property 'dataSource' with assign attribute must be __unsafe_unretained.
After some google search magic I found that I should assing my variables like this.
#property (nonatomic, strong) id<UITableViewDelegate> delegate;
#property (nonatomic, strong) id<KalDataSource> dataSource;
But then I get this error.
linker command failed with exit code 1 (use -v to see invocation)
Can anybody help me with this?
Kind regards!
The error you're experiencing has nothing to do with your memory qualifiers (they were right the first time around). The problem lies in the fact that you have declared a backing iVar somewhere without qualifiers. When iVars are declared, they are implicitly strong, so if you go to your shadowing iVars, and prepend __weak or __unsafe_unretained, the warning should disappear. Of course a better solution would be to just remove your backing iVars altogether, because Xcode will synthesize them for you.
Delegates are usually weak references.
The object using the delegate doesn't own it.
It's just a reference to an object which could, or could not be responding.
Weak says, that if the real owner of the object releases it, it should be deallocated.
The weak reference is then automatically set to nil and you don't get any zombies.
Second, the problem is, that you already have property called dataSource.
EDIT
My previous statement about the duplicate property turns out to be wrong.
You should override the setters & getters, both the declaration in the .h and the implementation in the .m file.

Property attributes in custom setters/getter

If I create property, for example:
#property NSString *selectedSubProductId;
and create setter and getter:
- (NSString *)selectedSubProductId {}
- (void)setSelectedSubProductId:(NSString *)value_ {}
XCode says that "Deault property attribute 'assign' not appropriate for non-gc object". Do attributes have any meaning in this case? Does it matter if i make them copy or assign or are they only cue for #synthesize to create desired methods? If so, how should I disable the warnings?
If it is object, you should use retain/copy property modifier.
For example:
#property (nonatomic, retain) NSString *selectedSubProductId;
If the modifiers are missing, assign modifier is enabled by default. But it is only valid for scalar (int, float...) or struct.
You may get more details in Apple Documentation
That warning says that you are using a default property atribute (assign) because you forgot to say how do you want to hold your object.
If you want to "remove" the warning use a retain/copy property:
#property (copy) NSString *selectedSubProductId;
However, in Strings you should use copy. For more information please visit this question on stackoverflow.

Do I need to declare a private variable for an IBOutlet* property?

Let's say I have a simple view controller with one UITableView property:
#interface MyViewController : UIViewController {
UITableView *tv; // <-- DO I NEED THIS??
}
#property (nonatomic, retain) IBOutlet UITableView *tv;
#end
Do I actually need to declare the UITableView *tv ? I've found that even if I don't declare it (and simply #synthesize the property), everything works fine. Yet, lots of code samples explicitly declare the variable. I'm not sure what the benefit of declaring it (or the harm of not declaring it) is.
In Objective-C 2.0, the compiler will synthesize the storage for you as well as the accessors. That didn't used to be the case, hence all the examples where people explicitly declare the ivar.
No you do not have to declare it, synthesize will take care of dynamically injecting the code at compile time. You will on the other hand not be able to inspect the variable directly in Xcode if you do not declare it, that's the downside.

Help: Instance Variables & Properties [iPhone]

In something like this:
#interface Control_FunViewController : UIViewController {
UITextField *nameField;
UITextField *numberField;
}
#property (nonatomic, retain) IBOutlet UITextField *nameField;
#property (nonatomic, retain) IBOutlet UITextField *numberField;
I understand that "UITextField *nameField;" is an instance variable and "#property ..." is a property. But what do these individual things do?
I guess what I'm really asking is how the property is used for example in the implementation file (.m)
The instance variables are the actual variables, whereas the properties are the equivalent of
- (UITextField *)nameField;
- (void)setNameField:(UITextField *)newTextField;
and completely optional. They are also used by the compiler to understand exactly what you want when you #synthesize a variable. Basically the properties and corresponding #synthesize (or custom implementation) allow OTHER classes access to variables, and are completely optional. It is in fact generally recommended, as per standard object oriented encapsulation principals, not to use properties unless you specifically intend for them to be used by external classes. However, you still need Interface Builder to recognize the UITextFields (presumably) which is why we typically put the IBOutlet decorator before the ivar declaration, not the property.

Editing and iPhone SDK Framework?

I am working with MapKit and want to be able to add a (NSString *)itemTag value to each of my annotations. I have created myAnnotiation.m and myAnnotation.h
I tried adding itemTag to the myAnnotation.h/m but when I try to access currentAnnotation.itemTag within my main code, it says "itemID not found in protocols" - so I went to the MapKit.Framework and into MKAnnotation.h. I added (NSString *)itemID, but when I save the .h file in the Framework, it changes the file's icon and doesn't appear to by jiving with everything else.
Any help or links to help would be greatly appreciated. I am not even sure if I'm on the right path here, but Googling "modify iphone sdk framework" does not turn up much.
Why are you trying to modify the framework? You should be defining itemID as a property or instance variable (or both) in myAnnotation.h. You say that currentAnnotation.itemTag
didn't work; for that to work, you need to have itemTag defined as a property of whatever class currentAnnotation belongs to.
Changing the header file for the framework won't recompile it, so you won't be able to get that to work.
EDIT: Here's an example.
In MyAnnotation.h:
#interface MyAnnotation : NSObject <MKAnnotation> {
NSString *itemID;
// Other instance variables
}
#property (nonatomic, retain) NSString *itemID;
// Class and instance methods.
#end
In MyAnnotation.m:
#implementation MyAnnotation
#synthesize itemID;
// Your code here.
#end
The #property call defines the property and the #synthesize call will create setters and getters for you (methods to set and retrieve the value of itemID). In MyAnnotation.m, you can use self.itemID or [self itemID] to get the value of itemID, and you can use self.itemID = #"something" or [self setItemID:#"Something"] to set the value.
EDIT 2:
When you get currentAnnotation, if the compiler doesn't know that the annotation is an instance of your MyAnnotation class, it won't know about itemID. So, first ensure that you've included this line at the beginning of your .m file:
#import MyAnnotation.h
That wil ensure that the compiler knows about the class. When you use currentAnnotation, you cast it as an instance of MyAnnotation like so:
(MyAnnotation*)currentAnnotation
That should quiet down the warnings.