반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 데이터저장
- Python
- 어플만들기
- 자바
- 데이터모델링
- 노코드
- Ai
- 앱시트
- 앱만들기
- 데이터시각화
- lookML
- 휴가관리
- app
- 데이터분석
- 구글스프레드시트
- Java
- appsheet
- openAI
- 엑셀
- 파이썬
- 인공지능
- 샤딩
- data
- 데이터
- 노코드앱
- 자동화
- Looker
- nocode
- 어플
Archives
- Today
- Total
공부한 것 꼭꼭 씹어먹기
protocol 본문
반응형
프로토콜 : 특정 역할을 하기 위한 메서드, 프로퍼티, 기타 요구사항 등의 청사진을 정의하고 자신을 채택한 구조체, 클래스, 열거형에게 정의된 요구사항을 준수하라고 요청함 (🐣 프로토콜은 자바의 interface같은 것인가??)
protocol SomeProtocol {
}
protocol SomeProtocol2 {
}
// SomeStructure 구조체는 someProtocol, someProtocol2를 채택함
struct SomeStructure: SomeProtocol, SomeProtocol2 {
}
// 클래스는 상속받는 부모클래스가 있을 경우 가장 앞에 써줘야 함
class SomeClass: SomeSuperClass, SomeProtocol, SomeProtocol2 {}
protocol FirstProtocol {
var name: Int { get set }
var age: Int { get } // read only
}
protocol FullyNames {
var fullName: String { get set }
func printFullName() // 프로토콜에 함수를 정의할때 매개변수에 default를 설정할 수 없음
}
struct Person: FullyNames {
var fullName: String // FullyNames에서 정의한 프로토콜을 준수해야한다
func printFullName() {
print(fullName)
}
}
// 생성자 요구사항 준수하기
protocol SomeProtocol5 {
init()
}
class SomeClass: SomeProtocol5 {
// class에서 생성자를 준수할때는 required를 써야한다(struct에서는 안써도 됨)
// SomeClass가 상속받을수 없는 final class일때도 required를 안써도 된다
required init() { }
}
반응형
Comments