×

在Swift中使用数学函数出错

Falcon 2020-02-19 views:
自动摘要

正在生成中……

在swift 中使用一些数学函数如: sqrt(), floor(), round(), sin() ,pow() 出现以下错误:

Use of unresolved identifier 'pow'

根据平台的和实际需要,import不同的库

如果仅需要简单的数学函数运算

import Darwin
如果还需要其他标准函数
import Foundation
如果需要用户界面,macOS下,需要
import Cocoa
如果是在iOS下,则
import UIKit

或者对于所有平台,只使用数学函数运算时,可简单归纳为:

#if os(macOS) || os(iOS)
import Darwin
#elseif os(Linux) || CYGWIN
import Glibc
#endif