Swift教程之typealias取代OC的typedef

2015-07-09 14:44
//MARK:-------swift中的typedef--------------
//使用 关键字定义类型别名,类似typedef

typealias NSInteger = Int
var value : NSInteger = 45
value = 12
print(value);

//MARK:-------String--------------

let label = "The width is "
let width = 94
var widthLabel = label + String(width)  //Swift不支持隐式类型转换,需要显式类型转换
widthLabel += "!"
print(widthLabel)

//Swift使用\(item)的形式进行字符串格式化
let apples = 3
let oranges = 5
let appleSummary = "I have \(apples) apples."
let fruitSummary = "I have \(apples + oranges) pieces of fruit."

版权声明:本文为博主原创文章,未经博主允许不得转载。