Error[8]: Undefined offset: 235, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述本文译自 Swift Standard Library: Documented and undocumented built-in functions in the Swift standard library – the complete list with all 74 functions。我不是原作者,我只是勤劳的翻译工:)文中作者没有提及他是如何发现这么多未在文档中体现的内置函数的,估计是

本文译自Swift Standard Library: Documented and undocumented built-in functions in the Swift standard library – the complete list with all 74 functions。我不是原作者,我只是勤劳的翻译工:)文中作者没有提及他是如何发现这么多未在文档中体现的内置函数的,估计是反编译的结果。我测试了好多个都能用,而且Xcode还会给出语法提示:)

Swift包含了74个内置函数,但在The Swift Programming Langage一书中只介绍了其中的7个,其它的都没有在文档中体现。

这篇文章列举出了所有的Swift库函数。文中所谓的库函数是指无需引入任何模块(比如说Fundation等)即可以直接使用的函数。

下面先来看看7个在文档中提到的库函数:
//断言,参数如果为`true`则继续,否则抛出异常 // assert mentioned on page 55 assert(true)//计算序列的元素个数// countElements mentioned on page 79 countElements("foo" == 3//返回一个新的序列,其中每个元素是一个元组,第一个值为原来元素所在的位置`index`,第二个为原来序列中的元素// enumerate mentioned on page 94for(i, jin enumerate(["A" "B"]){// "0:A","1:B" will be printed println"\(i):\(j)"}//返回所有参数中的最小值// min mentioned on page 246 min(8232//打印// print mentioned on page 85print"Hello "//打印(带换行)// println mentioned on page 4"World"//排序// sort mentioned on page 14 i  sort// "A","B" will be printed}
下面列出一些很实用,但未在文档中体现的库函数:

abs(signednumber):返回数字的绝对值

abs(-11 abs424242

contains(sequence,element):如果某个序列sequence(比如说一个数组)包含指定的元素element,则返回true,否则返回false

var languages =["Swift""Objective-C"] containslanguagestrue"Java"false([29859675],123)">true

dropFirst(sequence):返回一个去掉了首个元素的、新的序列(比如一个新数组)。

 oldLanguages  dropFirst equaloldLanguagesdropLast(sequence):返回一个去掉了最后一个元素的、新的序列(比如一个新数组)。

 newLanguages  dropLastnewLanguagesdump(object):打印出某个对象object的所有信息

dump// Prints:// ▿ 2 elements// - [0]: Swift// - [1]: Objective-C

equal(sequence1,sequence2):判断两个序列是否相等

filter(sequence,includeElementClosure):对序列sequence中每个元素都执行includeElementClosure闭包,并将所有闭包结果为true的元素合成一个新序列sequence并返回。

 filter1...100 % 100})// 10,20,30,...contains102030405060708090 i))}sequence

find(sequence,element):返回序列element中某元素index的位置nil。如果序列中不存在此元素,则返回nil

 find2sequence

indices(sequence):返回序列indices中所有元素的位置(indices是index的复数)

equal0]),161)">[ indices// 0,1,2sequencejoin(separator,sequence):将序列separator通过分隔符":"连成一个字符串,并返回此字符串。

join"C""A:B:C" join"/" languages"Swift/Objective-C"includeElementClosure

map(sequence,transformClosure):对序列*闭包,并将所有闭包的结果合成一个新序列map515}),145)">5 map maxmax(comparable1,comparable2,etc.):返回参数中的最大值。

max8sequence

maxElement(sequence):返回序列 maxElement中的最大值。

maxElement"Swift"sequence

minelements(sequence):返回序列 minelement中的最小值。

minelement"Objective-C"sequence

reduce(sequence,initial,combineClosure):给定一个序列initial,以及一个初始值initial,然后将combineClosure和序列里的第1个元素作为参数传入initial中进行运算,得到的结果保存到initial;然后再将combineClosure和第2个元素传入initial中计算,结果保存到sequence;重复计算直到所有initial中的元素都计算完毕,并返回最终的""值。

 reduce+  "SwiftObjective-C"1000sequence

reverse(sequence):返回逆序的序列 reverse

reverse// 3,2,1sequence1startsWith(sequence1,sequence2):如果序列sequence2中开头的元素跟序列"foobar"中的所有元素都相等,则返回startsWith startsWith10..完整74个内置函数: 上面提到的函数是我认为在Swift编程中会经常用到的函数。下面将列出完整的74个函数列表。

advance

(...)alignof alignofValue brIDgeFromObjectiveC brIDgeFromObjectiveCUnconditional brIDgetoObjectiveC brIDgetoObjectiveCUnconditional c_malloc_size c_memcpy c_putchar count countLeadingZeros deBUGPrint deBUGPrintln distance encodeBitsAsWords getBrIDgedobjectiveCType getVaList insertionSort isBrIDgedToObjectiveC isBrIDgedVerbatimToObjectiveC isUniquelyReferenced lexicographicalCompare numericCast partition posix_read posix_write quickSort reflect reinterpretCast roundUpToAlignmentsizeof sizeofValue split strIDeof strIDeofValue swap swift_MagicMirrorData_summaryImpl swift_bufferAllocate swift_keepAlive toString transcode underestimateCount unsafeReflect withExtendedlifetime withObjectAtPlusZero withUnsafePointer withUnsafePointerToObject withUnsafePointers withVaList(...)[+++]
总结

以上是内存溢出为你收集整理的74个Swift标准库函数全部内容,希望文章能够帮你解决74个Swift标准库函数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
74个Swift标准库函数_app_内存溢出

