English 中文(简体)
@property
原标题:@property question

在我的执行中,我已经找到了像以下这样的人和制定者。 我想利用财产并综合地处理器和装置,但有几个问题。

- (NSString *)title {
return title;
}

- (void)setTitle:(NSString *)value {
if(title != value) {
    [title release];
    title = [value retain];
}
}

如果我把这变为财产,我会使用什么属性? 我思考的权利:

  • readwrite so both getters and setters are present
  • retain so that it increase the retain value of the value string so the object don t lose it.

我享有上述权利吗?

最后一件事。 我的方法如下:

- (void)setReleaseDate:(NSString *)value {
// YYYY-MM-DD HH:MM:SS +HHMM
if([releaseDate description] != value) {
    [releaseDate release];
    releaseDate = [[NSDate alloc] initWithString:value];
}
}

我认为我仍然必须包括这一方法,因为它含有综合采集器不会包括的编码?

感谢。

最佳回答

1. 贵阶层财产:

@property (nonatomic, retain) NSString* title;

这与以下内容相同:

@property (readwrite, nonatomic) NSString* title;

<>strong>readwrite是一个违约情况。 你们的大部分时间是想为你们的财产打造,因此,在你不使用“无过失”的时代,你只想用“<>><>>>号”来具体规定这一点。

<>>无活体>部分基本是指电离器将更快,通常使用。 你们可以在此获得更多信息:。 什么财产“没有住所”意味着什么?

关于你的第二个问题,如果你愿意,你可以执行你们自己的接触者。 如果你这样做的话,那么这种方式就压倒了目标C产生的接触者。 因此,在你的例子中,“租赁:”你定义的方法将用于“租赁”财产的固定方法——这完全正确! 不过,你的问题是,你重新通过《国家财产统计》** 确定日期,这意味着这一方法胜过如果你综合财产将使用的缺省套。 你必须把你重新定位为单一论点的同类价值,这样,你就不得不通过*NSDate**。

你们还必须确保,如果你主动提供一名出访者的话,他们会做在接口中宣布的内容。 兹宣布保留以下财产:

问题回答

页: 1 以及<代码>retain <>/code>是正确的,因为它将产生与你所张贴内容相符合的属地法。

释放后的财产集束器可加以综合,因为您将NSString改为NSDate,以储存该编号,这也避免了与NSString有关的共同问题,为此,您可更好地利用copy,以避免与NSMutableString出现问题。

除此以外,你的代码是罚款,但为了进行细微比较,你可能希望取代简单明细表核对表! 。 可可园。

通常使用<代码>copy semantics for NSString nature,以避免出现NSMutableString的物体在背后发生变化。

否则,你似乎远远落在后面。





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

热门标签