以下是书中的Objective-C代码:
头文件:
#import <Foundation/Foundation.h>
@interface Person : NSObject {
NSString *personName;
float expectedRaise;
}
@property (readwrite, copy) NSString *personName;
@property (readwrite) float expectedRaise;
@end
这里是实现
#import "Person.h"
@implementation Person
@synthesize personName;
@synthesize expectedRaise;
- (id)init
{
self = [super init];
if (self) {
expectedRaise = 0.05;
personName = @"New Person";
}
return self;
}
@end
您需要前往Interface Builder,获取一个Array Controller,将其指定为Person类,并将personName和expectedRaise添加为其键。
我重写了Swift中的Person类,如下所示:
import Cocoa
class Person: NSObject {
var personName = String()
var expectedRaise = Float()
}
我已经按照要求翻译了内容:
并按照书中的指示将其连接到ArrayController。
Document文件中还有一些代码:
init() {
employees = NSMutableArray()
println("hi")
super.init()
// Add your subclass-specific initialization here.
var p = Person()
p.personName = "New Person"
p.expectedRaise = 0.05
}
这是界面的样子(SO不允许我直接发布)https://www.dropbox.com/s/e5busxes9ex3ejd/Screenshot%202014-06-13%2019.02.37.png。当我试图运行应用程序并单击“添加员工”按钮时,控制台会显示以下错误:“RaiseMan [9290:303]无法找到名称为Person的对象类”。那么,我的问题是:我做错了什么?