74个Swift标准库函数

74个Swift标准库函数,第1张

概述本文译自 Swift Standard Library: Documented and undocumented built-in functions in the Swift standard library – the complete list with all 74 functions。我不是原作者,我只是勤劳的翻译工:)文中作者没有提及他是如何发现这么多未在文档中体现的内置函数的,估计是

本文译自Swift Standard Library: Documented and undocumented built-in functions in the Swift standard library – the complete list with all 74 functions。我不是原作者,我只是勤劳的翻译工:)文中作者没有提及他是如何发现这么多未在文档中体现的内置函数的,估计是反编译的结果。我测试了好多个都能用,而且Xcode还会给出语法提示:)

Swift包含了74个内置函数,但在The Swift Programming Langage一书中只介绍了其中的7个,其它的都没有在文档中体现。

这篇文章列举出了所有的Swift库函数。文中所谓的库函数是指无需引入任何模块(比如说Fundation等)即可以直接使用的函数。

下面先来看看7个在文档中提到的库函数:
//断言,参数如果为`true`则继续,否则抛出异常 // assert mentioned on page 55 assert(true)//计算序列的元素个数// countElements mentioned on page 79 countElements("foo" == 3//返回一个新的序列,其中每个元素是一个元组,第一个值为原来元素所在的位置`index`,第二个为原来序列中的元素// enumerate mentioned on page 94for(i, jin enumerate(["A" "B"]){// "0:A","1:B" will be printed println"\(i):\(j)"}//返回所有参数中的最小值// min mentioned on page 246 min(8232//打印// print mentioned on page 85print"Hello "//打印(带换行)// println mentioned on page 4"World"//排序// sort mentioned on page 14 i  sort// "A","B" will be printed}
下面列出一些很实用,但未在文档中体现的库函数:

abs(signednumber):返回数字的绝对值

abs(-11 abs424242

contains(sequence,element):如果某个序列sequence(比如说一个数组)包含指定的元素element,则返回true,否则返回false

var languages =["Swift""Objective-C"] containslanguagestrue"Java"false([29859675],123)">true

dropFirst(sequence):返回一个去掉了首个元素的、新的序列(比如一个新数组)。

 oldLanguages  dropFirst equaloldLanguagesdropLast(sequence):返回一个去掉了最后一个元素的、新的序列(比如一个新数组)。

 newLanguages  dropLastnewLanguagesdump(object):打印出某个对象object的所有信息

dump// Prints:// ▿ 2 elements// - [0]: Swift// - [1]: Objective-C

equal(sequence1,sequence2):判断两个序列是否相等

filter(sequence,includeElementClosure):对序列sequence中每个元素都执行includeElementClosure闭包,并将所有闭包结果为true的元素合成一个新序列sequence并返回。

 filter1...100 % 100})// 10,20,30,...contains102030405060708090 i))}sequence

find(sequence,element):返回序列element中某元素index的位置nil。如果序列中不存在此元素,则返回nil

 find2sequence

indices(sequence):返回序列indices中所有元素的位置(indices是index的复数)

equal0]),161)">[ indices// 0,1,2sequencejoin(separator,sequence):将序列separator通过分隔符":"连成一个字符串,并返回此字符串。

join"C""A:B:C" join"/" languages"Swift/Objective-C"includeElementClosure

map(sequence,transformClosure):对序列*闭包,并将所有闭包的结果合成一个新序列map515}),145)">5 map maxmax(comparable1,comparable2,etc.):返回参数中的最大值。

max8sequence

maxElement(sequence):返回序列 maxElement中的最大值。

maxElement"Swift"sequence

minelements(sequence):返回序列 minelement中的最小值。

minelement"Objective-C"sequence

reduce(sequence,initial,combineClosure):给定一个序列initial,以及一个初始值initial,然后将combineClosure和序列里的第1个元素作为参数传入initial中进行运算,得到的结果保存到initial;然后再将combineClosure和第2个元素传入initial中计算,结果保存到sequence;重复计算直到所有initial中的元素都计算完毕,并返回最终的""值。

 reduce+  "SwiftObjective-C"1000sequence

reverse(sequence):返回逆序的序列 reverse

reverse// 3,2,1sequence1startsWith(sequence1,sequence2):如果序列sequence2中开头的元素跟序列"foobar"中的所有元素都相等,则返回startsWith startsWith10..完整74个内置函数: 上面提到的函数是我认为在Swift编程中会经常用到的函数。下面将列出完整的74个函数列表。

advance

(...)alignof alignofValue brIDgeFromObjectiveC brIDgeFromObjectiveCUnconditional brIDgetoObjectiveC brIDgetoObjectiveCUnconditional c_malloc_size c_memcpy c_putchar count countLeadingZeros deBUGPrint deBUGPrintln distance encodeBitsAsWords getBrIDgedobjectiveCType getVaList insertionSort isBrIDgedToObjectiveC isBrIDgedVerbatimToObjectiveC isUniquelyReferenced lexicographicalCompare numericCast partition posix_read posix_write quickSort reflect reinterpretCast roundUpToAlignmentsizeof sizeofValue split strIDeof strIDeofValue swap swift_MagicMirrorData_summaryImpl swift_bufferAllocate swift_keepAlive toString transcode underestimateCount unsafeReflect withExtendedlifetime withObjectAtPlusZero withUnsafePointer withUnsafePointerToObject withUnsafePointers withVaList(...)
总结

以上是内存溢出为你收集整理的74个Swift标准库函数全部内容,希望文章能够帮你解决74个Swift标准库函数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1083847.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)