swfit各种Function表现形式
//: Playground - noun: a place where people can play
import UIKit
//多返回值函数
func countss(string:
String) -> (vowels:
Int,consonants:
Int,others: Int) {
var vowels =
0, consonants = 0, others =
0
for character
in string {
switch
String(character).lowercaseString {
case
"a", "e", "i",
"o", "u":
++vowels
case
"b", "c",
"d", "f", "g",
"h", "j",
"k", "l", "m",
"n", "p",
"q", "r", "s",
"t", "v",
"w", "x", "y",
"z":
++consonants
default:
++others
}
}
return (vowels, consonants, others)
}
let countsss =
countss("qwertyuiopasdfghj!234")
countsss.consonants
countsss.others
//外部參数名
func join(s1:
String, s2:
String, joiner:
String) -> String {
return s1 + joiner + s2
}
//当你调用这个函数,你传递给函数的三个字符串的目的就不是非常清楚了:
join("hello",
"world", ",")
//为了使这些字符串值的目的更为清晰,为每一个 join
函数參数定义外部參数名称:
func joiners(string s1:
String, toString s2:
String, withJoiner joiner:
String) ->
String {
return s1 + joiner + s2
}
joiners(string:
"hello", toString:
"world", withJoiner: ":")
//外部參数名称速记
func containsCharacter(#string:
String, characterToFind:
Character) ->
Bool {
for character
in string {
if character == characterToFind {
return
true
}
}
return
false
}
containsCharacter(string: "aaabbccc",
"f")
//參数的默认值
func joinerss(string s1:
String, toString s2:
String, withJoiner joiner:
String =
" ") -> String {
return s1 + joiner + s2
}
joinerss(string:
"hello", toString:
"world")
joinerss(string:
"hello", toString:
"world", withJoiner: "-")
//有默认值的外部名称參数
func joinersss(s1:
String, s2:
String, joiner:
String = " ") ->
String {
return s1 + joiner + s2
}
joinersss("hello",
"world")
joinersss("hello",
"world", joiner: ";")
//常量參数和变量參数
//函数參数的默认值都是常量。
试图改变一个函数參数的值会让这个函数体内部产生一个编译时错误。
这意味着您不能错
误地改变參数的值。
//在參数名称前用keyword var
定义变量參数:
func alignRight(var string:
String, countw:
Int, pad: Character) ->
String {
let amountToPad = countw -
count(string)
for
_ in
1...amountToPad {
string =
String(pad) + string
}
return string
}
alignRight("hello",
10,
"-")
//输入-输出參数
//方法的參数都是常量。不能改动;要声明变量必须在參数名前加 var
func swapTwoInts(inout a:
Int,inout b:
Int) {
let temporaryA = a
a = b
b = temporaryA
}
var someInt =
5
var anotherInt =
190
swapTwoInts(&someInt, &anotherInt)
someInt
anotherInt
swfit各种Function表现形式的更多相关文章
- 通过百度echarts实现数据图表展示功能
现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...
- JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式
相关链接: JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式 JS面向对象(2) -- this的使用,对 ...
- 【HTML5】嵌入另一张HTML文档、通过插件嵌入内容、嵌入数字表现形式
1.嵌入另一张HTML文档 iframe 元素允许在现有的HTML文档中嵌入另一张文档.下面代码展示了iframe元素的用法: <!DOCTYPE html> <html lang= ...
- easyui里弹窗的两种表现形式
easyui里弹窗的两种表现形式 博客分类: jQueryEasyUi 1.主JSP页面中描绘弹窗 <div id="centerDiv" data-options= ...
- function foo(){}、(function(){})、(function(){}())等函数区别分析
前面一段时间,看到(function(){}),(function(){}())这些函数就犯晕,不知道它到底是什么意思,为什么函数外要加小括号,函数后要加小括号,加和不加到底有什么区别……一直犯迷糊, ...
- [ActionScript 3.0] AS3.0 把图片分析成文本表现形式
PLP%uffs??1ti4b5I3iI5CMMGGE8Ta8?c8[mm3CF9sLaXZDll6kpjmhGmhE$GONEENhhGl6OWXb9lkNk0kkNpklZW6&bDN0q ...
- JavaScript之Function函数深入总结
整理了JavaScript中函数Function的各种,感觉函数就是一大对象啊,各种知识点都能牵扯进来,不单单是 Function 这个本身原生的引用类型的各种用法,还包含执行环境,作用域,闭包,上下 ...
- JavaScript Function 函数深入总结
整理了JavaScript中函数Function的各种,感觉函数就是一大对象啊,各种知识点都能牵扯进来,不单单是 Function 这个本身原生的引用类型的各种用法,还包含执行环境,作用域,闭包,上下 ...
- JS中函数常见的表现形式以及立即执行函数
函数常见的几种表现形式: 1.一般形式(函数声明): 会进行函数的预解释,函数会进行声明和定义,在函数体前面或则后面都可以进行调用. 2.函数表达式(匿名函数): 会进行函数的预解析,函数会进行声明但 ...
随机推荐
- poj 3278 catch that cow BFS(基础水)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 61826 Accepted: 19329 ...
- Java GUI编程4---标签组件JLabel
Java GUI编程4---标签组件JLabel 2018年06月11日 22:06:58 蓝蓝223 阅读数 12103更多 个人分类: Java书籍摘抄 所属专栏: Java Swing图形界面 ...
- AlloyClip的简单使用
<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- POJ2723 Get Luffy Out 【2-sat】
题目 Ratish is a young man who always dreams of being a hero. One day his friend Luffy was caught by P ...
- So注入工具TsoInject开发文档
So注入工具TsoInject开发文档 导语: 作为一个软件安全从业者而言,我们需要对某个App的关键函数就行Hook, 对于android而言,Smali层我们使用Xposed Hook框架,So层 ...
- python 小爬虫
import reimport urllibdef getHtml(url): page=urllib.urlopen(url); html=page.read() return htmldef ge ...
- jquery 获取 checkbox 的 checked 状态问题
这个郁闷了,今天写这个功能的时候发现了问题,上网找了好多资料对照,更加纠结... 事实证明一切,自己测试了N遍,发现网上的说法和自己以前的理解都是错的,不知道大家有没发现. 下面来看看网上大多资料的说 ...
- vue项目中使用阿里iconfont图标
在上一篇文章中介绍了如何在vue项目中使用vue-awesome,如果你想了解,请移步<vue项目中使用vue-awesome> 这里介绍一下vue项目中如何使用阿里的iconfont图标 ...
- 关于 react state的改变数据上面的一点问题
在react当中 比如说 this.state = { loginInfo: { account: "...", password: "..." } } thi ...
- 洛谷[P3622] 动物园
状压DP 发现本题中,每个小朋友是否高兴仅取决于其后五个动物的情况,我们可以用状压DP解决本题 首先已处理 num[i][s] 表示对于位置 i ,状态为 s 时有多少在 s 的同学满意 转移方程很好 ...