2969

[code]

    @interface AClass : NSObject
    + (instancetype)hoge;
    @end
    
    @interface BClass : AClass
    @end
    
    @implementation AClass
    + (instancetype)hoge {
        return [self new];
    }
    @end
    
    @implementation BClass
    @end
    
    
    id objA = [A hoge];    // AClass's instance
    id objB = [B hoge];    // BClass's instance
    
[/code]

このクラスをSwiftで書き換えることは出来ますか？


CC BY-SA 3.0
2015-01-03T07:03:17.803
2962
2015-01-03T07:58:41.927
2741
question
objective-c swift
サブクラスを想定に入れたinstancetypeを返すクラスメソッドをSwiftで書き換える方法は？

[code]

    class AClass : NSObject {
        required override init() {}
    
        class func hoge() -> Self {
            return self()
        }
    }
    
    class BClass : AClass {
    }
    
    var objA = AClass.hoge();
    var objB = BClass.hoge();
    
[/code]


CC BY-SA 3.0
2015-01-03T07:58:41.927
2969
2015-01-03T07:58:41.927
5984
2962
answer