swift创建函数
来源:互联网 发布:电脑操作手机屏幕软件 编辑:程序博客网 时间:2024/05/14 12:33
/*
定义函数
*/
//sayHello的函数主体首先定义了一个新的名为greeting的String常量
//并将其设置加上personName组成一句简单的问候消息
//(persnalName:String)函数的传参
//String: 函数的返回值类型,返回箭头( - >)
func sayHello(persnalName:String)->String
{
let greeting = "Hello" + persnalName + "!"
return greeting;
}
//无返回值的函数
func sayGoodBye(personNanem:String)
{
println("Goodbye,\(personNanem)!")
}
//第一个函数printAndCount,打印了一个字符串,然后并以Int类型返回它的字符数
func printAndCount(stringToPoint:String)->Int
{
println(stringToPoint)
return count(stringToPoint)
}
//第二个函数printWithoutCounting,调用的第一个函数,但忽略它的返回值
//函数的调用
//当第二函数被调用时,消息由第一函数打印了回来,但没有使用其返回值
func printWithoutCounting(stringToPonit:String)
{
printAndCount(stringToPonit)
}
func firstSwift(sender:UIButton)
{
println("第一个button的点击事件")
self.label1.text = "button点击了"
}
/*
调用函数
*/
println(sayHello("第一个函数"))
sayGoodBye("first company")
printAndCount("Hello world !")
printWithoutCounting("hello world !")
- swift创建函数
- swift 函数创建
- swift 创建类方法(扩展)和便利构造函数
- Swift函数
- Swift函数
- swift 函数
- swift,函数
- [Swift]函数
- Swift 函数
- Swift函数
- swift函数
- Swift-函数
- Swift - 函数
- swift --函数
- swift函数
- Swift函数
- Swift函数
- Swift函数
- mybatis调用mysql存储过程返回结果集
- 波
- 线程 NSThread 多线程 简单翻译
- Homebrew--Mac OS X 的包管理器
- easyui 给文本框 checkbox赋值问题
- swift创建函数
- 常说的七侠五义到底是什么?
- Unsupervised Feature Learning and Deep Learning(UFLDL) Exercise 总结
- java-String中的 intern()
- 几种字符串的转变
- 二分图的最大匹配、完美匹配和匈牙利算法
- 最小的k个数
- Swift语法之 ---- ?和!区别
- Android Lrucache类注意事项