In article
<75d8031e-7183-47c5-937d-e918b435aa54 RemoveThis @z23g2000prd.googlegroups.com>,
SLR <Sean.Raborg RemoveThis @gmail.com> wrote:
> Hi everybody. First off, I'd like to say I'm a complete noobie at
> Objective C/Cocoa programming, but I'm trying really hard to get
> things down. I'm really trying to learn how to program for the iPhone.
> I have some questions that are probably extrememly basic, but I
> haven't found any real answers for online or in any Objective-C/Cocoa
> book (I'm sure the answers are out there, I just can't find it).
>
> 1. What is the difference between brackets and parenthesis?
>
> For example, what is the difference between these
>
> [NSString someMethod]
This attempts to call a class method named someMethod on the NSString
class (not on any particular NSString instance). You'd need to add a
semicolon to make it complete. Even then it would only compile if
"someMethod" is actually a placeholder you're using for a method that
actually exists on NSString.
>
> and
>
> (NSString *) someMethod
This is (almost) a declaration of a method that takes no arguments and
returns an NSString. To be complete it needs either a "+" or "-" at the
start to indicate whether it's a class method or an instance method.
> 2. Is there a way to determine object type in an array (or just in
> general)?
>
> For example, lets say I had a simple inheritance setup: abstract car
> class with subclasses for Honda, Ford, Toyota, Dodge, etc. Now I
> create a mutable array of car objects and fill it with various
> subclass objects. Is there a function to determine the object type of
> a specific element in the array?
You can call the "class" method on any object to get a reference to its
class object. You can use "isKindOfClass" to ask an object if it's an
instance of a specific class.
> 3. I am really lost when it comes to creating constants and
> enumerations
>
> Lets say I have the following code:
>
> const screenWidth = 320;
> const screenHeight = 480;
> enum week { Mon, Tues, Wed, Thurs, Fri, Sat, Sun };
>
> Where do I place this code? Does it belong in a header file in the
> @interface section or in the @implentation section, or some other
> obscure place? I've seen quite a few different opinions online, but
> I'd like to learn the correct way to do this.
There's no single right answer, it depends on where you want those
declarations to be available. C scoping rules offer a variety of
solutions depending on what you need to have happen.
--
Tom "Tom" Harrington
Independent Mac OS X developer since 2002
http://www.atomicbird.com/