Reputation: 6758
I am moving from objective-C to Swift.
The header file was:
@interface RegisterType : NSObject
{
Class type;
NSString *typeName;
NSString *namespace;
int typeId;
}
@property (nonatomic,retain) Class type;
@property (nonatomic,retain) NSString *typeName;
@property (nonatomic,retain) NSString *namespace;
@property (nonatomic) int typeId;
@end
and the implementation was:
@implementation RegisterType
@synthesize type;
@synthesize typeName;
@synthesize namespace;
@synthesize typeId;
Now is Swift my code is:
class RegisterType {
//var type: AnyClass
var typeName: String = ""
var namespace: String = ""
var typeId: Int = 0
}
My main is problem is that I want to replace the generic type 'Class' that I used in objective-C. How do I replace it in Swift? Do I need an init method?
Upvotes: 4
Views: 381
Reputation: 70098
If I understand your question correctly, I would do something like this:
class RegisterType: NSObject {
override init() {
super.init()
self.type = self.classForCoder
}
var type: AnyClass?
var typeName: String = ""
var namespace: String = ""
var typeId: Int = 0
}
let xx = RegisterType()
println(xx.type) // prints "RegisterType"
Upvotes: 2