Re: Sending a Selector to another Class.

2009-10-22 Thread Rob Keniger

On 22/10/2009, at 3:52 PM, Joshua Garnham wrote:

 Ah, I see. so I need to send it to an instance of the class not the class it 
 self.
 How would I do that?


With respect, please understand that your questions are akin to this:

Q. How do I start the car?
A. You turn the key.
Q. How do I drive?
A. ummm

You need to learn the basics of Objective-C, it is very clear that you do not 
understand even the simplest concepts. 

To directly answer your question, you allocate and initialize an instance of 
your class using [[YourClass alloc] init], or using a convenience class method 
or other designated initializer. However, this information is unlikely to help 
you until you invest some time in learning Objective-C.

I personally recommend reading this book:

http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/0321566157

It's all laid down here though:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/index.html

--
Rob Keniger



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-22 Thread Paul M

With all due respect, but by 'directly answering the question' you
are doing the OP and all those reading this list a dis-service.
You are just rewarding his lazyness.

The OP has already been told to bone up on Obj-C basics, and he's
obviously completely ignored this advice, the reason being that
people continue to answer his silly questions.

He will learn how to find his own answers if forced to do so, and
will become a much better coder as a result.

It's much better for him and for all the rest of us, if you would
please refrain from 'directly answering the question in these
circumstances.


paulm



On 22/10/2009, at 7:12 PM, Rob Keniger wrote:



On 22/10/2009, at 3:52 PM, Joshua Garnham wrote:

Ah, I see. so I need to send it to an instance of the class not the  
class it self.

How would I do that?



With respect, please understand that your questions are akin to this:

Q. How do I start the car?
A. You turn the key.
Q. How do I drive?
A. ummm

You need to learn the basics of Objective-C, it is very clear that you  
do not understand even the simplest concepts.


To directly answer your question, you allocate and initialize an  
instance of your class using [[YourClass alloc] init], or using a  
convenience class method or other designated initializer. However,  
this information is unlikely to help you until you invest some time in  
learning Objective-C.


I personally recommend reading this book:

http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/ 
0321566157


It's all laid down here though:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ 
ObjectiveC/index.html


--
Rob Keniger



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/list%40no-tek.com

This email sent to l...@no-tek.com



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-22 Thread Jim Kang
Jens, thanks for clearing up the thing about the selector defining a message
(method plus parameters) rather than a method and thus not being tied to a
class.

On Thu, Oct 22, 2009 at 1:21 AM, Jens Alfke j...@mooseyard.com wrote:


 On Oct 21, 2009, at 9:43 AM, Jim Kang wrote:

 That selector is a unique index that points to a method of a specific
 class.


 No, that's not true of Objective-C (although it is of C++ method-pointers.)
 A selector is, basically, just a unique string: it defines a *message*,
 not a method, to use the old Smalltalk OOP terminology.


However, a selector is not a string. I was just listening to this podcast
with Mike Ash, and he discusses this around the 9:23 mark or so:

http://podcast.mobileorchard.com/episode-23-mike-ash-on-the-objective-c-runtime-objects-and-the-runtime-message-sending-and-no-such-method/

He explains that comparing strings is too slow for the runtime to use for
finding messages and so it uses integers to represent the messages and calls
them selectors.


 Any class that implements a method with that name uses the same selector
 for it, regardless of inheritance.

 To be specific, if I create two unrelated classes A and B, each of which
 implements a -foo method, the selector @selector(foo) is used for both.


This is really good to know.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-22 Thread Bill Bumgarner

On Oct 22, 2009, at 5:54 AM, Jim Kang wrote:

 However, a selector is not a string. I was just listening to this podcast
 with Mike Ash, and he discusses this around the 9:23 mark or so:
 
 http://podcast.mobileorchard.com/episode-23-mike-ash-on-the-objective-c-runtime-objects-and-the-runtime-message-sending-and-no-such-method/
 
 He explains that comparing strings is too slow for the runtime to use for
 finding messages and so it uses integers to represent the messages and calls
 them selectors.

Selectors are strings, but it is an implementation detail.

The runtime uniques the strings such that there is only ever one instance of, 
say, the drawRect: selector floating about.  Thus, the runtime can use 
pointer comparison to determine selector equality.

It is an implementation detail though.  One that is exceedingly unlikely to 
ever change but, still, an implementation detail.

Use the Objective-C runtime API if you want to do selector comparison.

sel_isEqual(), IIRC.

b.bum

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-22 Thread Jens Alfke

On Oct 22, 2009, at 5:54 AM, Jim Kang wrote:

However, a selector is not a string. I was just listening to this  
podcast

with Mike Ash, and he discusses this around the 9:23 mark or so:

http://podcast.mobileorchard.com/episode-23-mike-ash-on-the-objective-c-runtime-objects-and-the-runtime-message-sending-and-no-such-method/

