struct
struct Game{
let title: String
let version: Double
init(title theTitle: String, version theVersion: Double ) {
self.title = theTitle
self.version = theVersion
}
func play(){
print(self.title + " is playing.....")
}
}
let MyGame = Game(title: "MyFirstGame", version: 0.1)
MyGame.play() // MyFirstGame is playing.....
Supports interfaces in Java
protocol Updatable{
func update(_ version: Double)
}
struct Game: Updatable{
~~~Abbreviation~~~
func update(_ version: Double) {
print("updated")
}
}
Structure name: Protocol name
SwiftUI Based on this, quoted from ContentView.swift
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
}
}
In other words, the ContentView structure is defined using the View protocol. The View protocol needs to implement the body property, so that's right. The some type is an arbitrary type that conforms to the View protocol, so it does not necessarily have to be a View.
Recommended Posts