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

Swift 基本数据类型,常/变量声明(一)

发布时间:2020-12-14 07:10:02 所属栏目:百科 来源:网络整理
导读:https://github.com/Zhangjingwang1993/Swift.git /// 项目不太忙,撸撸Swift 变量 使用var声明 var str :String = "dd" str = "GG" print( str ) 常量 使用let声明 let count: Int = 16 print (count) 整型 Int ,Int8,Int16,Int32,Int64UInt,UInt8,UInt16,UI

https://github.com/Zhangjingwang1993/Swift.git
/// 项目不太忙,撸撸Swift

变量 使用var声明

var str:String = "dd"
str = "GG"
print(str)

常量 使用let声明

let count:Int = 16
print(count)

整型

Int,Int8,Int16,Int32,Int64
UInt,UInt8,UInt16,UInt32,UInt64

浮点型,布尔型

Float,Double,Bool

获取字符串的数量 // str = GG

print(str.characters.count) // 2

检查字符串是否有特定的前缀和后缀 pre/suf

let sttPre = "hello.com"
if sttPre.hasSuffix(".com33"){
   print("YES")
  }else{
   print("NO")
       }

还可以”()”

let name1 = "helloworld"
let msg = "Welcome to (name1)"
print(msg) // Welcome to helloworld

大小写转换

通过字符串的uppercaseString、lowercaseString、capitalizedString
属性来访问一个字符串的大写/小写/首字母大写

字符

var char:Character = "$"
print(char)

元组

let myCode = (one:"ZJwang",two:123)
print("(myCode.one)")

(编辑:李大同)

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

    推荐文章
      热点阅读