English 中文(简体)
制作一个目标C物体,将另一个物体与相同的接口——KVC/KVO问题
原标题:Creating an Objective-C object that wraps another object with the same interface - KVC/KVO issues

我需要在一个等级中制造一个物体,从另一个等级中总结一个物体。 他们都有着非常相似的接口,我希望自动获得我对目标表示的精 wrap的信息,以代替执行自己的财产。 我这样做是为了利用这样的东西:

- (id)forwardingTargetForSelector:(SEL)sel 
{
    if ([self.wrappedObject respondsToSelector:sel])
        return self.wrappedObject;

    return self;
}

但是,这不利于关键价值编码的工作。 我怎么能以使用包装物体特性的方式执行关键价值编码?

最佳回答

页: 1 例如:

- (id)valueForKey:(NSString *)key {
  if (/* wrapped object has key */)
    return [self.wrappedObject valueForKey: key];
  else
    return [super valueForKey: key];
}

trick块将用来确定所包装物体确实执行的关键。 容易的做法是很难加以编码,但这并非太小。 如果你想要做到非常笼统,你会利用目标C的反转录器做一些事情。 这里有两个想法:

  • 你们的所有财产实际上是被宣布为财产。 您可以使用管理职能类别——植被,检查其存在,并选择性地获取额外信息。 然后,检查可以看上去:if (等值_getproperty([自负)类,[UTF8String])!= nil){

  • Your nature also have accessors only. 然后,你应当从钥匙中构筑挑选器,并使用<代码>。 反对与你以前一样回应:......]。 定居者的名称是主要加一殖民地。 然而,问题在于,财产名称不同。 第一种选择肯定是最好的。

问题回答

暂无回答




相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签