본문 바로가기

iOS Solution

UIView 상속시 필요한 초기화 구문

두가지 형태로 구현할 수 있다.

 

1. 초기화 함수를 재정의 하는 방법

override init(frame: CGRect)
{
    super.init(frame: frame)
    // 초기화 작업
}    

required init?(coder aDecoder: NSCoder)
{
    super.init(coder: aDecoder)
    fatalError("This class does not support NSCoding")
}

 

2. 초기화 함수 사용자화(커스터마이즈) 하기

init(parameter: Any)
{
    super.init(frame:frame)
    // 초기화 작업
}

required init?(coder aDecoder: NSCoder)
{
    super.init(coder: aDecoder)
    fatalError("This class does not support NSCoding")
}