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
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 603
 
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 68030
 
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

Similar Threads
thread Thread Starter Forum Replies Last Post
The "White is Girly" Argument ucfgrad11 Wasteland 14 Sep 21, 2013 05:24 PM
The old "Shipped vs Sold" argument - Apple admits.... Assault Alternatives to iOS and iOS Devices 24 May 14, 2013 08:31 PM
Can you determine "build date" from external box label? btomasie MacBook Pro 6 May 9, 2013 09:03 AM
My Logic "track expander tube" doesn't have "end tips" to grab! Whats up? kristenanne77 Digital Audio 3 Mar 28, 2013 08:15 AM
Why is the "choice" aspect of homosexuality so central to the gay equality argument? AP_piano295 Politics, Religion, Social Issues 56 Nov 19, 2012 03:33 AM

Forum Jump

All times are GMT -5. The time now is 02:28 AM.

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

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