gpt4 book ai didi

objective-c - 如何在 Objective C 中使用 DTO

转载 作者:行者123 更新时间:2023-12-04 05:39:29 24 4
gpt4 key购买 nike

我一直在 Java 中使用数据传输对象,比如

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com