我一直在 Jave 中使用数据传输对象,例如
public class AccountDEM
{
private String userName;
private String userAuthToken;
private int user_Id;
public void setuserName(String _userName)
{
this.userName=_userName;
}
public string getuserName()
{
return userName;
}
...
}
我如何在 Objective C 中使用相同的内容。可能“Objective C 的属性”将达到我认为的目的。但有人可以详细解释一下,如何利用 Objective C 的特性来编写 DTO 并有效地使用它们并保持内存安全(避免内存泄漏)。
如果可能的话,请尝试将上面的代码转换为Obj C。
最佳答案
@interface AccountDEM
@property (nonatomic,retain) NSString* userName;
@property (nonatomic,retain) NSString* userAuthToken;
@property (nonatomic) int user_Id;
@end
@implementaion
@synthesize userName;
@synthesize userAuthToken;
@synthesize user_Id;
@end
对于属性,您可以阅读 http://objective-c-properties.blogspot.in/
关于objective-c - 如何在 Objective C 中使用 DTO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11448267/