Swift knowledge point
The following describes what to use to write Swift code. First, Swift does not have a header file and A. H file.
Variable Declaration
Swift variable Declaration has two keywords: var and let. var is similar to Javascript. You can declare any type of object and specify the type through var mystring: string.
var myVariable = 42myVariable = 50let myConstant = 42
Function
Swift function expression, which is the same as the Javascript keyword, is func, followed by the function name. Note that the parameters in brackets are respectively the name, type string, and name day, type string, where-> string is the type of the function return parameter.
func greet(name: String, day: String) -> String { return "Hello \(name), today is \(day)."}greet("Bob", "Tuesday")
Class and Object
Class Declaration, in which the class method is defined in the braces of the class.
class Shape { var numberOfSides: Int = 0 func description() -> String { return "A shape with \(numberOfSides) sides." }}
Protocol
protocol ExampleProtocol { var simpleDescription: String { get } mutating func adjust()}