스위프트의 character는 하나 이상의 Unicode scaler로 이루어져있다. 즉 가변적인 길이이기 때문에 subscript로 접근할 수 없고 String.Index로 접근해야한다.
상속이 가능한 메소드이기 때문이다. class에서는 static과 class 메소드가 같다.
static 메소드를 override가 가능하게 만든 것
UserDefault
class MyObjectToObserve: NSObject {
@objc dynamic var myDate = NSDate(timeIntervalSince1970: 0) // 1970
func updateDate() {
myDate = myDate.addingTimeInterval(Double(2 << 30)) // Adds about 68 years.
}
}
class MyObserver: NSObject {
@objc var objectToObserve: MyObjectToObserve
var observation: NSKeyValueObservation?
init(object: MyObjectToObserve) {
objectToObserve = object
super.init()
observation = observe(
\.objectToObserve.myDate,
options: [.old, .new]
) { object, change in
print("myDate changed from: \(change.oldValue!), updated to: \(change.newValue!)")
}
}
}
키 값으로 Notification이나 userInfo의 값을 가져오기 때문
참고자료
- https://github.com/iOS-SOPT-iNNovation/iOS_Traning/issues/24
- https://velog.io/@hayeon/Subscripts에-대해서-설명하시오
- https://velog.io/@hansangjin96/Swift-String은-왜-subscriptInt로-접근이-안될까
- https://velog.io/@hayeon/instance-메서드와-class-메서드의-차이점을-설명하시오
- https://prod.velog.io/@hayeon/Delegate-패턴을-활용하는-경우를-예를-들어-설명하시오
- https://velog.io/write?id=1025fd8d-8963-43d1-9f00-0d7d5b433442
- https://github.com/ios-study-boost/iOSInterviewquestions/issues/7
- https://velog.io/@hayeon/KVO-동작-방식에-대해-설명하시오
- https://velog.io/@hayeon/Delegates와-Notification-방식의-차이점에-대해-설명하시오
- https://www.notion.so/286e419e66484f92ad188649b788a7fd