Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 7, 2013, 08:02 AM   #1
Vishwas Gagrani
macrumors newbie
 
Join Date: Sep 2012
What is the logic of "no label" for 1st argument of a function

Curious to know, if there is any logic behind the syntactical structure, where 1st argument is not labelled, but following arguments only need labelling ?


Code:
[myObject myFunction:firstArgument theSecondArgument:secondArgument];

Or is it just how it is made. There is no logic. ?
Vishwas Gagrani is offline   0 Reply With Quote
Old Jan 7, 2013, 08:21 AM   #2
KoolStar
macrumors Demi-God
 
KoolStar's Avatar
 
Join Date: Oct 2006
Location: Kentucky
Send a message via AIM to KoolStar Send a message via Skype™ to KoolStar
Typically if you were to create a method signature it would be something that would label the first argument itself. This can be seen with almost any of apples method signatures.

Code:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCELL_IDENTIFIER];
We can see that the first argument is prefixed with with initWithStyle thus labeling the first argument as a style and telling us that the function call is an init function.

Another such example in MKMapKit, imagine _mapView is an MKMapView reference.

Code:
[_mapView convertCoordinate:coordinate toPointToView:self.view];
We are converting a coordinate to a specific view that is provided by the first argument.

The logic behind the naming is to be descriptive that is the nature of Objective-C.
__________________
"Innovation distinguishes between a leader and a follower." : S.J.
KoolStar is offline   1 Reply With Quote
Old Jan 7, 2013, 08:57 AM   #3
Vishwas Gagrani
Thread Starter
macrumors newbie
 
Join Date: Sep 2012
ok, thnx for explanation.

However, when i think something like this :
Code:
[ mathObj addTheNumbers:number0  number1:number1 ]
it looks to me awkward. But may be it's just a matter of practice.
Vishwas Gagrani is offline   0 Reply With Quote
Old Jan 7, 2013, 09:21 AM   #4
phr0ze
macrumors 6502
 
Join Date: Jun 2012
Location: Columbia, MD
Quote:
Originally Posted by Vishwas Gagrani View Post
ok, thnx for explanation.

However, when i think something like this :
Code:
[ mathObj addTheNumbers:number0  number1:number1 ]
it looks to me awkward. But may be it's just a matter of practice.
Wouldn't it be better to pass that in another way?
__________________
2012 11" MBA i7/8/256
2011 Mac Mini with 27" Thunderbolt Display
Black iPad Air 64GB Verizon
Black iPhone 5S 32GB ATT
phr0ze is offline   0 Reply With Quote
Old Jan 7, 2013, 09:58 AM   #5
KoolStar
macrumors Demi-God
 
KoolStar's Avatar
 
Join Date: Oct 2006
Location: Kentucky
Send a message via AIM to KoolStar Send a message via Skype™ to KoolStar
Quote:
Originally Posted by phr0ze View Post
Wouldn't it be better to pass that in another way?
If I were writing that method I would most likely name it some to this affect.

Code:
[mathObj add:sumNumber to:sumNumber];
__________________
"Innovation distinguishes between a leader and a follower." : S.J.
KoolStar is offline   0 Reply With Quote
Old Jan 7, 2013, 11:39 AM   #6
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Shouldn't that be a class method instead of an instance method?
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 7, 2013, 11:50 AM   #7
KoolStar
macrumors Demi-God
 
KoolStar's Avatar
 
Join Date: Oct 2006
Location: Kentucky
Send a message via AIM to KoolStar Send a message via Skype™ to KoolStar
Quote:
Originally Posted by ArtOfWarfare View Post
Shouldn't that be a class method instead of an instance method?
Honestly something as trivial as adding numbers should be a function not even a method of a class or object. Whether it be a static or instance class.

In that case it would be:
Code:
int add(int x, int y)
{
     return x + y;
}
With usage of:
Code:
int result;
result = add(10, 20);
I think the original poster was simply asking about naming convention used for objective-c methods regardless or static or instance.
__________________
"Innovation distinguishes between a leader and a follower." : S.J.
KoolStar is offline   0 Reply With Quote
Old Jan 7, 2013, 05:08 PM   #8
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
addNumber:toNumber:

https://developer.apple.com/library/...uidelines.html
PhoneyDeveloper is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:40 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC