Re: makeObjectsPerformSelector on a sub class

2012-03-22 Thread T.J. Usiyan
Another option would be a container holding just the tiles.

On Wed, Mar 21, 2012 at 5:06 PM, James Bucanek wrote:

> Pascal Harris >
> wrote (Wednesday, March 21, 2012 7:56 AM -):
>
>
>  Now I want to scramble the state of each of the tiles.  In the game
>> controller, I'm using the following code:
>>
>> [[self.view subviews] makeObjectsPerformSelector:@**
>> selector(scrambleState)];
>>
>> I've put a breakpoint in scrambleState - and it never gets called. I'm
>> guessing that 'makeObjectsPerformSelector' fails to work because
>> scrambleState
>> is not a method in UIView. Question is, what do I need to do in order to
>> ensure that this code gets called?
>>
>
> Others have made a lot of valid suggestions and points, but if it wasn't
> mentioned I have another reason this would fail:
>
> You must ensure that *all* subview of self.view implement -scrambleState.
> The first object in the collection that doesn't implement this method will
> throw an exception and the iteration will stop.
>
> Safer, although longer, would be:
>
> // (warning: typed in mail)
> UIView* subview;
> for ( subview in self.view.subviews )
>if ([subview respondsToSelector:@selector(**scrambleState)])
>[subview scrambleState];
> --
> James Bucanek
>
>
>
> __**_
>
> 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:
> https://lists.apple.com/**mailman/options/cocoa-dev/**
> griotspeak%40gmail.com
>
> This email sent to griotsp...@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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: makeObjectsPerformSelector on a sub class

2012-03-22 Thread T.J. Usiyan
Does it work if you use a for in loop?
TJ

On Wed, Mar 21, 2012 at 4:28 PM, Quincey Morris <
quinceymor...@rivergatesoftware.com> wrote:

> On Mar 21, 2012, at 13:23 , Quincey Morris wrote:
>
> > One thing to check: if your 'scrambleState' actually has a parameter:
> >
> >   - (void) scrambleState: …
> >
> > Then you need '@selector(scrambleState:)', not
> '@selector(scrambleState)'. It's an easy thing to overlook.
>
> Er, pretend you never saw that -- if there was a parameter you wouldn't be
> expecting to invoke 'performSelector…'. Listen to Jens instead.
>
>
> ___
>
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/griotspeak%40gmail.com
>
> This email sent to griotsp...@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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: makeObjectsPerformSelector on a sub class

2012-03-21 Thread Gregory Weston
Pascal Harris wrote:

> Now I want to scramble the state of each of the tiles.  In the game 
> controller, I'm using the following code:
> 
> [[self.view subviews] makeObjectsPerformSelector:@selector(scrambleState)];
> 
> I've put a breakpoint in scrambleState - and it never gets called. I'm 
> guessing that 'makeObjectsPerformSelector' fails to work because 
> scrambleState is not a method in UIView.

That's not how Objective-C works. You can send any message to any object. It 
may not respond well, but there's nothing filtering the send.

My money is on: self.view is nil at the time this code executes.



___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: makeObjectsPerformSelector on a sub class

2012-03-21 Thread James Bucanek
Pascal Harris  wrote 
(Wednesday, March 21, 2012 7:56 AM -):



Now I want to scramble the state of each of the tiles.  In the game
controller, I'm using the following code:

[[self.view subviews] makeObjectsPerformSelector:@selector(scrambleState)];

I've put a breakpoint in scrambleState - and it never gets called. I'm
guessing that 'makeObjectsPerformSelector' fails to work because scrambleState
is not a method in UIView. Question is, what do I need to do in order to
ensure that this code gets called?


Others have made a lot of valid suggestions and points, but if 
it wasn't mentioned I have another reason this would fail:


You must ensure that *all* subview of self.view implement 
-scrambleState. The first object in the collection that doesn't 
implement this method will throw an exception and the iteration 
will stop.


Safer, although longer, would be:

// (warning: typed in mail)
UIView* subview;
for ( subview in self.view.subviews )
if ([subview respondsToSelector:@selector(scrambleState)])
[subview scrambleState];
--
James Bucanek


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: makeObjectsPerformSelector on a sub class

2012-03-21 Thread Greg Parker
On Mar 21, 2012, at 1:23 PM, Quincey Morris 
 wrote:
> One thing to check: if your 'scrambleState' actually has a parameter:
> 
>   - (void) scrambleState: …
> 
> Then you need '@selector(scrambleState:)', not '@selector(scrambleState)'. 
> It's an easy thing to overlook.

Of course, if that were true then 
makeObjectsPerformSelector:@selector(scrambleState:) would do the wrong thing 
anyway, because -makeObjectsPerformSelector: would not pass any value for that 
parameter.


-- 
Greg Parker gpar...@apple.com Runtime Wrangler



___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: makeObjectsPerformSelector on a sub class

2012-03-21 Thread Quincey Morris
On Mar 21, 2012, at 13:23 , Quincey Morris wrote:

> One thing to check: if your 'scrambleState' actually has a parameter:
> 
>   - (void) scrambleState: …
> 
> Then you need '@selector(scrambleState:)', not '@selector(scrambleState)'. 
> It's an easy thing to overlook.

