Objective-CBasicSyntaxIs the content to be introduced in this article, for beginners,Objective-cThere are a lot of confusing ways to write, in fact they are very elegant. What programmers write most isFunctionAnd calls self-written or written by othersFunction. This article starts fromFunctionFrom the perspectiveObjective-c.
C # AndObjective-cIt belongs to the C series language. Let's take a look at C #'sFunctionDefine and call.
C # Function Definition:
- public void doIt(string actorName, string movieName, int timesSeen)
- {
- Console.Write("{0} is my favorite actor in the movie {1}, I saw it {2} times.", actorName, movieName, timesSeen);
- }
Function call:
- Class1 objMovie = new Class1();
ObjMovie. doIt ("Leonardo DiCaprio", "dreamspace", 120 );
Let the. net programmer look at the definition of objective-c:
- - (void) doIt:(NSString *) actorName movieName: (NSString*) value timesSeen: (int)times
- {
- NSLog(@"%@ is my favorite actor in the movie %@, I saw it %i times.",actorName, value, times);
- }
If you read objective-c for the first time, you won't be able to figure out the above Code and wonder if it is wrong.
For the above function definition:
1. '-' indicates that this function is an instance function similar to a non-static function. '+' indicates that this function is a class function similar to a static function)
2. void) indicates that this function has no return value.
3. The function name is 'doit: movieName: timesSeen: ', not 'doit'
4. parameters are separated by Spaces
5. The parameter type is enclosed in brackets.
6. The parameters are divided into internal parameters and external parameters, such as the movie name. The internal parameters are: value, and the external parameters are: movieName,
7. A function parameter does not have the External Parameter Name and has an internal parameter name. For example, actorName.
Call ,:
From the code above, we can see that apart from the first parameter, other parameters can be added with external parameter names for difference.
We can see from the aboveObjective-cIt is very different from C #. net programmers.Objective-c FunctionsThe elegance of the design is that internal parameter names and external parameter names are both available, so you do not need to internally define variables to store them.Function.
Summary:Objective-CBasicSyntaxThis article is aboutObjective-c FunctionsFinally, I hope this article will help you!