Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-25-2009, 11:14 AM   #1 (permalink)
Registered Member
 
codeflakes's Avatar
 
Join Date: Jul 2009
Location: Paris
Posts: 84
codeflakes is on a distinguished road
Default Equivalent of Ruby's "method_missing" in objectice C ?

In Ruby when a class receives a message that it does not implement, the method_missing method is called so you can react to this.
Is there a way to do the same in objective C ?
__________________
CodeFlakes iPhones apps on: www.code-flakes.com
codeflakes is offline   Reply With Quote
Old 09-25-2009, 11:26 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by codeflakes View Post
In Ruby when a class receives a message that it does not implement, the method_missing method is called so you can react to this.
Is there a way to do the same in objective C ?
You can set a forwarding target for all unrecognized messages:
Code:
- (id)forwardingTargetForSelector:(SEL)aSelector
Or you can check unrecognized messages and repsond to them by defining
Code:
- (void)forwardInvocation:(NSInvocation *)anInvocation
There's a little example here
Mac Dev Center: NSObject Class Reference
__________________

Free Games!
smasher is offline   Reply With Quote
Old 09-25-2009, 11:28 AM   #3 (permalink)
Registered Member
 
codeflakes's Avatar
 
Join Date: Jul 2009
Location: Paris
Posts: 84
codeflakes is on a distinguished road
Default

Cool. Thanks a lot!
__________________
CodeFlakes iPhones apps on: www.code-flakes.com
codeflakes is offline   Reply With Quote
Old 09-25-2009, 12:59 PM   #4 (permalink)
Registered Member
 
codeflakes's Avatar
 
Join Date: Jul 2009
Location: Paris
Posts: 84
codeflakes is on a distinguished road
Default

Any idea how to suppress warning when calling a non existent message ?
If I call [Object method] and which to catch the unknow "method" I got a warning at compilation but in my case this is exactly what I want to do.
But the compile does not take into account my forwardingTargetForSelector implementation
__________________
CodeFlakes iPhones apps on: www.code-flakes.com
codeflakes is offline   Reply With Quote
Old 09-26-2009, 05:19 AM   #5 (permalink)
Registered Member
 
codeflakes's Avatar
 
Join Date: Jul 2009
Location: Paris
Posts: 84
codeflakes is on a distinguished road
Default

Quote:
Originally Posted by codeflakes View Post
Any idea how to suppress warning when calling a non existent message ?
If I call [Object method] and which to catch the unknow "method" I got a warning at compilation but in my case this is exactly what I want to do.
But the compile does not take into account my forwardingTargetForSelector implementation
Answer to myself
Explicitly call the unknown message from a selector

[object performSelector:@selector(method)]
__________________
CodeFlakes iPhones apps on: www.code-flakes.com
codeflakes is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 458
13 members and 445 guests
Domele, Duncan C, Feldspar, MacBook MH, Objective Zero, patapple, peterwilli, pipposanta, PixelInteractive, Punkjumper, SLIC, taylor202, Today's Posts
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,694
Threads: 94,137
Posts: 402,950
Top Poster: BrianSlick (7,990)
Welcome to our newest member, peterwilli
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0