IOS开发-Swift新语言初见
2014-06-03 15:57
405 查看
Safe
Swift pairs increased type safety with type inference, restricts direct access to pointers, and automatically manages memory—making it easy to create secure, stable software.func configureLabels(labels: UILabel[]) {
let labelTextColor = UIColor.greenColor()
for label in labels {
// label inferred to be UILabel
label.textColor = labelTextColor
}
}
Modern
Swift includes optionals, generics, tuples, and other modern language features. Inspired by and improving upon Objective-C, Swift code feels natural to read and write.let cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"]
let sortedCities = sort(cities) { $0 < $1 }
if let indexOfLondon = find(sortedCities, "London") {
println("London is city number \(indexOfLondon + 1) in the list")
}
Powerful
Take advantage of powerful pattern matching in Swift to write simple, expressive code. Format strings naturally with string interpolation. Use frameworks like Foundation and UIKit directly from Swift.let size = (20, 40)
switch size {
case let (width, height) where width == height:
println("square with sides \(width)")
case (1..10, 1..10):
println("small rectangle")
case let (width, height):
println("rectangle with width \(width) and height \(height)")
}
Interactive
Use playgrounds to experiment with new technologies, analyze problems, and prototype user interfaces.
Fast
The Swift compiler applies advanced code analysis to tune your code for performance, letting you focus on writing great apps instead of on implementing complex optimizations.
相关文章推荐
- IOS开发-Swift新语言初见
- IOS开发语言Swift入门连载---初见
- IOS开发语言Swift入门连载---可选链
- 北京iOS培训开发Swift语言首发
- IOS开发语言Swift入门连载---类型转换
- IOS开发语言Swift入门连载---控制流
- IOS开发语言Swift入门连载---类和结构体
- IOS开发语言Swift入门连载---基础部分
- ios新开发语言swift 入门教程
- IOS开发语言Swift入门连载---继承
- IOS开发语言Swift入门连载---字符串和字符
- IOS开发语言Swift入门连载---方法
- 【iOS开发】如何用 Swift 语言进行LBS应用的开发?
- IOS开发语言Swift入门连载---扩展
- IOS开发:swift 语言基本语法1
- IOS开发语言Swift入门连载---自动引用计数
- IOS开发语言Swift入门连载---闭包
- IOS开发语言Swift入门连载---基本运算符
- IOS开发语言Swift入门连载---枚举
- IOS开发语言Swift入门连载---协议