iphone - 对象界面布局?

标签 iphone objective-c cocoa-touch

以前我曾经这样编写对象接口(interface):

// VERSION 1.0
@interface Planet : NSObject {
    NSString *name;
    NSString *type;
    NSNumber *mass;
}
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSString *type;
@property(nonatomic, retain) NSNumber *mass;

-(NSString *)description;
@end

但是我最近发现我也可以这样写。我猜想删除 iVars 是最近添加到 Xcode 中的一项新功能。我是否正确地认为我应该寻求使用 VERSION 2.0(尽管我确实发现早期版本更具可读性,但代价是额外的打字)

// VERSION 2.0
@interface Planet : NSObject
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSString *type;
@property(nonatomic, retain) NSNumber *mass;

-(NSString *)description;
@end

加里。

最佳答案

使用新的 Xcode,编写 Objective-C 变得更容易、更短,但我相信它真正所做的只是在幕后添加 ivars 或综合属性。 (是的,在 xcode 4 中,属性默认是合成的) 真正的方法是1.0版本。 ,版本号二只是版本一的缩写,我不确定它是否可以在没有 Xcode 的情况下工作。 我相信 Xcode 已更改,但语言规范没有更改。 我希望这会有所帮助。

关于iphone - 对象界面布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3266325/

相关文章:

ios - 使用 iPhone 7 和 UIFeedbackGenerator,哪些系统操作执行哪种触觉反馈?

iphone - iOS:创建提示/帮助弹出窗口

ios - 在 iOS 8.1.1 中 typecast BOOL 总是返回 false

iphone - 保存UIBezierPaths

ios - Restkit:处理动态嵌套属性只返回一个对象

Iphone UI 案例研究 - 满意度远程

iphone - 如何在 tableView 单元格中圆化 ImageView 的角

iphone - UIButton 未在自定义 UITableViewCell 内获取触摸事件

iphone - SearchBar 在 iPhone 上挂起,但在模拟器上工作正常

iphone - 基于页面的应用加载 epub