Initialization - The Swift Programming Language (Swift 5.5)
<aside> ๐ก Assign default values to all properties.
</aside>
If all properties have default values, the compiler creates an initializer that takes no arguments. This initializer makes it easy to create a new instance by callingย
Data()
.
init์ ์ค์ ํ ๋, ์ด๊ธฐ๊ฐ์ ์ฃผ๋ฉด ๋งค๊ฐ๋ณ์ ์์ด ์ด๊ธฐํ ๊ฐ๋ฅ (ํ๋กํผํฐ๋ค์ ๋ํดํธ๊ฐ์ผ๋ก ์ค์ )
init(property: Int = 0)
...
init()
init.property = 0
๋ฌธ์ ๊ทธ๋๋ก ํธ๋ฆฌํ ์ด๊ธฐํ
๋ด๋ถ์ ์ ํ ์ด๊ธฐํ๋ฅผ ํตํด ์ ํํ ์ด๊ธฐํ๋ฅผ ๋ณด์ฅ
๋ํดํธ ๊ฐ์ ์ฌ์ฉํ๊ฑฐ๋ ๋งค๊ฐ๋ณ์ ๋ณ๊ฒฝ์ ํตํด ์ ๋ง๋๋ก ์ด๊ธฐํ๋ฅผ ์์ ๊ฐ๋ฅ
override init(frame: CGRect) {
super.init(frame: frame)
}
convenience init(in superview: UIView) {
self.init(frame: superview.frame)
...
}
(๋ฒ์ญ)https://icksw.tistory.com/49
https://www.hackingwithswift.com/example-code/language/what-are-convenience-initializers
https://stackoverflow.com/questions/40093484/what-is-the-difference-between-convenience-init-vs-init-in-swift-explicit-examp
http://xho95.github.io/xcode/swift/grammar/initialization/2016/01/23/Initialization.html