Swift Standard Library
Swift has 74 built-in functions but only seven of them are documented in the Swift book (“The Swift Programming Language”). The rest remain undocumented.
This article lists all built-in Swift functions – both documented and undocumented ones. The definition used for “built-in function” used in this article is a function available in Swift without
Let’s start with the seven documented built-in functions mentioned in the Swift book along with the page number on which the function was first mentioned:
[objc] view plaincopyprint?-
// assert mentioned on page 55
- assert(true)
- // countElements mentioned on page 79
- countElements("foo") == 3
- // enumerate mentioned on page 94
- for (i, j) in enumerate(["A", "B"]) {
- // "0:A", "1:B" will be printed
- println("\(i):\(j)")
- }
- // min mentioned on page 246
- min(8, 2, 3) == 2
- // print mentioned on page 85
-
print("Hello "
- // println mentioned on page 4
- println("World")
- // sort mentioned on page 14
- for i in sort(["B", "A"]) {
- // "A", "B" will be printed
- println(i)
- }
Now on to the most useful undocumented functions …
abs(signedNumber): Returns the absolute value of a given signed number. Trivial but not documented.
[objc] view plaincopyprint?- abs(-1) == 1
- abs(-42) == 42
- abs(42) == 42
contains(sequence, element): Returns true if a given sequence (such as an array) contains the specified element. [objc] view plaincopyprint?
- var languages = ["Swift", "Objective-C"]
- contains(languages, "Swift") == true
- contains(languages, "Java") == false
- contains([29, 85, 42, 96, 75], 42) == true
dropFirst(sequence): Returns a new sequence (such as an array) without the first element of the sequence. [objc] view plaincopyprint?
- var languages = ["Swift", "Objective-C"]
- var oldLanguages = dropFirst(languages)
- equal(oldLanguages, ["Objective-C"]) == true
dropLast(sequence): Returns a new sequence (such as an array) without the last element of the sequence passed as argument to the function. [objc] view plaincopyprint?
- var languages = ["Swift", "Objective-C"]
- var newLanguages = dropLast(languages)
- equal(newLanguages, ["Swift"]) == true
dump(object): Dumps the contents of an object to standard output.
[objc] view plaincopyprint?- var languages = ["Swift", "Objective-C"]
- dump(languages)
- // Prints:
- // ▿ 2 elements
- // - [0]: Swift
- // - [1]: Objective-C
equal(sequence1, sequence2): Returns true if sequence1 and sequence2 contain the same elements.
[objc] view plaincopyprint?- 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))
- }
find(sequence, element): Return the index of a specified element in the given sequence. Or nil if the element is not found in the sequence. [objc] view plaincopyprint?
- var languages = ["Swift", "Objective-C"]
- find(languages, "Objective-C") == 1
- find(languages, "Java") == nil
- find([29, 85, 42, 96, 75], 42) == 2
indices(sequence): Returns the indices (zero indexed) of the elements in the given sequence. [objc] view plaincopy
相關推薦
Swift Standard Library
Swift has 74 built-in functions but only seven of them are documented in the Swift book (“The Swift Programming Language”). The rest r
Python Standard Library
pos 介紹 win .net let keyword xpath imp 9.4 出自:http://blog.csdn.net/qiqll/article/details/39339319 0.1. 關於本書 0.2. 代碼約定 0.3. 關於例
筆記-python-standard library-8.1 data types-datetime
none struct supported 方法 all min lag ons ros 筆記-python-standard library-8.1 data types-datetime 1. Datatimes 本章節內容為日期和時間處理類和方法。
筆記-python-standard library-9.6 random
conf next step += spi red exp option server 筆記-python-standard library-9.6 random 1. random source code:Lib/random.py 1.1. func
筆記-python-standard library-11.2 os.path
exist time split case linu basename 當前 輸出 字符轉換 筆記-python-standard library-11.2 os.path 1. os.path Source code: Lib/posixpath.py (f
筆記-python-standard library-17.7 queue
筆記-python-standard library-17.7 queue 1. queue source code:Lib/queue.py 該模組實現了多生產者,多消費者佇列。 此模組實現了所有的required locking semantics. 模組
筆記-python-standard library-16.3 time
輸出 bsp sleep 定義 最適 元組 enter local int 筆記-python-standard library-16.3 time 1. time 1.1. 開始 time模塊中時間表現的格式主要有三種: timestamp時間戳,
The Python 2 Standard Library by Example
Distributed with every copy of Python, the Standard Library contains hundreds of modules that provide tools for interacting with the operating system, i
Go: Testing Standard Library Changes
Go: Testing Standard Library ChangesI had a wonderful time at GopherCon 2017. One of the highlights was being a mentor at the Go Contributor Workshop. This
Python3.5.2 document學習系列之02、The Python Standard Library(python 標準庫)——介紹
1.介紹Python庫包含幾種不同種類的組成部分。它包含通常被認為是一種語言“核心”部分的資料型別,如數字和列表。對這些型別來說,Python語言核心定義了書寫上的格式和位置以及一些語義上的約束,但沒有完全定義語法(另一方面,語言核心定義了語法特性像拼寫和操作優先順序)這個庫
Python手冊(Standard Library)--datetime+time+calendar
datetime datetime模組定義了6個類 datetime.date 表示日期的類 datetime.datetime 表示日期時間的類 datetime.time 表示時間的類 datetime.timedelta
標準標簽庫JSTL(JSP Standard Tag Library)
when 標準 表達 XML 只有一個 默認 with 本地 輸出變量 1, 核心標簽(最常用, 最重要的) 表達式控制標簽 out 輸出常量 value---直接賦值 輸出變量 default---默認值 escapeXml--
STL(Standard Template Library)
float hms stl containe 排序 Go iterator 操作 eight 容器(Containers) list、deque、vector、map等 算法(Algorithms) 算法作用於容器,它們提供了執行各種操作的方式。包括了對容器的
<Standard Template Library>標準模板庫專項複習總結
看了看部落格園的申請時間也一年多了...想想自己一年多以來一直處於各種划水狀態,現在又要面臨ACM的衝擊... 還是要抓緊時間趕緊複習一下了- -畢竟校園新生賽還是有獎金的.. 1.棧 先進後出(LIFO)表 標頭檔案:#include<stack> 變數
<Standard Template Library>標準模板庫專項複習總結(二)
4.佇列 先進先出(FIFO)表 標頭檔案:#include<queue> 變數的定義:queue<TYPE>queueName 成員函式: bool empty() 空佇列返回true,否則返回false void pop
Swift工程如何整合Static Library
我們的iOS專案中使用了Swift+Objective-C的混合開發,很長一段時間我們在Podfile中使用的是use_frameworks!,也就是把所有Pods做成Dynamic framework。 微信等第三方SDK以靜態庫.a的形式提供給開發者,導致我們沒有辦法直接依賴,會報類似xxx has tr
Cpp Chapter 16: The string Class and the Standard Template Library
(這已經是第二次部落格園吞我東西了,有點心態爆炸) 16.1 The string Class ) Constructing a string Here is a table which shows the seven form of constructors that the string class
JSTL(JavaServer Pages Standard Tag Library)
JSTL(JavaServer Pages Standard Tag Library,JSP標準標籤庫)是一個不斷完善的開放原始碼的JSP標籤庫。 之前有學過c++的STL,剛開始還以為JSTL是java的STL。。。 大致簡介: JSTL 1.0 釋出於 2002
The Standard Template Library
Containers: 容器是一大堆元素的集合,主要分為三類容器: (1)序列式容器(sequence containers) 序列式容器經常被實現為array或者linked list。這是一種有序(ordered)的集合,每個元素都有確鑿的位置,主要取決於插入時機和地點,與元素的數值無關。STL中包含的s
【JavaEE】JSTL(JSP Standard Tag Library,JSP標準標籤庫)
怎麼用? 1.引入jar包。jstl.jar和standard.jar 2.在頁面中引入,使用JSPtaglib指令。注意,如果想和EL表示式一起使用,需要加入高版本的JSTL 基本用法: 假定頁面引入是這樣的指令 <%@ taglib prefix="c" uri="