Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 28, 2012, 03:54 AM   #1
Prasoon
macrumors newbie
 
Join Date: Jul 2012
In doubt

Can you please explain the code below?

Code:
-(id)initWithName:(NSString *)newName atFrequency:(double)newFrequency;

Last edited by OllyW; Jul 28, 2012 at 11:54 AM. Reason: Please use code tags
Prasoon is offline   0 Reply With Quote
Old Jul 28, 2012, 01:25 PM   #2
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: San Diego, CA USA
It is a declaration of an Objective-C object instance method with 2 parameters. Presumably it initializes a previously allocated object.
mfram is offline   0 Reply With Quote
Old Jul 28, 2012, 03:17 PM   #3
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Quote:
Originally Posted by Prasoon View Post
Can you please explain the code below?

Code:
-(id)initWithName:(NSString *)newName atFrequency:(double)newFrequency;
mfram explained it well, but I thought I'd break it down by component.
-
This indicates an instance or object method. This means you call this method on an instance of this class. The other option is a + which you call on the class itself. This is used for utility methods, object factories, etc.
(id)
This indicates the return type, which is id in this case. id is the most generic object pointer. It can point to any sort of object.
initWithName:
This is part of the method name. Objective-C methods have "segmented" names with arguments interspersed so each argument has a label, making it easier to know what the argument does, rather than just its type.
(NSString *)
This indicates the type of the first argument. NSString is the Cocoa string implementation. The * indicates that the type is a pointer to an NSString. You will see this for every object type, as Objective-C dynamically allocates all objects on the heap, so you never have a "local" object used without a pointer.
newName
This is the name of the first argument, and what will be used in the method to refer to it.
atFrequencydouble)newFrequency
This is the second segment of the method name, the type of the second argument (double is a double precision floating point value. It is a primitive type.), and the name of the second argument.

-Lee
lee1210 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
RMBP config doubt macran MacBook Pro 7 Apr 2, 2013 05:23 PM
iPhone 5 Actual Doubt Kidder1994 iPhone 26 Jan 4, 2013 09:41 PM
iPhone: Doubt on Facebook Korez iOS 6 2 Sep 13, 2012 08:00 AM
Doubt about the partition. ismar23 OS X 10.8 Mountain Lion 2 Jul 30, 2012 11:21 AM

Forum Jump

All times are GMT -5. The time now is 05:50 AM.

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

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