Swift中共有74个内建函数
- abs(-1) == 1
- abs(-42) == 42
- abs(42) == 42
- var languages = ["Swift", "Objective-C"]
- contains(languages, "Swift") == true
- contains(languages, "Java") == false
- contains([29, 85, 42, 96, 75], 42) == true
- var languages = ["Swift", "Objective-C"]
- var oldLanguages = dropFirst(languages)
- equal(oldLanguages, ["Objective-C"]) == true
- var languages = ["Swift", "Objective-C"]
- var newLanguages = dropLast(languages)
- equal(newLanguages, ["Swift"]) == true
- var languages = ["Swift", "Objective-C"]
- dump(languages)
- // Prints:
- // ? 2 elements
- // - [0]: Swift
- // - [1]: Objective-C
- var languages = ["Swift", "Objective-C"]
- equal(languages, ["Swift", "Objective-C"]) == true
- var oldLanguages = dropFirst(languages)
- equal(oldLanguages, ["Objective-C"]) == true
- for i in filter(1...100, { $0 % 10 == 0 })
- {
- // 10, 20, 30, ...
- println(i)
- assert(contains([10, 20, 30, 40, 50, 60, 70, 80, 90, 100], i))
- }
- var languages = ["Swift", "Objective-C"]
- find(languages, "Objective-C") == 1
- find(languages, "Java") == nil
- find([29, 85, 42, 96, 75], 42) == 2
- equal(indices([29, 85, 42]), [0, 1, 2])
- for i in indices([29, 85, 42]) {
- // 0, 1, 2
- println(i)
- }
- join(":", ["A", "B", "C"]) == "A:B:C"
- var languages = ["Swift", "Objective-C"]
- join("/", languages) == "Swift/Objective-C"
- equal(map(1...3, { $0 * 5 }), [5, 10, 15])
- for i in map(1...10, { $0 * 10 }) {
- // 10, 20, 30, ...
- println(i)
- assert(contains([10, 20, 30, 40, 50, 60, 70, 80, 90, 100], i))
- }
- max(0, 1) == 1
- max(8, 2, 3) == 8
- maxElement(1...10) == 10
- var languages = ["Swift", "Objective-C"]
- maxElement(languages) == "Swift"
- minElement(1...10) == 1
- var languages = ["Swift", "Objective-C"]
- minElement(languages) == "Objective-C"
- var languages = ["Swift", "Objective-C"]
- reduce(languages, "", { $0 + $1 }) == "SwiftObjective-C"
- reduce([10, 20, 5], 1, { $0 * $1 }) == 1000
- equal(reverse([1, 2, 3]), [3, 2, 1])
- for i in reverse([1, 2, 3]) {
- // 3, 2, 1
- println(i)
- }
- startsWith("foobar", "foo") == true
- startsWith(10..100, 10..15) == true
- var languages = ["Swift", "Objective-C"]
- startsWith(languages, ["Swift"]) == true
- abs(...)
- advance(...)
- alignof(...)
- alignofValue(...)
- assert(...)
- bridgeFromObjectiveC(...)
- bridgeFromObjectiveCUnconditional(...)
- bridgeToObjectiveC(...)
- bridgeToObjectiveCUnconditional(...)
- c_malloc_size(...)
- c_memcpy(...)
- c_putchar(...)
- contains(...)
- count(...)
- countElements(...)
- countLeadingZeros(...)
- debugPrint(...)
- debugPrintln(...)
- distance(...)
- dropFirst(...)
- dropLast(...)
- dump(...)
- encodeBitsAsWords(...)
- enumerate(...)
- equal(...)
- filter(...)
- find(...)
- getBridgedObjectiveCType(...)
- getVaList(...)
- indices(...)
- insertionSort(...)
- isBridgedToObjectiveC(...)
- isBridgedVerbatimToObjectiveC(...)
- isUniquelyReferenced(...)
- join(...)
- lexicographicalCompare(...)
- map(...)
- max(...)
- maxElement(...)
- min(...)
- minElement(...)
- numericCast(...)
- partition(...)
- posix_read(...)
- posix_write(...)
- print(...)
- println(...)
- quickSort(...)
- reduce(...)
- reflect(...)
- reinterpretCast(...)
- reverse(...)
- roundUpToAlignment(...)
- sizeof(...)
- sizeofValue(...)
- sort(...)
- split(...)
- startsWith(...)
- strideof(...)
- strideofValue(...)
- swap(...)
- swift_MagicMirrorData_summaryImpl(...)
- swift_bufferAllocate(...)
- swift_keepAlive(...)
- toString(...)
- transcode(...)
- underestimateCount(...)
- unsafeReflect(...)
- withExtendedLifetime(...)
- withObjectAtPlusZero(...)
- withUnsafePointer(...)
- withUnsafePointerToObject(...)
- withUnsafePointers(...)
- withVaList(...)
欢迎讨论,敬请勘误!
Swift中共有74个内建函数的更多相关文章
- Swift中编写单例的正确方式
在之前的帖子里聊过状态管理有多痛苦,有时这是不可避免的.一个状态管理的例子大家都很熟悉,那就是单例.使用Swift时,有许多方法实现单例,这是个麻烦事,因为我们不知道哪个最合适.这里我们来回顾一下单例 ...
- 关于Swift中的指针的那些事
前言 在Objective-c的世界中,一切对象都是指针.它是一种运行时语言,具体指针的对象类型将会在运行时,由系统分配.这样虽然自由,但是却并不安全. Swift世界就不一样了,Swift的世界很安 ...
- swift 中关于open ,public ,fileprivate,private ,internal,修饰的说明
关于 swift 中的open ,public ,fileprivate,private, internal的区别 以下按照修饰关键字的访问约束范围 从约束的限定范围大到小的排序进行说明 open,p ...
- 阿里巴巴最新开源项目 - [HandyJSON] 在Swift中优雅地处理JSON
项目名称:HandyJSON 项目地址:https://github.com/alibaba/handyjson 背景 JSON是移动端开发常用的应用层数据交换协议.最常见的场景便是,客户端向服务端发 ...
- Swift中的可选链与内存管理(干货系列)
干货之前:补充一下可选链(optional chain) class A { var p: B? } class B { var p: C? } class C { func cm() -> S ...
- 在Swift中实现单例方法
在写Swift的单例方法之前可以温习一下Objective-C中单例的写法: + (instancetype)sharedSingleton{ static id instance; static d ...
- [翻译]理解Swift中的Optional
原文出处:Understanding Optionals in Swift 苹果新的Swift编程语言带来了一些新的技巧,能使软件开发比以往更方便.更安全.然而,一个很有力的特性Optional,在你 ...
- 窥探Swift之使用Web浏览器编译Swift代码以及Swift中的泛型
有的小伙伴会问:博主,没有Mac怎么学Swift语言呢,我想学Swift,但前提得买个Mac.非也,非也.如果你想了解或者初步学习Swift语言的话,你可以登录这个网站:http://swiftstu ...
- swift 中指针的使用UnsafeMutablePointer
在swift中已经弱化了指针的使用,可以这么使用 let s: NSRange = NSMakeRange(, ) let at = UnsafeMutablePointer<NSRange&g ...
随机推荐
- Tomcat禁止显示目录和文件列表
Tomcat禁止显示目录和文件列表 打开 tomcat的安装目录/conf/web.xml 文件 <servlet> <servlet-name>default</s ...
- Candies(差分约束)
http://poj.org/problem?id=3159 题意: flymouse是幼稚园班上的班长,一天老师给小朋友们买了一堆的糖果,由flymouse来分发,在班上,flymouse和snoo ...
- 使用Struts2开发Java Web应用程序(目录)
连接地址 http://blog.csdn.net/struts2/article/details/1721752
- screen space directional occlusion(SSDO) in Unity5
也许是哪里出了问题..效果一般 16采样点 Gird . Random 博主近期渲染:最近用unity5弄的一些渲染 ---- by wolf96 http://blog.csdn.net/wolf ...
- Unity Fresnel Hero(Dota2) Shader
Shader "HeroShader" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _Rim ...
- C语言实现两栈空间共享
一个同学让我改一段两栈共享的C语言代码,实现进栈.出栈.输出栈里元素的功能. 代码如下: #include <stdio.h> #include <stdlib.h> #def ...
- UVa 10029 hash + dp
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- linux-kernel/CodingStyle
https://www.kernel.org/doc/Documentation/zh_CN/CodingStyle Chinese translated version of Documentati ...
- C#中的线程(中)-线程同步
1.同步要领 下面的表格列展了.NET对协调或同步线程动作的可用的工具: 简易阻止方法 构成 目的 Sleep 阻止给定的时间周期 Join 等待另一个线程 ...
- 关于session的实现:cookie与url重写
本文讨论的语境是java EE servlet. 我们都知道session的实现主要两种方式:cookie与url重写,而cookie是首选(默认)的方式,因为各种现代浏览器都默认开通cookie功能 ...