在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Swift是什么?Swift是苹果于WWDC 2014发布的编程语言,这里引用The Swift Programming Language的原话:
简单的说:
Swift语言概览// Playground - noun: a place where people can play import Cocoa var str = "Hello, playground" var str1 = "Hello Wrold!!!" var str2 = "O(∩_∩)O哈哈~" // Hello, world println("Hello, world") // 变量与常量 // Swift 使用 var 声明 变量 , let 声明常量 var myVariable = 42 myVariable = 50 let myConstant = 42 // 类型推导 let explicitDouble : Double = 70 // Swift 不支持隐式 类型转换 (所以需要显式类型转换) let label = "The width is" let width = 94 let width1 = label + String(width) // 使用 \(item) 的形式进行 字符串格式化 let apples = 3 let orages = 5 let sum = "I have \(apples) apples." let sum1 = "I have \(apples + orages) pieces of fruit." // 数组和字典 // Swift 使用[] 操作符声明 数组(array)和字典 (dictionary) var listArr = ["fish","water","apple","rice"] listArr[1] = "bottle of water" var dict = [ "name": "melody", "age" : "26", ] dict["sex"] = "female" // 一般使用初始化器(initializer)语法创建空数组和空字典 let emptyArray = String[]() let emptyDict = Dictionary<String, Float>() Xcode贴图
|
请发表评论