Replace class with fast

I am moving from objective-C to Swift.

Header file:

@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 Swift is my code:

class RegisterType {

    //var type: AnyClass
    var typeName: String = ""
    var namespace: String = ""
    var typeId: Int = 0

}

My main problem is that I want to replace the generic type โ€œclassโ€ that I used in objective-C. How to replace it in Swift? Do I need an init method?

+4
source share
1 answer

If I understood 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"
+2
source

Source: https://habr.com/ru/post/1584931/


All Articles