Er, pretend you never saw that -- if there was a parameter you wouldn't be 
expecting to invoke 'performSelector…'. Listen to Jens instead.


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: makeObjectsPerformSelector on a sub class

2012-03-21 Thread Quincey Morris
On Mar 21, 2012, at 07:56 , Pascal Harris wrote:

> @interface gameTile : UIView
> 
> And I've successfully drawn my tiles onto the iOS Simulator screen.
> 
> Now I want to scramble the state of each of the tiles.  In the game 
> controller, I'm using the following code:
> 
> [[self.view subviews] makeObjectsPerformSelector:@selector(scrambleState)];
> 
> I've put a breakpoint in scrambleState - and it never gets called. I'm 
> guessing that 'makeObjectsPerformSelector' fails to work because 
> scrambleState is not a method in UIView. Question is, what do I need to do in 
> order to ensure that this code gets called?

Assuming that 'scrambleState' is a method of the 'gameTile' class, then it 
doesn't matter that it's not a UIView method -- it only matters that it's a 
method of the objects you send the selector to, i.e. the subviews.

One thing to check: if your 'scrambleState' actually has a parameter:

- (void) scrambleState: …

Then you need '@selector(scrambleState:)', not '@selector(scrambleState)'. It's 
an easy thing to overlook.


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: makeObjectsPerformSelector on a sub class

2012-03-21 Thread Nick Zitzmann

On Mar 21, 2012, at 8:56 AM, Pascal Harris wrote:

> I've put a breakpoint in scrambleState - and it never gets called. I'm 
> guessing that 'makeObjectsPerformSelector' fails to work because 
> scrambleState is not a method in UIView. Question is, what do I need to do in 
> order to ensure that this code gets called?

It's not a method of UIView; it's a method of various collection objects. And 
to ensure that it's being called, you must break on the 
-makeObjectsPerformSelector: line and ensure that:

1. The code is actually reaching that line.
2. self.view is not nil.
3. self.view.subviews is not nil.
4. self.view.subviews actually has objects in it & is therefore not empty.
5. The line is not throwing an exception.

For 2, 3, and 4 above, you can use the debugger console and the "po" debugger 
command to evaluate the code. Note that you will have to use bracket notation 
instead of dot notation with the po command or it will think you're trying to 
print the object's internals rather than the result of sending a message to an 
accessor.

For 5, you should turn on breaking on ObjC exceptions in the debugger. You can 
do that by clicking on the + button in the breakpoints view in Xcode and then 
choosing to break on exceptions.

Nick Zitzmann



___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: makeObjectsPerformSelector on a sub class

2012-03-21 Thread Jens Alfke

On Mar 21, 2012, at 7:56 AM, Pascal Harris wrote:

> [[self.view subviews] makeObjectsPerformSelector:@selector(scrambleState)];
> 
> I've put a breakpoint in scrambleState - and it never gets called. I'm 
> guessing that 'makeObjectsPerformSelector' fails to work because 
> scrambleState is not a method in UIView.

No, that isn’t an issue. It will be called correctly regardless of where the 
method was introduced.

Are you sure that the array [self.view subviews] actually contains your views? 
If it’s empty, nothing will happen. If it contains any views that aren’t of 
your subclass, you’ll get an exception raised. Try setting a breakpoint at the 
line you’ve shown, and enter “po [[self view] subviews]”.

—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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: makeObjectsPerformSelector on a sub class

2012-03-21 Thread Seth Willits
On Mar 21, 2012, at 7:56 AM, Pascal Harris wrote:

> Now I want to scramble the state of each of the tiles.  In the game 
> controller, I'm using the following code:
> 
> [[self.view subviews] makeObjectsPerformSelector:@selector(scrambleState)];
> 
> I've put a breakpoint in scrambleState - and it never gets called. I'm 
> guessing that 'makeObjectsPerformSelector' fails to work because 
> scrambleState is not a method in UIView.

That's definitely not the reason. Making a method call in that way doesn't care 
what class in the hierarchy, or even what category on any of those classes the 
method is implemented at. The method will always be called even if the object 
*doesn't* implement it.

The only reasons it wouldn't be called are:

0) self is nil
1) self.view is nil
2) self.view has no subviews.


--
Seth Willits


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


makeObjectsPerformSelector on a sub class

2012-03-21 Thread Pascal Harris
I'm doing a little development on iOS (but hopefully this will apply equally to 
Mac OS X, so fingers crossed that someone will be able to help me out here), 
and I'm having a little bother with makeObjectsPerformSelector.

I've created a custom view (which will be a tile in my game) as follows:

@interface gameTile : UIView

And I've successfully drawn my tiles onto the iOS Simulator screen.

Now I want to scramble the state of each of the tiles.  In the game controller, 
I'm using the following code:

[[self.view subviews] makeObjectsPerformSelector:@selector(scrambleState)];

I've put a breakpoint in scrambleState - and it never gets called. I'm guessing 
that 'makeObjectsPerformSelector' fails to work because scrambleState is not a 
method in UIView. Question is, what do I need to do in order to ensure that 
this code gets called?

I'm hoping that you can help me out, and regards,

Pascal


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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