assert
- 특정 조건을 체크하고, 조건이 성립되지 않으면 메세지를 출력 하게 할 수 있는 함수
- assert 함수는 디버깅 모드에서만 동작하고 주로 디버깅 중 조건의 검증을 위하여 사용합니다.
var value = 0
assert(value == 0)
value = 2
assert(value == 0, "값이 0이 아닙니다")
gurad 문
- 뭔가 검사하여 그 다음에 오는 코드를 실행할지 말지 결정하는 것
- guard 문에 주어진 조건문이 거짓일 때 구문이 실행됨
/*
gurad 조건 else {
// 조건이 false 이면 else 구문이 실행되고
return or throw or break 를 통해 이 후 코드를 실행하지 않도록 한다.
}
*/
프로토콜
특정 역활을 하기 위한 메서드, 프로퍼티, 기타 요구사항 등의 청사진
protocol SomeProtocol {}
protocol SomeProtocol2 {}
struct SomeStructure: SomeProtocol {}
struct SomeStructure2: SomeProtocol, SomeProtocol2 {}
protocol FirstProtocol {
var name: Int { get set }
var age: Int { get }
}
protocol AnotherProtocol {
static var someTypeProperty: Int { get set }
}
protocol FullyNames {
var fullname: String { get set }
func printFullName()
}
struct Person: FullyNames {
var fullName: String
func printFullName() {
print(fullName)
}
}
protocol SomeProtocol3 {
func someTypeMethod()
}
protocol SomeProtocol {
init()
}
class SomeClass: SomeProtocol {
required init() {
}
// 상속받은 init이 final 이라면 required를 작성할 필요는 없다.
}