Protocols
Protocol Basics
A protocol names behavior or data that conforming types must provide.
Conform to a shape
protocol_basics.swift
protocol Named {
var name: String { get }
}
struct Student: Named {
let name: String
}
let studentName =
let student = Student(name: studentName)
let label = "student=\(student.name)"
print(label)
protocol Named {
var name: String { get }
}
struct Student: Named {
let name: String
}
let studentName =
let student = Student(name: studentName)
let label = "student=\(student.name)"
print(label)
protocol Named {
var name: String { get }
}
struct Student: Named {
let name: String
}
let studentName =
let student = Student(name: studentName)
let label = "student=\(student.name)"
print(label)
protocol
A type conforms to a protocol by providing the required members.