I. common error messages
1.
Error: 'xxx' undeclared (first use in this function)
Not Defined yet (used for the first time in this function ).
Note: If a variable is not defined before use, this error occurs. In OC and C, you must define the variable before using it.
This error often occurs when you forget to define variables. However, after getting used to it, this kind of error will rarely appear. On the contrary, this error is often caused by misspelling of the variable name, that is, the variable name used is inconsistent with the defined variable name.
Example:
-(Void) test
{
Int COUNT = 0;
Return conut + 1; // the variable count is inconsistent with conut. }
Correct syntax:
-(Void) test
{
Int COUNT = 0;
Return count + 1; // change the variable name count to the same one .}
2. Error: Parse error before 'xxx' token
A parsing error occurred before 'xxx.
Note: This error occurs only when a low-level error occurs. Parsing errors mean that the program statements cannot be parsed using the OC syntax. Take a closer look at the cause of the error and you will surely find the parts that do not conform to the syntax.
Example:
-(Void) test
{
Nsstring * STR = @ "this is test" // The semicolon is missing here
Nslog (STR );
}
3. Error: Invalid preprocessing directive # xxx
Keyword # XXX is incorrect.
Note: This error message is displayed when a spelling error occurs for the # include, # import and other keywords starting. In xcode, the string followed by # Will change color, which is very prone to errors.
Example:
# Improt <Cocoa/cocoa. h> // # incorrect import spelling
4. Error: XXX. h: no such file or directory
The file or directory named XXX. h does not exist.
Note: This information is displayed when the file specified in # include, # import does not exist. The most likely cause is that the file name is incorrect. Check the file name.
If this error occurs, check the actual file. It is possible that the file retrieval path is not specified correctly. As long as the file is included in the project folder, there is no problem.
Example:
# Import "appcontrler. H" // The appcontrler. h file does not exist.
Correct:
# Import appcontrller. h
5. Error: undefined symbols: 'xxx'
The symbol 'xxx' is not defined.
Note: This error occurs not only during compilation, but also during connection. This information is displayed when a nonexistent class or function is used for connection.
The most common error is that the function name is incorrect. When calling C functions, the compilation will pass even if the name is incorrect. However, this error occurs during connection.
Other possible reasons are that the frameworks or libraries other than cocoa are not included in the project. All required libraries or frameworks must be included in the project.
Ii. Common Warning Information
The warning must be fixed and ignored. However, it is quite comfortable to delete all warnings, so we should try to modify them as much as possible.
1. Warning: 'xxx' may not respond to 'yyy'
Class 'xxx' does not have the method 'yyy' declaration.
Note: When a method in a class is called, the class declaration does not contain this information. The first possible cause is that the method name is incorrect. Check the method name carefully to make sure it is correct.
Example:
Nsstring * STR;
STR = [nsstring stringwithforatm: @ "% d", 10]; // The method name is incorrect.
Correct:
Nsstring * STR;
STR = [nsstring stringwithformat: @ "% d", 10];
In addition, when a class calls a method defined by itself, if the method is appended to the class declaration, no problem will occur. If the actual call is in front of the method definition, this warning message is also displayed. This is because the compiler checks the method definition in sequence from the beginning of the file. With this feature, if you do not want other classes to call methods, you do not need to append them to the class declaration.
Example:
Warning:
-(Void) methoda
{
[Self methodb]; // The definition of methodb is later
}
-(Void) methodb
{
}
No warning:
-(Void) methodb
{
}
-(Void) methoda
{
[Self methodb]; // There is no warning when methodb is defined.
}
What will happen if you ignore this warning? First, compilation and connection are successful, so the application can be started. However, when the application is actually running here, it will check whether the called method is actually defined in the class. If not defined, an exception is thrown; otherwise, the Operation passes normally. Therefore, if you have already defined this method in the class, you can deliberately ignore this warning.
2. Warning: unused variable 'xxx'
The variable 'xxx' is not used.
Note: This information is displayed when the variable has been defined but is not used at one time. It is often said that the variable used in the past is no longer used after modification, but the definition is still saved. In this case, you only need to delete the definition of the variable. You can do this without deleting it.
In addition, this warning message is displayed when the defined variable name is inconsistent with the used variable name.
Example:
-(Void) test
{
Int A, B; // B is not used
A = 5;
Return;
}
Correct:
-(Void) test
{
Int A; // Delete the definition of B
A = 5;
Return;
}
3. Warning: Local declaration of 'xxx' hides instance variable
The local variable 'xxx' overwrites the instance variable (that is, the same name ).
Note: When the variable name defined in the method has the same name as a variable of the instance variable, this warning message is displayed. Because of the same name, all users will not be able to access it. In this case, the external instance variables cannot be accessed. Modify the variable names of one party.
Example:
@ Interface myobject: nsobject
{
Int count;
}
@ End
@ Implementation myobject
-(Void) updatecount :( INT) count
{
// The parameter name is the same as the instance variable name.
}
Correct:
@ Interface myobject: nsobject
{
Int count;
}
@ End
@ Implementation myobject
-(Void) updatecount :( INT) num
{
// Modify the parameter name to make it different from the instance variable name.
}
4. Warning: incomplete implementation of class 'xxx'
Warning: method definition for 'yyy' not found
The code for the class 'xxx' is not completed.
The definition of method 'yyy' is not found.
Note: This warning message is displayed when code execution is not written for a method in the class declaration. After a warning occurs, the Execution Code should be completed. If you feel that this method is not needed, you can delete the definition of this method in the class declaration file. In addition, if the method name in the actual code is inconsistent with the defined method name, this warning message is also displayed.
5. Warning: control reaches end of non-void Function
The return value is not set for a function of the non-void type.
Note: When a method or function requires a return value, no warning message is displayed when any return value is set. In methods other than void, you must return a specific value. If no return value is required, change the return value type of the method to void.
Conversely, if the return value is set to the void type, and a value is returned in a function or method, "'Return 'with a value, in function returning void (Return Value in void function) "Warning.
Example:
-(INT) test :( INT) count
{
Count ++; // The integer value must be returned without returning any value.
}
Correct:
-(INT) test :( INT) count
{
Return count ++;
}
6. Warning: Passing argument n of 'xxx' assignment from distinct objective-C type
The Nth parameter of method 'xxx' is different from the type of objective-C.
Note: When a parameter is passed to the method 'xxx', this warning is displayed when the parameter object passed is different from the parameter type declared in the method. For example, if the declared nsenumerator type is passed in as nsstring type, this warning is displayed.
The most likely cause is that there are many parameters for the method, and the order is wrong during the setting. When you use methods with many parameters and the warning message is displayed, check the Parameter order carefully.
In addition, you can use this warning when defining a method. If you want to specify the passed parameter as a specific class, define a clear type for the parameter. If any object can be used, it is defined as the ID type. The Parameter definition contains the information that the class designer gives to the user.
Example:
Int value = 3;
Nsstring * STR;
STR = [nsstring stringwithformat: "% d", value];
// The stringwithformat: parameter cannot be a C string.
Correct:
Int value = 3;
Nsstring * STR;
STR = [nsstring stringwithformat: "@ % d", value];
// Append the @ symbol before the parameter string