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(...)
一些常用的:
abs(signedNumber): 返回给定的有符号数字的绝对值。很简单,但是没有在文档中记录。
abs(-1)==1abs(-42)==42abs(42)==42
contains(sequence,element): 如果给定的序列(如数组)包含特定的元素,则返回true。
varlanguages=["Swift","Objective-C"]contains(languages,"Swift")==truecontains(languages,"Java")==falsecontains([29,85,42,96,75],42)==true
dropFirst(sequence): 返回一个去掉第一个元素的新序列(如数组)。
varlanguages=["Swift","Objective-C"]varoldLanguages=dropFirst(languages)equal(oldLanguages,["Objective-C"])==true
dropLast(sequence): 返回一个的新序列(如数组),该序列去掉作为参数传递给函数的最后一个元素。
varlanguages=["Swift","Objective-C"]varnewLanguages=dropLast(languages)equal(newLanguages,["Swift"])==true
varlanguages=["Swift","Objective-C"]dump(languages)//Prints://?2elements//-[0]:Swift//-[1]:Objective-C
equal(sequence1,sequence2): 如果序列1和序列2包含相同的元素,则返回true。
varlanguages=["Swift","Objective-C"]equal(languages,["Swift","Objective-C"])==truevaroldLanguages=dropFirst(languages)equal(oldLanguages,["Objective-C"])==true
filter(sequence,includeElementClosure): 返回序列的一个元素,这个元素满足includeElementClosure所指定的条件。
foriinfilter(1...100,{$0%10==0}){//10,20,30,...println(i)assert(contains([10,40,50,60,70,80,90,100],i))}
find(sequence,element): 再给定的序列中返回一个指定的索引,如果在序列中没有找到这个元素就返回nil。
varlanguages=["Swift","Objective-C"]find(languages,"Objective-C")==1find(languages,"Java")==nilfind([29,42)==2
indices(sequence): 在指定的序列中返回元素的索引(零索引)。
equal(indices([29,42]),[0,1,2])foriinindices([29,42]){//0,2println(i)}
join(separator,sequence): 返回一个由给定的分隔符分离出来的序列的元素。
join(":",["A","B","C"])=="A:B:C"varlanguages=["Swift","Objective-C"]join("/",languages)=="Swift/Objective-C"
map(sequence,transformClosure): 如果transformClosure适用于所给序列中所有的元素,则返回一个新序列。
equal(map(1...3,{$0*5}),[5,10,15])foriinmap(1...10,{$0*10}){//10,i))}
max(comparable1,comparable2,etc.): 返回函数所给参数中的最大值。
max(0,1)==1max(8,2,3)==8
maxElement(sequence): 返回所给序列的同类元素中的最大元素。
maxElement(1...10)==10varlanguages=["Swift","Objective-C"]maxElement(languages)=="Swift"
minElements(sequence): 返回所给序列的同类元素中的最小元素。
minElement(1...10)==1varlanguages=["Swift","Objective-C"]minElement(languages)=="Objective-C"
reduce(sequence,initial,combineClosure): 从第一个初始值开始对其进行combineClosure操作,递归式地将序列中的元素合并为一个元素。
varlanguages=["Swift","Objective-C"]reduce(languages,"",{$0+$1})=="SwiftObjective-C"reduce([10,5],{$0*$1})==1000
reverse(sequence): 返回所给序列的倒序。
equal(reverse([1,3]),[3,1])foriinreverse([1,3]){//3,1println(i)}
startsWith(sequence1,sequence2):如果序列1和序列2的起始元素相等,则返回true。
startsWith("foobar","foo")==true
startsWith(10..100,10..15)==true
varlanguages=["Swift","Objective-C"]
startsWith(languages,["Swift"])==true