He explains that comparing strings is too slow for the runtime to  
use for
finding messages and so it uses integers to represent the messages  
and calls

them selectors.


This statement is true; however those integers happen to be the memory  
addresses of unique instances of the strings*. This makes it very  
efficient for the runtime to convert a selector to an NSString, and  
vice versa, and also helps with debugging (in gdb you can just type  
print (char*)sel to inspect a selector.)


—Jens

* C strings, not NSStrings.___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-22 Thread Kyle Sluder

On Oct 22, 2009, at 9:01 AM, Jens Alfke j...@mooseyard.com wrote:

This statement is true; however those integers happen to be the  
memory addresses of unique instances of the strings*. This makes it  
very efficient for the runtime to convert a selector to an NSString,  
and vice versa, and also helps with debugging (in gdb you can just  
type print (char*)sel to inspect a selector.)


Don't forget NSStringFromSelector, which I find is usually more  
convenient and doesn't rely on implementation details. Invoke it in  
GDB by casting its return value to id:


po (id)NSStringFromSelector(_cmd)

(Although I have noticed that gdb is much better about inferring when  
it can expect an object return value from a function/method call).


--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-22 Thread Jeff Johnson

On Oct 22, 2009, at 10:53 AM, Bill Bumgarner wrote:


Selectors are strings, but it is an implementation detail.

The runtime uniques the strings such that there is only ever one  
instance of, say, the drawRect: selector floating about.  Thus,  
the runtime can use pointer comparison to determine selector equality.


It is an implementation detail though.  One that is exceedingly  
unlikely to ever change but, still, an implementation detail.


Use the Objective-C runtime API if you want to do selector comparison.

sel_isEqual(), IIRC.

b.bum


http://twitter.com/gparker/status/2400099786

Ignore bbum. We hereby promise never to break == for SEL. (But SEL is  
not char*. We will break that.)


And now that it's on the mailing lists, it can be considered part of  
Apple's official documentation. ;-)


-Jeff

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-22 Thread mmalc Crawford

On Oct 22, 2009, at 9:54 am, Jeff Johnson wrote:

 Ignore bbum. We hereby promise never to break == for SEL. (But SEL is not 
 char*. We will break that.)
 And now that it's on the mailing lists, it can be considered part of Apple's 
 official documentation. ;-)
 
It already is:

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/sel_isEqual

mmalc

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Sending a Selector to another Class.

2009-10-21 Thread Joshua Garnham
How would I send a Selector to another class?
I know to send it to a selector in the same file you do 
[self performSelector:@selector(doSomething)];

and for sending it to another class I've tried 
[otherClass performSelector:@selector(doSomethingElse)];

But I just get an error in the Debugger saying
+[otherClass doSomethingElse]: unrecognized selector sent to class 0xe5c4

What have I done wrong?

Thanks.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-21 Thread I. Savant

On Oct 21, 2009, at 12:23 PM, Joshua Garnham wrote:


How would I send a Selector to another class?
I know to send it to a selector in the same file you do
[self performSelector:@selector(doSomething)];

and for sending it to another class I've tried
[otherClass performSelector:@selector(doSomethingElse)];

But I just get an error in the Debugger saying
+[otherClass doSomethingElse]: unrecognized selector sent to class  
0xe5c4


What have I done wrong?


  You seem to be missing the very basics of Objective-C (and I'd dare  
to say object-oriented programming topics in general). You should (re) 
read the introductory material in the documentation and take advantage  
of places like cocoadevcentral.com (free articles) to get a handle on  
this.


The Objective-C Programming Language
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html

Cocoa Application Tutorial
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCTutorial/01Introduction/01Introduction.html

CocoaDev Central
http://www.cocoadevcentral.com

--
I.S.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-21 Thread Shawn Erickson
On Wed, Oct 21, 2009 at 9:23 AM, Joshua Garnham
joshua.garn...@yahoo.co.ukwrote:

 How would I send a Selector to another class?
 I know to send it to a selector in the same file you do
 [self performSelector:@selector(doSomething)];


Why not simply... [self doSomething] ?


 and for sending it to another class I've tried
 [otherClass performSelector:@selector(doSomethingElse)];


Why not simply [otherClass doSomethingElse] ?

...aka... Why are you using performSelector in the above?


 But I just get an error in the Debugger saying
 +[otherClass doSomethingElse]: unrecognized selector sent to class 0xe5c4

 What have I done wrong?


You are sending a message to an object that doesn't respond to that message
(aka no implementation for it). The error message you listed should have
more information about the class of the object you messaged incorrectly,
what does the rest of it say?

Hard to tell what may be going wrong with the limited information you have
posted. I rather not waste time guessing (can think of at least 4 common
things you could be doing wrong).

