加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift教程之typealias取代OC的typedef

发布时间:2020-12-14 02:02:38 所属栏目:百科 来源:网络整理
导读://MARK:-------swift中的typedef--------------//使用 关键字定义类型别名,类似typedeftypealias NSInteger = Intvar value : NSInteger = 45value = 12print(value);//MARK:-------String--------------let label = "The width is "let width = 94var widt
//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."

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读