swift:基本数据类型

//: Playground - noun: a place where people can play

import UIKit
// 整数类型
let int_a = 10
let int_b : Int
let int_c : Int = 10
// 注意不能 let int_c ( 即是在定义常量或者变量时,在隐示声明的时候必须初始化 )
//
字符串
let string_a = "i like eat"
let string_b: String
let string_c: String = "i like eat"
// 类型强制转换
let apple = "the number of apple is "
let number = 10
let number_apple= apple + String ( number )
print ( "the number is \ ( number )" )
// 浮点数
let float_a = 1.0
let float_b: Float
let float_c: Float = 1.0
let double_a = 1.99
let double_b: Double
let double_c: Double = 1.99
// 布尔类型
let bool_a= true
let bool_b= false
let bool_c: Bool
let bool_d: Bool = true
// 数组与字典
let emptyArray = [ String ]()
var array1 = [ "aa" , "bb" , 12 ]
let emptyDictionary = Dictionary < String , Float >()
var dictionary1 = [ "xiaoming" : 10 , "xiaohong" : 12 ]
dictionary1 [ "xiaofei" ] = 12 // 添加元素
print( dictionary1)

//枚举

enum Person{

    case 小明

    case 小红

    case 小花

}

let person1:Person = .小明

let person2:Person = .小红

let person3:Person = .小花

let person:Person = person2

switch person{

    case .小明:

        print("是小明")

    case .小红:

        print("是小红")

    case .小花:

        print("是小花")

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值