Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6224695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:42:57+00:00 2026-05-24T08:42:57+00:00

The NSProxy Class Reference says this: Typically, a message to a proxy is forwarded

  • 0

The NSProxy Class Reference says this:

Typically, a message to a proxy is forwarded to the real object or causes the proxy to load (or transform itself into) the real object.

How exactly would the “transform itself into the real object” work?

To make things a little more specific, suppose class Foo has a method newFooWithString: that takes a string and returns a new instance of Foo. Would it be possible to setup an NSProxy that sits around, and if a pleaseBecomeAFooUsingString: @"bar" message is received, transforms itself into [Foo newFooWithString: @"bar"], occupying the same memory, without messing with other references to itself that may exist?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:42:58+00:00Added an answer on May 24, 2026 at 8:42 am

    If you have a pointer to the same NSProxy instance all over the code and will “transform” it, it will change all over the code. There is no way to differentiate a caller of a method for an object, so you will not be able to alternate targets for forwarding of methods invocation in your code automatically. Common transformable proxy will looks in following way:

    MyTrickyProxy.h

    #import <Foundation/Foundation.h>
    
    @interface MyTrickyProxy : NSProxy {
        NSObject *object;
    }
    
    - (id)transformToObject:(NSObject *)anObject;
    
    @end
    

    MyTrickyProxy.m

    #import "MyTrickyProxy.h"
    
    @implementation MyTrickyProxy
    
    - (void)dealloc 
    {
        [object release];
        object = nil;
    
        [super dealloc];
    }
    
    - (NSString *)description 
    {
        return [object description];
    }
    
    //Stupid transform implementation just by assigning a passed in object as transformation target. You can write your factory here and use passed in object as id for object that need ot be created.
    - (id)transformToObject:(NSObject *)anObject 
    {
        if(object != anObject) {
            [object release];
        }
        object = [anObject retain];
    
        return object;
    }
    
    - (void)forwardInvocation:(NSInvocation *)invocation 
    {
        if (object != nil) {
            [invocation setTarget:object];    
            [invocation invoke];
        }
    }
    
    - (NSMethodSignature *)methodSignatureForSelector:(SEL)sel 
    {
        NSMethodSignature *result;
        if (object != nil) {
            result = [object methodSignatureForSelector:sel];
        } else {
            //Will throw an exception as default implementation
            result = [super methodSignatureForSelector:sel];
        }
    
        return result;
    }
    
    @end
    

    So what you requested is some sort of code-magic, but NSProxy is a simple forwarder of a messages, there is no any magic at all, so your goal is not achievable in a way as you described.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not clear with following code struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy); this can
I would like to code a proxy that forwards method invocations to another object
Does NSProxy really implement -autorelease and -release ? If not, do I need to
We know that in Objective-C there are two main root classes: NSObject and NSProxy
I'm writing a basic html-proxy in python (3), and up to now I'm not
I'm using OCMock to mock some Core Data objects. Previously, I had the properties
I'm using OCMock trying to test the behavior of NSURLConnection. Here's the incomplete test:
I use HessianKit to communicate with server. In the situation of network or server
I installed Fedora 16 last night and saw it had NoMachine's NX in the
I'm poking around a bit in some of the more suspicious objects apple APIs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.