Swift标准函数
标签:
abs(-1)==1
abs(-42)==42
abs(42)==42
contains(languages,"Swift")==true
contains(languages,"Java")==false
contains([29,85,42,96,75],42)==true
dump(languages)
//Prints:
//?2elements
//-[0]:Swift
//-[1]:Objective-C
equal(languages,["Swift","Objective-C"])==true
varoldLanguages=dropFirst(languages)
equal(oldLanguages,["Objective-C"])==true
- foriinfilter(1...100,{$0%10==0})
- {
- //10,20,30,...
- println(i)
- assert(contains([10,40,50,60,70,80,90,100],i))
- }
find(languages,"Objective-C")==1
find(languages,"Java")==nil
find([29,42)==2
equal(indices([29,42]),[0,1,2])
foriinindices([29,42]){
//0,2
println(i)
}
join(":",["A","B","C"])=="A:B:C"
varlanguages=["Swift","Objective-C"]
join("/",languages)=="Swift/Objective-C"
- equal(map(1...3,{$0*5}),[5,10,15])
- foriinmap(1...10,{$0*10}){
- //10,i))
- }
max(0,1)==1
max(8,2,3)==8
- maxElement(1...10)==10
- varlanguages=["Swift","Objective-C"]
- maxElement(languages)=="Swift"
minElement(1...10)==1
varlanguages=["Swift","Objective-C"]
minElement(languages)=="Objective-C"
reduce(languages,"",{$0+$1})=="SwiftObjective-C"
reduce([10,5],{$0*$1})==1000
equal(reverse([1,3]),[3,1])
foriinreverse([1,3]){
//3,1
println(i)
}
startsWith("foobar","foo")==true
startsWith(10..100,10..15)==true
varlanguages=["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(...)
标签: