I am looking at the Swift documentation, but I can't find reference to what there's in other languages...
我正在查看Swift文档,但是我找不到其他语言的参考资料……
Examples: sin()
, cos()
, abs()
for math, uppercase()
, lowercase()
for strings, sort()
, pop()
, push()
for arrays etc...
例如:sin()、cos()、abs()表示数学、大写()、小写()表示字符串、sort()、pop()、push()表示数组等等。
For strings I've found this in the docs:
对于字符串,我在文档中发现:
Swift’s String type is bridged seamlessly to Foundation’s NSString class. If you are working with the Foundation framework in Cocoa or Cocoa Touch, the entire NSString API is available to call on any String value you create, in addition to the String features described in this chapter. You can also use a String value with any API that requires an NSString instance.
Swift的字符串类型无缝地连接到Foundation的NSString类。如果您正在使用Cocoa或Cocoa Touch中的Foundation框架,除了本章描述的字符串特性之外,还可以使用整个NSString API来调用创建的任何字符串值。您还可以对任何需要NSString实例的API使用字符串值。
Could you point me to some doc or where can I find those functions listed?
你能指给我看一些医生吗?我在哪里可以找到这些功能?
3 个解决方案
#1
17
Looks like this is working...
看来这行得通……
import Foundation
var theCosOfZero: Double = Double(cos(0)) // theCosOfZero equals 1
#2
10
sin()
, cos()
, abs()
are C methods defined in math.h https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/math.3.html
sin()、cos()、abs()是数学中定义的C方法。h https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/math.3.html
"str".uppercaseString()
and "str".lowercaseString()
are NSString methods.
“str”.upper casestring()和“str”. lowercasestring()是NSString方法。
sort()
is part of the Swift Standard Library, documented at https://developer.apple.com/documentation/swift/array/1688499-sort
sort()是Swift标准库的一部分,记录在https://developer.apple.com/documentation/swift/array/1688499-sort中
Array.append()
and Array.removeLast()
are also defined in the Swift Standard Library, documented at https://developer.apple.com/documentation/swift/array
Array.append()和Array.removeLast()在Swift标准库中也有定义,记录在https://developer.apple.com/documentation/swift/array中
#3
9
The math functions are defined in the Darwin module, so as absolute minimum you have add this:
数学函数是在Darwin模块中定义的,因此,作为绝对最小值,您可以添加以下内容:
import Darwin
In most cases import Foundation
or import Cocoa
will suffice, since those modules import the Darwin
module. If you need access to constants like M_PI
or similar, navigate with cmd+click to the Darwin
module and the to the Darwin.C
. Here you would find the C API imports and the Darwin.C.math
among them. This way you may examine what's available, already converted to Swift. Nevertheless, all that C API is available with import Darwin
.
在大多数情况下,导入Foundation或导入Cocoa都足够了,因为这些模块导入Darwin模块。如果您需要访问诸如M_PI或类似的常量,请使用cmd+单击达尔文模块和达尔文。在这里你会发现C API导入和达尔文。C。数学在他们中间。通过这种方式,您可以检查可用的、已经转换为Swift的内容。不过,所有的C API都可以通过import Darwin获得。
You cannot issue import Darwin.C.math
directly, because you will see the following runtime error (or similar if you're not in the playground):
你不能提出进化论。直接计算,因为您将看到以下运行时错误(如果您不在操场上,您将看到类似的错误):
Playground execution failed: Error in auto-import:
failed to get module 'math' from AST context
Example playground code:
操场上的代码示例:
import Darwin
func degToRad(degrees: Double) -> Double {
// M_PI is defined in Darwin.C.math
return M_PI * 2.0 * degrees / 360.0
}
for deg in 0..<360 {
sin(degToRad(Double(deg)))
}
#1
17
Looks like this is working...
看来这行得通……
import Foundation
var theCosOfZero: Double = Double(cos(0)) // theCosOfZero equals 1
#2
10
sin()
, cos()
, abs()
are C methods defined in math.h https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/math.3.html
sin()、cos()、abs()是数学中定义的C方法。h https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/math.3.html
"str".uppercaseString()
and "str".lowercaseString()
are NSString methods.
“str”.upper casestring()和“str”. lowercasestring()是NSString方法。
sort()
is part of the Swift Standard Library, documented at https://developer.apple.com/documentation/swift/array/1688499-sort
sort()是Swift标准库的一部分,记录在https://developer.apple.com/documentation/swift/array/1688499-sort中
Array.append()
and Array.removeLast()
are also defined in the Swift Standard Library, documented at https://developer.apple.com/documentation/swift/array
Array.append()和Array.removeLast()在Swift标准库中也有定义,记录在https://developer.apple.com/documentation/swift/array中
#3
9
The math functions are defined in the Darwin module, so as absolute minimum you have add this:
数学函数是在Darwin模块中定义的,因此,作为绝对最小值,您可以添加以下内容:
import Darwin
In most cases import Foundation
or import Cocoa
will suffice, since those modules import the Darwin
module. If you need access to constants like M_PI
or similar, navigate with cmd+click to the Darwin
module and the to the Darwin.C
. Here you would find the C API imports and the Darwin.C.math
among them. This way you may examine what's available, already converted to Swift. Nevertheless, all that C API is available with import Darwin
.
在大多数情况下,导入Foundation或导入Cocoa都足够了,因为这些模块导入Darwin模块。如果您需要访问诸如M_PI或类似的常量,请使用cmd+单击达尔文模块和达尔文。在这里你会发现C API导入和达尔文。C。数学在他们中间。通过这种方式,您可以检查可用的、已经转换为Swift的内容。不过,所有的C API都可以通过import Darwin获得。
You cannot issue import Darwin.C.math
directly, because you will see the following runtime error (or similar if you're not in the playground):
你不能提出进化论。直接计算,因为您将看到以下运行时错误(如果您不在操场上,您将看到类似的错误):
Playground execution failed: Error in auto-import:
failed to get module 'math' from AST context
Example playground code:
操场上的代码示例:
import Darwin
func degToRad(degrees: Double) -> Double {
// M_PI is defined in Darwin.C.math
return M_PI * 2.0 * degrees / 360.0
}
for deg in 0..<360 {
sin(degToRad(Double(deg)))
}