• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie question on Methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question on Methods


  • Subject: Re: Newbie question on Methods
  • From: Mike Abdullah <email@hidden>
  • Date: Sun, 12 Mar 2006 16:36:48 +0000
  • Resent-date: Sun, 12 Mar 2006 16:42:06 +0000
  • Resent-from: Mike Abdullah <email@hidden>
  • Resent-message-id: <email@hidden>
  • Resent-to: email@hidden


On 12 Mar 2006, at 16:10, Bobby B wrote:

Hello there, this is my first post so let me introduce myself.  I
working through some of the beginner exercises on Cocoadev.com.  I
have a lot of past experience developing simple applications (medical
billing, etc) for the PC in Delphi.  This is my "entrance" to
ObjC/Cocoa/MacOSX programming.  I have a pretty decent understanding
of C.  I've read the majority of Apple's document "Introduction to
Objective C".

There is one concept I'm not understanding. In the
NSOpenPanelWithFileTypes example (on CocoaDev.com) there is the following code:


NSArray *fileTypes = [NSArray arrayWithObject:@"td"];
NSOpenPanel *oPanel = [NSOpenPanel openPanel];

I understand that in the first line you are declaring an instance of
the class (fileTypes) of the NSArray object.

Correct, you are making NSArray object that you have "called" fileTypes

But I don't understand
the part that follows it.  Why do you send the message to the NSArray
instead of to the fileTypes class?

Well, normally you would send the message you would like to the instance (fileType). You would do this:


NSArray *fileType = [[[NSArray alloc] initWithObject: @"td"] autorelease];

However, by sending the arrayWithObject to NSArray, it is doing the alloc and autorelease bit for you. It's just a nice sort of convenience method.

And the same question follows for
the NSOpenPanel right below it.

I was using the following code for the NSOpenPanel:

NSOpenPanel * op;
op = [[NSOpenPanel alloc] init];

How is that functionally different from:

NSOpenPanel *oPanel = [NSOpenPanel openPanel];

In the case of the open panel, this is different. The openPanel inherits (eventually) from NSWindow, and the designated initializer for this is not init but initWithContentRect:styleMask:backing:defer:


However, the openPanel does things in its own "special" way, and so the only way of creating one is by using:

	[NSOpenPanel openPanel];


Is it something regarding object methods and instance methods? To further obfuscate my question, when do you have to do the [[Receiver alloc] init] method? I notice when you declare a string : NSString * myString =@"This is my string"; you don't have to run [[NSString alloc] init]; on it. Why is this?

Thank you kindly
Bobby B
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden

Hope that helps you a little.

Mikel.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Popup List Contains <MyObject 0x1234>
  • Next by Date: Re: Advice On Where To Start
  • Previous by thread: Re: Newbie question on Methods
  • Next by thread: Re: Newbie question on Methods
  • Index(es):
    • Date
    • Thread