English 中文(简体)
将财产添加到国际不动产交易所及其所有子公司
原标题:Adding properties to UIViewController and all it s subclasses

如标题所示,Im 想增加每名国际电算师和每名分流(如可调的电算器)的定制特性。 我的第一项想法是建立一个类别,但我认识到,不能在其中增加一ars,因此我可以综合财产。 如果我简单地把《国际调查评论》调子了下来,并加进了脚, 它不会影响其他子类。

从根本上讲,我的目的是在我的“情报调查员”分级(第2号)上添加一个习惯工具路障,因为各种原因,我不得不使用这一缺陷。 如果主计长想要一个工具路障,它就需要向每个观察员提问,在这种情况下需要一系列工具路障。 就像UIToolbar公司如何运作我所相信的那样?

你们怎样做?

最佳回答

可通过目标C的相关物体A.A. 添加特性(>有:> > 背后储存)。 我甚至为此写了几篇大论。 但是,在宏观经济之前,这里要看“未开发”:

#import <objc/runtime.h>

@interface UIViewController (SOAdditions)
@property (atomic, readwrite, copy) NSString* myProperty;
@end

static void * const kMyPropertyAssociatedStorageKey = (void*)&kMyPropertyAssociatedStorageKey; 

@implementation UIViewController (SOAdditions)

- (void)setMyProperty:(NSString *)myProperty
{
    objc_setAssociatedObject(self, kMyPropertyAssociatedStorageKey, myProperty, OBJC_ASSOCIATION_COPY);
}

- (NSString*)myProperty
{
     return objc_getAssociatedObject(self, kMyPropertyAssociatedStorageKey);
}

@end

查阅有关储存的文件。 你们应当认识到,使用相关物体的表现(快速和记忆)受到处罚。 他们重新trick笑,但你可能想问,是否有更好的办法去做你重新尝试做的事情。 (如果你问我,那么trick中哪一部分是,根据你具体指明的政策,操作时间将处理-releases on -dealloc,供你使用;见关于更多信息的文件。)

现今是宏观的:

#ifndef ASSOCIATED_STORAGE_PROPERTY_IMP
#define THREE_WAY_PASTER_INNER(a, b, c) a ## b ## c
#define THREE_WAY_PASTER(x,y,z) THREE_WAY_PASTER_INNER(x,y,z)

#define ASSOCIATED_STORAGE_PROPERTY_IMP(type, setter, getter, policy) 
static void * const THREE_WAY_PASTER(__ASSOCIATED_STORAGE_KEY_, getter, __LINE__) = (void*)&THREE_WAY_PASTER(__ASSOCIATED_STORAGE_KEY_, getter,__LINE__); 

- (type)getter { return objc_getAssociatedObject(self, THREE_WAY_PASTER(__ASSOCIATED_STORAGE_KEY_, getter,__LINE__) ); } 

- (void)setter: (type)value { objc_setAssociatedObject(self, THREE_WAY_PASTER(__ASSOCIATED_STORAGE_KEY_, getter,__LINE__) , value, policy); } 

#endif

如果你在你的主人档案中pop,那么上述例子就可减少:

#import <objc/runtime.h>

@interface UIViewController (SOAdditions)

@property (atomic, readwrite, copy) NSString* myProperty;

@end

@implementation UIViewController (SOAdditions)

ASSOCIATED_STORAGE_PROPERTY_IMP(NSString*, setMyProperty, myProperty, OBJC_ASSOCIATION_COPY)

@end

不用说,你在“财产申报”中宣布的政策(即保留/范围/签字、原子/非住所)需要与你在使用宏观(和(或)要求基本文本时使用的政策相匹配,如果你不使用大型软件的话)否则,你就会停止泄露记忆(或坠毁)。

另外,我要再次就<>星号<>表示。 这种骗局是“免费的”,因此,请确保衡量业绩,并确保通过使用这种方式获得的任何好处都值得。

EDIT:我将在我关于相关物品储存的性能惩罚的令人振奋和可怕的警告上,重新跟踪一个轨道。 有一种惩罚,但快速调查告诉我,以这种方式实施的财产并非都比其“同化”和“ivar”支持等同物更糟。 试验是争议性的,但有10 000 000个物体,每个物体有5个附属存储器支持的单载体,发现约30%的性能放慢和获得。 这实际上不是所有这种可怕的,即IMHO。 我预计会更糟。 与既定业务有关的记忆管理(保存、复印件)所花时间正在从联系的眼光中敲响间接费用。

问题回答

暂无回答




相关问题
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 ...

热门标签