WARNINGS
Warnings should be fixed, but you will not be prevented from running your app. Your app may run just fine, or your app may crash. Depends upon the nature of the warning. Rule of thumb: fix them.
Unused Variable
Brief: You defined a variable, but then you didn't do anything with it. The
variable is
unused.
Code example:
Code:
- (void)anyMethod
{
NSString *aVariable = @"Hey There"; // warning: unused variable 'aVariable'
}
Consequences:
Nothing, really. This is a helpful message to let you know that you went to the effort to declare something, but then you didn't do anything with it.
Possible Solutions:
1. Do something with the variable somehow. Ex:
Code:
[[self aTextField] setText:aVariable];
2. Delete or comment out the offending code
May Not Respond
Brief: You are calling a method on a particular class. The compiler is not finding that method declared (in .h file) for that class. The compiler does not know if the class implements that method.
Code example:
Code:
- (void)anyMethod
{
[self doThatThingYouDo]; // warning: 'RootViewController' may not respond to '-doThatThingYouDo'
}
Consequences:
Depends on whether the method actually is implemented in .m file. If it is, your app will work just fine. If it isn't, your app will crash when this line is executed.
Possible Solutions:
1. Verify that you are calling the correct kind of object. The warning message tells you which class type is being called - RootViewController. Make sure that is the correct target.
2. Verify that the method is declared in the .h file. In this case:
Code:
- (void)doThatThingYouDo;
3. In some situations, the compiler may not know what kind of object you are dealing with (the type is "id"). You can help the compiler by typing the object.
Code:
[(NSString *)[theArray objectAtIndex:0] length];
In this case, we are telling the compiler to assume that the item in the array is a string. Now it knows that length is a valid method. IMPORTANT: This does not force the objects in the array to become strings. If you have views in the array instead, that will be bad at run time.
Local Declaration of Variable Hides Instance Variable
Brief: You have defined an instance variable, AND defined a local variable with the same name. So you're not using your instance variable.
Code example:
Code:
// .h
@interface RootViewController : UIViewController
{
NSString *aVariable;
}
// .m
- (void)anyMethod
{
NSString *aVariable = @"Hey There"; // warning: local declaration of 'aVariable' hides instance variable
aVariable = @"Oops";
}
Consequences:
You are only messing with the local variable, not the instance variable. It's as if your instance variable doesn't exist. So if we log this variable at a later time:
Code:
NSLog(@"aVariable is: %@", aVariable);
...
aVariable is: (null) // Uh, thought it should be "Oops". Oops!
Possible Solutions:
1. Use a different variable name:
Code:
NSString *notThatVariable = @"Hey There";
2. Don't re-declare the variable:
Code:
aVariable = @"Hey There";
IMPORTANT: Messing with instance variables in this way is very dangerous. See the properties link in my signature for a better approach.
ERRORS
Errors must be fixed. You will not be able to run your app until they are fixed.