| 🟢 |
Actor
|
| ✅ |
Any |
| ✅ |
AnyActor |
| ✅ |
AnyHashable |
| ✅ |
AnyObject |
| 🟢 |
Array
init()
init(repeating: Element, count: Int)
init(_ sequence: any Sequence<Element>)
- 集合 API 的支持情况请参见
Collection
|
| ✅ |
assert |
| ✅ |
assertionFailure |
| ✅ |
AsyncSequence |
| ✅ |
AsyncStream
- 调用
init(unfolding:) 构造器时,请使用带标签的参数,不要使用尾随闭包
|
| 🟢 |
Bool
static func random() -> Bool
static func random(using gen: inout RandomNumberGenerator) -> Bool
|
| ✅ |
CaseIterable |
| ✅ |
CGAffineTransform |
| ✅ |
CGFloat |
| ✅ |
CGPoint |
| ✅ |
CGRect |
| ✅ |
CGSize |
| 🟢 |
Character
init(_: Character)
init(_: String)
var isNewline: Bool
var isWhitespace: Bool
var isUppercase: Bool
var isLowercase: Bool
func lowercased() -> String
func uppercased() -> String
|
| 🟢 |
Codable
|
| 🟡 |
Collection
- 注意:此列表汇总了 Swift 多种集合类型所支持的 API,包括
Sequence、Collection、BidirectionalCollection 等
func allSatisfy(_ predicate: (Element) throws -> Bool) rethrows -> Bool
mutating func append(_ newElement: Element)
mutating func append(contentsOf newElements: any Sequence<Element>)
func contains(_ element: Element) -> Bool
func contains(where predicate: (Element) throws -> Bool) rethrows -> Bool
func distance(from start: Int, to end: Int) -> Int
func drop(while predicate: (Element) throws -> Bool) rethrows -> [Element]
func dropFirst(_ k: Int = 1) -> [Element]
func dropLast(_ k: Int = 1) -> [Element]
func elementsEqual(_ other: any Sequence<Element>) -> Bool
func elementsEqual(_ other: any Sequence<Element>, by areEquivalent: (Element, Element) throws -> Bool) rethrows -> Bool
func enumerated() -> any Sequence<(offset: Int, element: Element)>
var endIndex: Int
func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> [Element]
func first(where predicate: (Element) throws -> Bool) rethrows -> Element?
func firstIndex(of element: Element) -> Int?
func firstIndex(where predicate: (Element) throws -> Bool) rethrows -> Int?
var first: Element?
func flatMap<RE>(_ transform: (Element) throws -> any Sequence<RE>) rethrows -> [RE]
func formIndex(_ i: inout Int, offsetBy distance: Int)
func formIndex(after i: inout Int)
func index(_ i: Int, offsetBy distance: Int) -> Int
func index(after i: Int) -> Int
var indices: any Sequence<Int>
var isEmpty: Bool
func joined<RE>() -> [RE] where Element: Sequence<RE>
func joined<RE>(separator: any Sequence<RE>) -> [RE] where Element: Sequence<RE>
func joined(separator: String) -> String
func makeIterator() -> any IteratorProtocol<Element>
func map<RE>(_ transform: (Element) throws -> RE) rethrows -> [RE]
func max() -> Element?
func max(by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> Element?
func min() -> Element?
func min(by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> Element?
var underestimatedCount: Int
func prefix(_ maxLength: Int) -> [Element]
func prefix(through end: Int) -> [Element]
func prefix(upTo end: Int) -> [Element]
mutating func popFirst() -> Element?
mutating func popLast() -> Element?
func randomElement() -> Element?
func randomElement(using generator: inout any RandomNumberGenerator) -> Element?
func reduce<R>(_ initialResult: R, _ nextPartialResult: (_ partialResult: R, Element) throws -> R) rethrows -> R
func reduce<R>(into initialResult: R, _ updateAccumulatingResult: (_ partialResult: inout R, Element) throws -> Void) rethrows -> R
func remove(at i: Int) -> Element
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
mutating func removeAll(where shouldBeRemoved: (Element) throws -> Bool) rethrows
mutating func removeFirst() -> Element
mutating func removeFirst(_ k: Int)
mutating func removeLast() -> Element
mutating func removeLast(_ k: Int)
mutating func reverse()
func reversed() -> [Element]
mutating func shuffle()
mutating func shuffle<T: RandomNumberGenerator>(using generator: inout T)
mutating func sort()
mutating func sort(by areIncreasingOrder: (Element, Element) throws -> Bool) rethrows
mutating func swapAt(_ i: Int, _ j: Int)
subscript(bounds: Range<Int>) -> any Collection<Element>
subscript(position: Int) -> Element
func starts(with possiblePrefix: Any) -> Bool
func starts(with possiblePrefix: Any, by areEquivalent: (Element, Element) throws -> Bool) rethrows -> Bool
func suffix(from start: Int) -> [Element]
func suffix(_ maxLength: Int) -> [Element]
func sorted() -> [Element]
func sorted(by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> [Element]
var startIndex: Int
var count: Int
func count<E>(where: (E) throws -> Bool) rethrows -> Int
func withContiguousStorageIfAvailable<R>(_ body: (Any) throws -> R) rethrows -> R?
func forEach(_ body: (Element) throws -> Void) rethrows
func drop(while predicate: (Element) throws -> Bool) rethrows -> [Element]
func dropFirst(_ k: Int = 1) -> [Element]
func dropLast(_ k: Int = 1) -> [Element]
func enumerated() -> any Sequence<(offset: Int, element: Element)>
func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> [Element]
func first(where predicate: (Element) throws -> Bool) rethrows -> Element?
func map<RE>(_ transform: (Element) throws -> RE) rethrows -> [RE]
func max(by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> Element?
func min(by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> Element?
func reduce<R>(_ initialResult: R, _ nextPartialResult: (_ partialResult: R, Element) throws -> R) rethrows -> R
func reduce<R>(into initialResult: R, _ updateAccumulatingResult: (_ partialResult: inout R, Element) throws -> Void) rethrows -> R
func reversed() -> [Element]
func shuffled() -> [Element]
func shuffled<T: RandomNumberGenerator>(using generator: inout T) -> [Element]
func flatMap<RE>(_ transform: (Element) throws -> any Sequence<RE>) rethrows -> [RE]
func compactMap<RE>(_ transform: (Element) throws -> RE?) rethrows -> [RE]
func sorted(by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> [Element]
func joined<RE>() -> [RE] where Element: Sequence<RE>
func joined<RE>(separator: any Sequence<RE>) -> [RE] where Element: Sequence<RE>
func joined(separator: String) -> String
func starts(with possiblePrefix: Any) -> Bool
func contains(_ element: Element) -> Bool
func min() -> Element?
func max() -> Element?
func sorted() -> [Element]
var startIndex: Int
var endIndex: Int
var indices: any Sequence<Int>
func index(_ i: Int, offsetBy distance: Int) -> Int
func distance(from start: Int, to end: Int) -> Int
func index(after i: Int) -> Int
func formIndex(after i: inout Int)
func formIndex(_ i: inout Int, offsetBy distance: Int)
func randomElement() -> Element?
func randomElement(using generator: inout any RandomNumberGenerator) -> Element?
mutating func popFirst() -> Element?
var first: Element?
func prefix(upTo end: Int) -> [Element]
func suffix(from start: Int) -> [Element]
func prefix(through end: Int) -> [Element]
mutating func removeFirst() -> Element
mutating func removeFirst(_ k: Int)
func firstIndex(of element: Element) -> Int?
func firstIndex(where predicate: (Element) throws -> Bool) rethrows -> Int?
mutating func shuffle()
mutating func shuffle<T: RandomNumberGenerator>(using generator: inout T)
mutating func sort()
mutating func sort(by areIncreasingOrder: (Element, Element) throws -> Bool) rethrows
mutating func reverse()
mutating func swapAt(_ i: Int, _ j: Int)
mutating func append(_ newElement: Element)
mutating func append(contentsOf newElements: any Sequence<Element>)
mutating func insert(_ newElement: Element, at i: Int)
mutating func insert(contentsOf newElements: any Sequence<Element>, at i: Int)
mutating func remove(at i: Int) -> Element
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
mutating func removeAll(where shouldBeRemoved: (Element) throws -> Bool) rethrows
mutating func popLast() -> Element?
mutating func removeLast() -> Element
mutating func removeLast(_ k: Int)
subscript(bounds: Range<Int>) -> any Collection<Element>
subscript(position: Int) -> Element
|
| ✅ |
Comparable |
| ✅ |
CustomDebugStringConvertible |
| ✅ |
CustomStringConvertible |
| 🟢 |
Decodable
|
| 🟢 |
Dictionary
init()
init(minimumCapacity: Int)
init(uniqueKeysWithValues keysAndValues: any Sequence<(Key, Value)>)
func filter(_ isIncluded: ((Key, Value)) throws -> Bool) rethrows -> Dictionary<Key, Value>
subscript(key: Key) -> Value?
subscript(key: Key, default defaultValue: Value) -> Value
func mapValues<T>(_ transform: (Value) throws -> T) rethrows -> Dictionary<Key, T>
func compactMapValues<T>(_ transform: (Value) throws -> T?) rethrows -> Dictionary<Key, T>
mutating func updateValue(_ value: Value, forKey key: Key) -> Value?
mutating func removeValue(forKey key: Key) -> Value?
var keys: any Collection<Key>)
var values: any Collection<Value>
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
- 集合 API 的支持情况请参见
Collection
|
| ✅ |
DiscardingTaskGroup |
| 🟢 |
Double
static var nan: Double
static var infinity: Double
static var pi: Double
var isNan: Bool
var isFinite: Bool
var isInfinite: Bool
static func random(in range: Range<Double>) -> Double
func rounded() -> Double
func rounded(_ rule: FloatingPointRoundingRule) -> Double
|
| 🟢 |
Encodable
|
| ✅ |
Equatable |
| ✅ |
Error |
| ✅ |
fatalError |
| 🟢 |
Float
static var nan: Float
static var infinity: Float
static var pi: Float
var isNan: Bool
var isFinite: Bool
var isInfinite: Bool
static func random(in range: Range<Float>) -> Float
func rounded() -> Float
func rounded(_ rule: FloatingPointRoundingRule) -> Float
|
| ✅ |
Hashable |
| ✅ |
Hasher |
| ✅ |
Identifiable |
| 🟢 |
Int8
static var min: Int8
static var max: Int8
static func random(in range: Range<Int8>) -> Int8
static func random(in range: Range<Int8>, using gen: inout RandomNumberGenerator) -> Int8
|
| 🟢 |
Int16
static var min: Int16
static var max: Int16
static func random(in range: Range<Int16>) -> Int16
static func random(in range: Range<Int16>, using gen: inout RandomNumberGenerator) -> Int16
|
| 🟢 |
Int32
static var min: Int32
static var max: Int32
static func random(in range: Range<Int32>) -> Int32
static func random(in range: Range<Int32>, using gen: inout RandomNumberGenerator) -> Int32
|
| 🟢 |
Int
- Kotlin 的
Int 为 32 位
static var min: Int
static var max: Int
static func random(in range: Range<Int>) -> Int
static func random(in range: Range<Int>, using gen: inout RandomNumberGenerator) -> Int
|
| 🟢 |
Int64
static var min: Int64
static var max: Int64
static func random(in range: Range<Int64>) -> Int64
static func random(in range: Range<Int64>, using gen: inout RandomNumberGenerator) -> Int64
|
| 🟢 |
@MainActor |
| 🟢 |
MainActor
static func run<T>(body: () throws -> T) async -> T
|
| 🟢 |
math.h
var M_E: Double
var M_LOG2E: Double
var M_LOG10E: Double
var M_LN2: Double
var M_LN10: Double
var M_PI: Double
func acosf(_ x: Float) -> Float
func acos(_ x: Double) -> Double
func acosl(_ x: Double) -> Double
func asinf(_ x: Float) -> Float
func asin(_ x: Double) -> Double
func asinl(_ x: Double) -> Double
func atanf(_ x: Float) -> Float
func atan(_ x: Double) -> Double
func atanl(_ x: Double) -> Double
func atan2f(_ x: Float, _ y: Float) -> Float
func atan2(_ x: Double, _ y: Double) -> Double
func atan2l(_ x: Double, _ y: Double) -> Double
func cosf(_ x: Float) -> Float
func cos(_ x: Double) -> Double
func cosl(_ x: Double) -> Double
func sinf(_ x: Float) -> Float
func sin(_ x: Double) -> Double
func sinl(_ x: Double) -> Double
func tanf(_ x: Float) -> Float
func tan(_ x: Double) -> Double
func tanl(_ x: Double) -> Double
func acoshf(_ x: Float) -> Float
func acosh(_ x: Double) -> Double
func acoshl(_ x: Double) -> Double
func asinhf(_ x: Float) -> Float
func asinh(_ x: Double) -> Double
func asinhl(_ x: Double) -> Double
func atanhf(_ x: Float) -> Float
func atanh(_ x: Double) -> Double
func atanhl(_ x: Double) -> Double
func coshf(_ x: Float) -> Float
func cosh(_ x: Double) -> Double
func coshl(_ x: Double) -> Double
func sinhf(_ x: Float) -> Float
func sinh(_ x: Double) -> Double
func sinhl(_ x: Double) -> Double
func tanhf(_ x: Float) -> Float
func tanh(_ x: Double) -> Double
func tanhl(_ x: Double) -> Double
func expf(_ x: Float) -> Float
func exp(_ x: Double) -> Double
func expl(_ x: Double) -> Double
func exp2f(_ x: Float) -> Float
func exp2(_ x: Double) -> Double
func exp2l(_ x: Double) -> Double
func expm1f(_ x: Float) -> Float
func expm1(_ x: Double) -> Double
func expm1l(_ x: Double) -> Double
func logf(_ x: Float) -> Float
func log(_ x: Double) -> Double
func logl(_ x: Double) -> Double
func log10f(_ x: Float) -> Float
func log10(_ x: Double) -> Double
func log10l(_ x: Double) -> Double
func log2f(_ x: Float) -> Float
func log2(_ x: Double) -> Double
func log2l(_ x: Double) -> Double
func log1pf(_ x: Float) -> Float
func log1p(_ x: Double) -> Double
func log1pl(_ x: Double) -> Double
func logbf(_ x: Float) -> Float
func logb(_ x: Double) -> Double
func logbl(_ x: Double) -> Double
func abs(_ x: Double) -> Double
func abs(_ x: Int) -> Int
func abs(_ x: Int64) -> Int64
func fabsf(_ x: Float) -> Float
func fabs(_ x: Double) -> Double
func fabsl(_ x: Double) -> Double
func cbrtf(_ x: Float) -> Float
func cbrt(_ x: Double) -> Double
func cbrtl(_ x: Double) -> Double
func hypotf(_ x: Float, _ y: Float) -> Float
func hypot(_ x: Double, _ y: Double) -> Double
func hypotl(_ x: Double, _ y: Double) -> Double
func powf(_ x: Float, _ y: Float) -> Float
func pow(_ x: Double, _ y: Double) -> Double
func powl(_ x: Double, _ y: Double) -> Double
func sqrtf(_ x: Float) -> Float
func sqrt(_ x: Double) -> Double
func sqrtl(_ x: Double) -> Double
func ceilf(_ x: Float) -> Float
func ceil(_ x: Double) -> Double
func ceill(_ x: Double) -> Double
func floorf(_ x: Float) -> Float
func floor(_ x: Double) -> Double
func floorl(_ x: Double) -> Double
func roundf(_ x: Float) -> Float
func round(_ x: Double) -> Double
func roundl(_ x: Double) -> Double
func fmodf(_ x: Float, _ y: Float) -> Float
func fmod(_ x: Double, _ y: Double) -> Double
func fmodl(_ x: Double, _ y: Double) -> Double
func remainderf(_ x: Float, _ y: Float) -> Float
func remainder(_ x: Double, _ y: Double) -> Double
func remainderl(_ x: Double, _ y: Double) -> Double
func fmaxf(_ x: Float, _ y: Float) -> Float
func fmax(_ x: Double, _ y: Double) -> Double
func fmaxl(_ x: Double, _ y: Double) -> Double
func fminf(_ x: Float, _ y: Float) -> Float
func fmin(_ x: Double, _ y: Double) -> Double
func fminl(_ x: Double, _ y: Double) -> Double
|
| ✅ |
max(_:_:) |
| ✅ |
min(_:_:) |
| ✅ |
ObjectIdentifier |
| ✅ |
OptionSet |
| ✅ |
precondition |
| ✅ |
preconditionFailure |
| ✅ |
RandomNumberGenerator |
| 🟠 |
Range
- 通常只支持
Range<Int>
var lowerBound: Bound
var upperBound: Bound
func contains(_ element: Bound) -> Bool
var isEmpty: Bool
func map<RE>(_ transform: (Bound) throws -> RE) rethrows -> [RE]
|
| ✅ |
RawRepresentable |
| 🟠 |
Regex
init(_ string: String)
func matches(_ string: String) -> [Match]
func replace(_ string: String, with replacement: String) -> String
|
| 🟠 |
Regex.Match
var count: Int
subscript(index: Int) -> MatchGroup
|
| 🟠 |
Regex.MatchGroup
var substring: Substring?
|
| ✅ |
Result |
| 🟡 |
swap(_:_:)
|
| 🟢 |
Set
init()
init(_ sequence: any Sequence<Element>)
- 参见
Collection
- 参见
SetAlgebra
|
| 🟢 |
SetAlgebra
func contains(_ element: Element) -> Bool
func union(_ other: Self) -> Self
func intersection(_ other: Self) -> Self
func symmetricDifference(_ other: Self) -> Self
mutating func insert(_ newMember: Element) -> (inserted: Bool, memberAfterInsert: Element)
mutating func remove(_ member: Element) -> Element?
mutating func update(with newMember: Element) -> Element?
mutating func formUnion(_ other: Self)
mutating func formIntersection(_ other: Self)
mutating func formSymmetricDifference(_ other: Self)
func subtracting(_ other: Self) -> Self
func isSubset(of other: Self) -> Bool
func isDisjoint(with other: Self) -> Bool
func isSuperset(of other: Self) -> Bool
var isEmpty: Bool
mutating func subtract(_ other: Self)
func isStrictSubset(of other: Self) -> Bool
func isStrictSuperset(of other: Self) -> Bool
|
| 🟢 |
String
- Kotlin 字符串**不可变**
init(data: Data, encoding: StringEncoding)
init(bytes: [UInt8], encoding: StringEncoding)
init(contentsOf: URL)
var capitalized: String
var deletingLastPathComponent: String
func replacingOccurrences(of search: String, with replacement: String) -> String
func components(separatedBy separator: String) -> [String]
func trimmingCharacters(in set: CharacterSet) -> String
var utf8Data: Data
func data(using: StringEncoding, allowLossyConversion: Bool = true) -> Data?
var utf8: [UInt8]
var utf16: [UInt8]
var unicodeScalars: [UInt8]
- 参见
Collection
- 由
Foundation 提供的其他字符串 API,请参见 SkipFoundation
|
| ✅ |
strlen |
| ✅ |
strncmp |
| 🟢 |
Substring
|
| ✅ |
SystemRandomNumberGenerator |
| 🟡 |
Task
init(priority: TaskPriority? = nil, operation: @escaping () async throws -> Success)
static func detached(priority: TaskPriority? = nil, operation: @escaping () async -> Success) -> Task<Success, Failure>
var value: Success
func cancel()
static func yield() async
var isCancelled: Bool
static var isCancelled: Bool
static func checkCancellation() throws
static func sleep(nanoseconds duration: UInt64) async throws
static var min: UInt8
|
| ✅ |
TaskGroup |
| ✅ |
ThrowingDiscardingTaskGroup |
| ✅ |
ThrowingTaskGroup |
| ✅ |
type(of:) |
| 🟢 |
UInt8
static var min: UInt8
static var max: UInt8
static func random(in range: Range<UInt8>) -> UInt8
static func random(in range: Range<UInt8>, using gen: inout RandomNumberGenerator) -> UInt8
|
| 🟢 |
UInt16
static var min: UInt16
static var max: UInt16
static func random(in range: Range<UInt16>) -> UInt16
static func random(in range: Range<UInt16>, using gen: inout RandomNumberGenerator) -> UInt16
|
| 🟢 |
UInt32
static var min: UInt32
static var max: UInt32
static func random(in range: Range<UInt32>) -> UInt32
static func random(in range: Range<UInt32>, using gen: inout RandomNumberGenerator) -> UInt32
|
| 🟢 |
UInt
- Kotlin 的
UInt 为 32 位
static var min: UInt
static var max: UInt
static func random(in range: Range<UInt>) -> UInt
static func random(in range: Range<UInt>, using gen: inout RandomNumberGenerator) -> UInt
|
| 🟢 |
UInt64
static var min: UInt64
static var max: UInt64
static func random(in range: Range<UInt64>) -> UInt64
static func random(in range: Range<UInt64>, using gen: inout RandomNumberGenerator) -> UInt64
|
| ✅ |
withDiscardingTaskGroup |
| ✅ |
withTaskCancellationHandler |
| ✅ |
withThrowingTaskGroup |
| ✅ |
withThrowingDiscardingTaskGroup |
| ✅ |
withThrowingTaskGroup |