參考文檔:[譯] 官方 Swift API 設計規範ios
extension List {
public mutating func remove(at position: Index) -> Element
public mutating func remove(_ member: Element) -> Element?
}
複製代碼
func add(_ observer: NSObject, for keyPath: String)
func addObserver(_ observer: NSObject, forKeyPath path: String)
複製代碼
x.subViews(havingColor: y)
x.subViews(color: y)
複製代碼
let foreground = Color(red: 32, green: 64, blue: 128)
let foreground = Color(havingRGBValuesRed: 32, green: 64, andBlue: 128)
複製代碼
x.sort()
x.sorted()
複製代碼
Protocol
有什麼命名規則?extension Shape {
/// Returns `true` iff `other` is within the area of `self`.
func contains(_ other: Point) -> Bool { ... }
/// Returns `true` iff `other` is entirely within the area of `self`.
func contains(_ other: Shape) -> Bool { ... }
}
複製代碼
extension Box {
/// Returns the `Int` stored in `self`, if any, and
/// `nil` otherwise.
func value() -> Int? { ... }
/// Returns the `String` stored in `self`, if any, and
/// `nil` otherwise.
func value() -> String? { ... }
}
複製代碼
func filter(_ predicate: (Element) -> Bool) -> [Generator.Element]
func filter(_ includedInResult: (Element) -> Bool) -> [Generator.Element]
複製代碼
extension String {
/// ...description...
public func compare(_ options: CompareOptions = [], other: String, range: Range? = nil, locale: Locale? = nil ) -> Ordering
}
複製代碼
min(number1, number2)
zip(sequence1, sequence2)
複製代碼
extension UInt32 {
/// Creates an instance having the specified value.
init(_ value: Int16)
/// Creates an instance having the lowest 32 bits of source.
init(truncating source: UInt64)
}
複製代碼
// a 移動到某個點上
a.move(toX: b, y: c)
a.moveTo(x: b, y: c)
複製代碼
extension UIView {
func addSubview(_ view: UIView)
func add(subview: UIView)
}
複製代碼
struct Array {
/// Inserts `newElement` at `self.endIndex`.
public mutating func append(_ newElement: Element)
/// Inserts the contents of `newElements`, in order, at
/// `self.endIndex`.
public mutating func append(_ newElements: S)
where S.Generator.Element == Element
}
複製代碼
struct Model {
var sourceURL: URL
var sourceUrl: URL
}
複製代碼