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.函数表达式(匿名函数): 会进行函数的预解析,函数会进行声明但 ...
随机推荐
- Matlab freqs 函数
freqs 模拟滤波器的频率响应 语法: h = freqs(b,a,w)[h,w] = freqs(b,a)[h,w] = freqs(b,a,f)freqs(b,a) 描述: freqs 返回一个 ...
- TOJ5272: 逆矩阵
5272: 逆矩阵 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 11 ...
- WebService常用公共接口
Web Service 一些对外公开的网络服务接口 商业和贸易: 1.股票行情数据 WEB 服务(支持香港.深圳.上海基金.债券和股票:支持多股票同时查询) Endpoint: http://we ...
- HLG 1494网络 (求的割点数目)可做模板
网络 Time Limit: 1000 MS Memory Limit: 65535 K Total Submit: 103(32 users) Total Accepted: 54(31 users ...
- CodeForces Round #521 (Div.3) A. Frog Jumping
http://codeforces.com/contest/1077/problem/A A frog is currently at the point 00 on a coordinate axi ...
- CF 964C Alternating Sum
给定两正整数 $a, b$ .给定序列 $s_0, s_1, \dots, s_n,s_i$ 等于 $1$ 或 $-1$,并且已知 $s$ 是周期为 $k$ 的序列并且 $k\mid (n+1)$,输 ...
- react输入框输入中文bug
一般来说,react上我们都会用change事件去处理input的输入,但这样就导致一个问题,在输入中文的时候,我们还没输入完成就会触发change事件,这样显然不是理想状况. 那么,怎么解决这个问题 ...
- 【CCF】炉石传说 模拟
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- springboot开启定时任务 添加定时任务 推送
最近在自学Java的springboot框架,要用到定时推送消息.参考了网上的教程,自己调试,终于调好了.下面将网上的教程归纳下,总结复习下. springboot开启定时任务 在SpringBo ...
- 反射的基本使用以及原理(Class获取方式)
1.什么是反射技术? 动态获取指定类以及类中的内容(成员),并运行其内容. 应用程序已经运行,无法在其中进行new对象的建立,就无法使用对象.这时可以根据配置文件的类全名去找对应的字节码文件,并加载进 ...