English 中文(简体)
国家安全局如何“向另一个物体转变”?
原标题:How does NSProxy "transform itself into another object"?

rel=“nofollow noreferer”>NSProxy Level Reference:

典型的情况是,向代理人发送的电文被发送到真实物体,或导致代理人装载(或转化为)真实物体。

“向真正的目标转变”工作究竟如何?

使事情更加具体,代谢类别 Foo有一个方法new FooWithString:,该方法采用一个新实例:。 Foo。 如果收到<条码>条码<>条码<>条码>,则有可能形成<条码>。

最佳回答

如果你在守则上都有一个同一个国家程序小组的协调人,并且将“修改”守则,那么,它就会改变所有做法。 没有任何办法区别使用物体的方法,因此,你无法选择自动在你的法典中提出使用方法的目标。 共同可变的代理办法将采取以下方式:

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

因此,你要求的是某种规范,但国家安全局是传递信息的一个简单渠道,根本不存在任何魔鬼,因此,你的目标不能像你所描述的那样实现。

问题回答

您可以创立一个子级的国家安全局,这一变化反对它,将其方法推向根据你们想要的每一项标准。 因此,您的反对将永远指向国家食品安全局,但请BecomeAFooUsingString:将目标转变为“Foo”。





相关问题
How do you create UIBarButtonItems with a radio interface?

I have a UIToolbar that needs three buttons in a radio style, meaning that of the three, only one button can be pushed at a time. The documentation makes reference to the possibility of setting up ...

iPhone settings bundle

I want to allow the user to enter a valid date using the iPhone’s settings application. I have experimented with many of the PreferenceSpecifiers data node types including date. I have two issues: ...

Circular #import/@class problem in ObjectiveC

I m going to use an example to properly illustrate my confusion. I can t quite wrap my head around this. In Cocoa touch, we have UIViewController and its subclass, UINavigationController. Now, UIVC ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Cocoa-Touch: issue looping MPMoviePlayerController

I have an app which has to load some data at startup, so I want to display a splash-screen animation. I m using the MPMoviePlayerController to play a m4v file. The movie has it s background set to [...

Iphone sequential animation with setAnimationDelay

I m trying to chain animation events. The application I m coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "...

热门标签