【ios】swift教程

学习swift地址
https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
和其他语言比起来,语法层次确实有些不一样的地方。

在wwdc2019上看到了苹果公司关于swiftui的介绍,感觉这就是未来。
Parentheses()
brackets[]
braces{}

Swift编程语言简介
Swift命令行操作

Swift defines away large classes of common programming errors by adopting modern programming patterns:

Variables are always initialized before use.
Array indices are checked for out-of-bounds errors.
Integers are checked for overflow.
Optionals ensure that nil values are handled explicitly.
Memory is managed automatically.
Error handling allows controlled recovery from unexpected failures.

A swift tour

下面的内容如果你有不理解的请不要太过于悲观,我们将会在以后继续学习

Simple Values

let 定义常量
var 定义变量

Control Flow

Use if and switch to make conditionals, and use for-in, while, and repeat-while to make loops. Parentheses around the condition or loop variable are optional. Braces around the body are required.

if true {
print("this is true")
} else{
print("this is not true")
}
var tmp = ""
switch tmp{
case "1":
	print("1")
	case "2":
	print("2")
	default:
	print("default")
}

for i in [1, 3, 5,7,9]{
		print(i)
}
for i in 1..<5{
print(i)
}
for i in 1...5{
print(i)
}
while condition {
	   print("do something")
}
repeat {
    print("至少执行一次")
}while 2 < 1

函数和闭包

By default, functions use their parameter names as labels for their arguments. Write a custom argument label before the parameter name, or write _ to use no argument label.

func greet(person: String, day: String) -> String {
    return "Hello \(person), today is \(day)."
}
greet(person: "Bob", day: "Tuesday")

对象和类


实例话一个类

Enumerations and Structures

Protocols and Extensions

Error Handling

异常捕获

你可能感兴趣的:(ios)