Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-08-2010, 08:08 PM   #2 (permalink)
Kalimba
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,178
Default

Quote:
Originally Posted by creig View Post
I am a complete noob about Objective-C. My background is in C and Java, and I am just starting to learn how to develop for the iPhone. I am trying to understand some of the concepts that don't easily map to APIs I understand.

In the iPhone SDK class UIApplication, it creates a UIApplicationDelete protocol that includes the following two methods:

- (void)applicationWillResignActive: (UIApplication *)application;

- (BOOL)application: (UIApplication *)application handleOpenURL: (NSURL *)url;

I understand the first syntax as it is basically (return type) functionName: functionArgument.

I am struggling to understand the syntax of the second method. If handleOpenURL is the method name, what is the role of "application: (UIApplication *)application"? The documentation indicates "application" is a parameter, but I don't understand why it appears between the return type and the method name.

I have not been able to find out what the syntax means or even whether I am comprehending it correctly. And since am just beginning, I don't have the vocabulary mastered enough to know what terms to search for.

Thanks.
As someone who had been writing C/C++ code for decades before diving into Obj-C, I feel your pain. IMO, learning how to "see" the syntax of Obj-C functions is one of the most difficult hurdles to get over when starting in this language.

In virtually every other "popular" programming language, function declarations have a return type, followed by the full function name, followed by a parameter list. In Obj-C, however, the function name and the parameter list actually interleave each other when the function takes more than 1 argument. When the function takes 1 or fewer arguments, the function syntax should look similar to other languages, as in the case of the first function declaration you posted.

Let's break down the second function declaration:
Code:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url;
This is a class instance function/method, because that's what the "-" symbol indicates.

The return type follows, in parentheses. This function will return a BOOL data type.

What follows is an interleave of function name "parts", and function parameters. The name part includes everything up to and including the colon ":". A parameter type in parentheses is next and the parameter name follows. This pattern is repeated for as many function parameters there are. The actual function name is built by concatinating all of the name "parts".

In this instance, the actual function name is "application:handleOpenURL:". The function accepts two parameters, a UIApplication * which is named "application" and an NSURL * named "url".

The first parameter named "application" is entirely coincidental to the fact that the first function name part is "application:". This parameter can simply be named "app", and the function declaration will then look like:
Code:
- (BOOL)application:(UIApplication *)app handleOpenURL:(NSURL *)url;
Hope this helps.
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
 

» Advertisements
» Online Users: 349
20 members and 329 guests
ADY, apatsufas, BdR, catedawn, Duncan C, georg8betx, Graham, Gurpartap Singh, iph_s, joeallenpro, john love, jorge599, kampftrinker, MarkC, Naughty_Ottsel, RoryHarvey, sadr1an1, superg, syver
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,876
Threads: 89,225
Posts: 380,699
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jorge599
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.