• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Swift代码着色测试

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Swift代码:

// this is a single line comment using two slashes.
 
/* this is also a comment,
   but written over multiple lines */
 
/* multiline comments
   /* can be nested! */
   Therefore you can block out code containing multiline
   comments
*/
 
// Swift variables are declared with "var"
// this is followed by a name, a type, and a value
var explicitDouble: Double = 70
 
// If the type is omitted, Swift will infer it from
// the variable\'s initial value
var implicitInteger = 70
var implicitDouble = 70.0
var 國 = "美國"
 
// Swift constants are declared with "let"
// followed by a name, a type, and a value
let numberOfBananas: Int = 10
 
// Like variables, if the type of a constant is omitted,
// Swift will infer it from the constant\'s value
let numberOfApples = 3
let numberOfOranges = 5
 
// Values of variables and constants can both be
// interpolated in strings as follows
let appleSummary = "I have \(numberOfApples) apples."
let fruitSummary = "I have \(numberOfApples + numberOfOranges) pieces of fruit."
 
// In "playgrounds", code can be placed in the global scope
println("Hello, world")
 
// This is an array variable
var fruits = ["mango", "kiwi", "avocado"]
 
// Example of an if statement; .isEmpty, .count
if fruits.isEmpty {
    println("No fruits in my array.")
} else {
    println("There are \(fruits.count) items in my array")
}
 
// Define a dictionary with four items:
// Each item has a person\'s name and age
let people = ["Anna": 67, "Beto": 8, "Jack": 33, "Sam": 25]
 
// Now we use Swift\'s flexible enumerator system
// to extract both values in a single loop
for (name, age) in people {
    println("\(name) is \(age) years old.")
}
 
// Functions and methods are both declared with the
// "func" syntax, and the return type is specified with ->
func sayHello(personName: String) -> String {
    let greeting = "Hello, " + personName + "!"
    return greeting
}
 
// prints "Hello, Dilan!"
print(sayHello("Dilan"))
 
// Parameter names can be made external and required
// for calling.
// The external name can be the same as the parameter
// name by prefixing with an octothorpe (#)
// - or it can be defined separately.
 
func sayAge(#personName: String, personAge Age: Int) -> String {
    let result = "\(personName) is \(Age) years old."
    return result
}
 
// We can also specify the name of the parameter
 
print(sayAge(personName: "Dilan", personAge: 42))

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[Swift A] - Welcome to Swift发布时间:2022-07-13
下一篇:
swift.org - About Swift 官网关于notes发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap