前端之家收集整理的这篇文章主要介绍了
swift基础知识<一>,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/*
print("Hello,World!")
let let_1 = 80
var var_1 = 100
var_1 = 1234
print(var_1)
var var_2 = "hello"
print(var_2);
var var_int1 = 100
var var_int2 = 200
var res = var_int1 + var_int2
print(res)
var var_string1 = "fuck"
var var_string2 = " off"
var res_str = var_string1 + var_string2
print(res_str)
var var_int_1: Int = 10
var var_float_1:Float = 1.0
var var_double_1: Double = 1.23
var var_char_1: Character = "a"
var var_BOOL_1: Bool = true
var string_1 :String = "u r my sunshine"
*/
/*
var david = ("David",18,188,"未知","男")
let name = david.0
let age = david.1
let height = david.2
let long = david.3
let gender = david.4
print("姓名:\(name) 年龄:\(age) 身高:\(height) 长度:\(long)mm 性别:\(gender) ")
var carl = (name:"Carl",age:25,height:185.5,性别:"男")
let name_1 = carl.name;
let age_1 = carl.age;
let height_1 = carl.height
let gender_1 = carl.性别
print("姓名:\(name_1) 年龄:\(age_1) 身高:\(height_1) 性别:\(gender_1)")
var jack:(name:String,age:Int,height:Double,gender:String) = ("Jack",23,175,"男")
let name_2 = jack.name
let age_2 = jack.age
let height_2 = jack.height
let gender_2 = jack.gender
print(name_2,age_2,height_2,gender)
let array_1 = ["ni","hao","ma"]
let temp_arr_1 = array_1[0]
*/
var array_2 = ["长江","黄河","大海"]
array_2.append("湖泊")
array_2.insert("小溪",atIndex: 4)
print(array_2)
array_2[2] = "池塘"
print(array_2)
print(array_2)
for value in array_2
{
print(value)
}
for value in array_2[0..<3]
{
print(value)
}
for(index,value) in array_2.enumerate()
{
print(index,value)
}
var dict_1 = ["key1":"a","key2":"b","key3":"c"]
dict_1.updateValue("d",forKey: "key4")
dict_1["key5"] = "e"
dict_1.removeValueForKey("key3")
print(dict_1["key2"]!)
dict_1["key1"] = "cool"
for key in dict_1.keys
{
print(key)
}
for value in dict_1.values
{
print(value)
}
for ( key,value) in dict_1
{
print(dict_1)
}
print(dict_1)
var var_int_a = Int?()
var var_int_b:Int?
var_int_b = 100
if var_int_b == nil{
print("不能拆包")
}else{
print("可以拆包")
let opt_a:Int = var_int_b!
print(opt_a)
}
原文链接:https://www.f2er.com/swift/325698.html