//: 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表现形式的更多相关文章

  1. 通过百度echarts实现数据图表展示功能

    现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...

  2. JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式

    相关链接: JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式 JS面向对象(2) -- this的使用,对 ...

  3. 【HTML5】嵌入另一张HTML文档、通过插件嵌入内容、嵌入数字表现形式

    1.嵌入另一张HTML文档 iframe 元素允许在现有的HTML文档中嵌入另一张文档.下面代码展示了iframe元素的用法: <!DOCTYPE html> <html lang= ...

  4. easyui里弹窗的两种表现形式

    easyui里弹窗的两种表现形式 博客分类: jQueryEasyUi   1.主JSP页面中描绘弹窗   <div id="centerDiv" data-options= ...

  5. function foo(){}、(function(){})、(function(){}())等函数区别分析

    前面一段时间,看到(function(){}),(function(){}())这些函数就犯晕,不知道它到底是什么意思,为什么函数外要加小括号,函数后要加小括号,加和不加到底有什么区别……一直犯迷糊, ...

  6. [ActionScript 3.0] AS3.0 把图片分析成文本表现形式

    PLP%uffs??1ti4b5I3iI5CMMGGE8Ta8?c8[mm3CF9sLaXZDll6kpjmhGmhE$GONEENhhGl6OWXb9lkNk0kkNpklZW6&bDN0q ...

  7. JavaScript之Function函数深入总结

    整理了JavaScript中函数Function的各种,感觉函数就是一大对象啊,各种知识点都能牵扯进来,不单单是 Function 这个本身原生的引用类型的各种用法,还包含执行环境,作用域,闭包,上下 ...

  8. JavaScript Function 函数深入总结

    整理了JavaScript中函数Function的各种,感觉函数就是一大对象啊,各种知识点都能牵扯进来,不单单是 Function 这个本身原生的引用类型的各种用法,还包含执行环境,作用域,闭包,上下 ...

  9. JS中函数常见的表现形式以及立即执行函数

    函数常见的几种表现形式: 1.一般形式(函数声明): 会进行函数的预解释,函数会进行声明和定义,在函数体前面或则后面都可以进行调用. 2.函数表达式(匿名函数): 会进行函数的预解析,函数会进行声明但 ...

随机推荐

  1. Selenium - WebDriver: Waits

    These days most of the web apps are using AJAX techniques. When a page is loaded to browser, the ele ...

  2. File IO(NIO.2):路径类 和 路径操作

    路径类 Java SE 7版本中引入的Path类是java.nio.file包的主要入口点之一.如果您的应用程序使用文件I / O,您将需要了解此类的强大功能. 版本注意:如果您有使用java.io. ...

  3. 【转】unity自带寻路Navmesh入门教程(一)

    http://liweizhaolili.blog.163.com/blog/static/16230744201271161310135/ 说明:从今天开始,我阿赵打算写一些简单的教程,方便自己日后 ...

  4. try 与catch的作用

    首先要清楚,如果没有try的话,出现异常会导致程序崩溃.而try则可以保证程序的正常运行下去,比如说: try{ int i = 1/0; }catch(Exception e){ e.printSt ...

  5. BZOJ1797 [Ahoi2009]Mincut 最小割 【最小割唯一性判定】

    题目 A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站,如果切断这条道路 ...

  6. swarm 集群管理

    1.创建服务 docker service create --replicas 1 --name hello busybox ping baiud.com 2.显示服务详细信息 3.扩展服务数量 4. ...

  7. Python之面向对象:面向对象基础

    一.面向过程.面向对象对比 1.面向过程 根据业务逻辑从上到下写垒代码 2.函数式思想 将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 3.面向对象 对函数进行分类和封装 1.2.3一步 ...

  8. css 两列布局中单列定宽单列自适应布局的6种思路

    前面的话 说起自适应布局方式,单列定宽单列自适应布局是最基本的布局形式.本文将从float.inline-block.table.absolute.flex和grid这六种思路来详细说明如何巧妙地实现 ...

  9. AJAX在VS2005中的简单应用 使用ajaxpro.2.dll[点击按钮执行事件不刷新]

    原文发布时间为:2008-10-21 -- 来源于本人的百度文章 [由搬家工具导入] 1.下載ajaxpro.dll或AjaxPro.2.dll 放在Bin文件夹中2.配置web.config 3.u ...

  10. config .net webapi to return json.

    1.add content negotiator using System; using System.Collections.Generic; using System.Linq; using Sy ...