-Shawn
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-21 Thread Joshua Garnham
Hi,

That was all that showed up in the debugger, but in the class otherClass there 
is a method called doSomething. 
I have also tried what you suggested - [otherClass doSomethingElse] - but i get 
a warning in xcode, http://cld.ly/7c4la.
(JGManagedObject is what replaces otherClass)

Thanks.




From: Shawn Erickson shaw...@gmail.com
To: Joshua Garnham joshua.garn...@yahoo.co.uk
Cc: cocoa-dev@lists.apple.com
Sent: Wednesday, 21 October, 2009 18:02:55
Subject: Re: Sending a Selector to another Class.




On Wed, Oct 21, 2009 at 9:23 AM, Joshua Garnham joshua.garn...@yahoo.co.uk 
wrote:

How would I send a Selector to another class?
I know to send it to a selector in the same file you do
[self performSelector:@selector(doSomething)];


Why not simply... [self doSomething] ?
 

and for sending it to another class I've tried
[otherClass performSelector:@selector(doSomethingElse)];


Why not simply [otherClass doSomethingElse] ?

...aka... Why are you using performSelector in the above?
 
But I just get an error in the Debugger saying
+[otherClass doSomethingElse]: unrecognized selector sent to class 0xe5c4

What have I done wrong?


You are sending a message to an object that doesn't respond to that message 
(aka no implementation for it). The error message you listed should have more 
information about the class of the object you messaged incorrectly, what does 
the rest of it say?

Hard to tell what may be going wrong with the limited information you have 
posted. I rather not waste time guessing (can think of at least 4 common things 
you could be doing wrong).

-Shawn



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-21 Thread Quincey Morris

On Oct 21, 2009, at 10:02, Shawn Erickson wrote:


But I just get an error in the Debugger saying
+[otherClass doSomethingElse]: unrecognized selector sent to class  
0xe5c4




You are sending a message to an object that doesn't respond to that  
message
(aka no implementation for it). The error message you listed should  
have
more information about the class of the object you messaged  
incorrectly,

what does the rest of it say?


The error message has enough information -- the +.

The problem is that the OP sent an instance method selector to the  
class object, which obviously doesn't recognize it. That indicated a  
confusion between classes and instances (at a minimum), which drove  
I.S. into the well known demented-schoolmarm-handing-out-homework  
impersonation. :)

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-21 Thread Phillip Mills

- Message from joshua.garn...@yahoo.co.uk -


but i get a warning in xcode, http://cld.ly/7c4la.
(JGManagedObject is what replaces otherClass)


That one is usually a case of not importing the JGManagedObject header 
or not declaring the class method in that interface.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-21 Thread Jim Kang
That selector is a unique index that points to a method of a specific class.
Methods themselves belong to a specific class and can't operate outside of
their classes. (They compile down to regular C functions that accept an
additional object parameter.)
So, it doesn't make sense to use one class's selector on another class.
Maybe these two classes should inherit from a common parent that has the
method you want to share.

On Wed, Oct 21, 2009 at 12:23 PM, Joshua Garnham joshua.garn...@yahoo.co.uk
 wrote:

 How would I send a Selector to another class?
 I know to send it to a selector in the same file you do
 [self performSelector:@selector(doSomething)];

 and for sending it to another class I've tried
 [otherClass performSelector:@selector(doSomethingElse)];

 But I just get an error in the Debugger saying
 +[otherClass doSomethingElse]: unrecognized selector sent to class 0xe5c4

 What have I done wrong?

 Thanks.



 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/jimkang%40gmail.com

 This email sent to jimk...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Sending a Selector to another Class.

2009-10-21 Thread Joshua Garnham
Ah, I see. so I need to send it to an instance of the class not the class it 
self.
How would I do that?


Thanks,
Josh.



From: Jens Alfke j...@mooseyard.com
To: Jim Kang jimk...@gmail.com
Cc: Joshua Garnham joshua.garn...@yahoo.co.uk; cocoa-dev@lists.apple.com
Sent: Thursday, 22 October, 2009 6:21:29
Subject: Re: Sending a Selector to another Class.



On Oct 21, 2009, at 9:43 AM, Jim Kang wrote:

That selector is a unique index that points to a method of a specific class.


No, that's not true of Objective-C (although it is of C++ method-pointers.) A 
selector is, basically, just a unique string: it defines a message, not a 
method, to use the old Smalltalk OOP terminology. Any class that implements a 
method with that name uses the same selector for it, regardless of inheritance.

To be specific, if I create two unrelated classes A and B, each of which 
implements a -foo method, the selector @selector(foo) is used for both.

Joshua's problem was, apparently, that he was trying to send an message to a 
class object instead of an instance, but the corresponding method was defined 
on instances, not the class.

—Jens



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com