2017-12-17 21 views
0

나는 초기화 방법을 가지고있다. & & 또는 ||를 사용하는 경우 모든 멤버가 초기화되기 전에 클로저로 '자체'를 캡처하는 이유는 무엇입니까? 피연산자.&&, ||를 사용하여 클로저 오류로 '자체'를 캡처했습니다. operator

var type:Type? = .non 

init(dictionary:[String:AnyObject]){ 

    if let type = dictionary["type"] as? Int { 
     self.type = Type.init(rawValue: type)! 
    } 


    //'self' captured by a closure before all members were initialized 

    if self.type == .picture || self.type == .textWithPicture { 
    //........ 
    }  
} 
+0

전체 클래스 선언을 제공 할 수 있습니까? 그냥 메서드를 생략하십시오. – mownier

+0

if 문을 전달할 수 없기 때문에 – CZ54

답변

3

NSObject에서 클래스를 상속하고 있습니까? 그렇다면이 클래스의 속성을 사용하기 전에 super의 init 메소드를 호출해야합니다.

+0

예, 알겠습니다. 나는 그것을 몰랐다. 고맙다! https://stackoverflow.com/questions/25630031/calling-super-init-in-initializer-of-nsobject-subclass-in-swift –