Swift開源了,有什么好處?
swift開源了,喜大淚奔的好消息!
swift的官方網(wǎng)站https://swift.org
swift在github的開源地址https://github.com/apple/swift
今天早上J君問我,swift開源了有什么好處呢?
我想從以下的幾個方面來回答他:
1.學(xué)習(xí)swift更加方便和簡單了
學(xué)習(xí)swift的時候,遇到問題,或者有一些想法的時候,你可以打開swift的源碼參考一番,我相信會有很大的收獲。
舉個例子,我們來看看swift中的Bool類型的定義和實現(xiàn),是不是對你自定義一個類型的時候很有幫助呢?
- public struct Bool {
- internal var _value: Builtin.Int1
- /// Default-initialize Boolean value to `false`.
- @_transparent
- public init() {
- let zero: Int8 = 0
- self._value = Builtin.trunc_Int8_Int1(zero._value)
- }
- @_transparent
- internal init(_ v: Builtin.Int1) { self._value = v }
- }
- extension Bool : _BuiltinBooleanLiteralConvertible, BooleanLiteralConvertible {
- @_transparent
- public init(_builtinBooleanLiteral value: Builtin.Int1) {
- self._value = value
- }
- /// Create an instance initialized to `value`.
- @_transparent
- public init(booleanLiteral value: Bool) {
- self = value
- }
- }
- extension Bool : BooleanType {
- @_transparent
- @warn_unused_result
- public func _getBuiltinLogicValue() -> Builtin.Int1 {
- return _value
- }
- /// Identical to `self`.
- @_transparent public var boolValue: Bool { return self }
- /// Construct an instance representing the same logical value as
- /// `value`.
- public init<T : BooleanType>(_ value: T) {
- self = value.boolValue
- }
- }
- extension Bool : CustomStringConvertible {
- /// A textual representation of `self`.
- public var description: String {
- return self ? "true" : "false"
- }
- }
- // This is a magic entrypoint known to the compiler.
- @_transparent
- public // COMPILER_INTRINSIC
- func _getBool(v: Builtin.Int1) -> Bool { return Bool(v) }
- @_transparent
- extension Bool : Equatable, Hashable {
- /// The hash value.
- ///
- /// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`.
- ///
- /// - Note: the hash value is not guaranteed to be stable across
- /// different invocations of the same program. Do not persist the
- /// hash value across program runs.
- public var hashValue: Int {
- return self ? 1 : 0
- }
- }
- //===----------------------------------------------------------------------===//
- // Operators
- //===----------------------------------------------------------------------===//
- // Unary logical complement.
- @_transparent
- @warn_unused_result
- public prefix func !(a: Bool) -> Bool {
- return Bool(Builtin.xor_Int1(a._value, true._value))
- }
- @_transparent
- @warn_unused_result
- public func ==(lhs: Bool, rhs: Bool) -> Bool {
- return Bool(Builtin.cmp_eq_Int1(lhs._value, rhs._value))
- }
2.swift會變得更加的完善
swift開源不到一天的時間,swift項目在github收到了13087個star,1351個fork。并且還在快速增長中......
這表示了眾多開發(fā)者對swift這個語言的關(guān)注和熱情十分的高漲,并且全球的開發(fā)者都會為swift貢獻自己的代碼和力量。大家看下圖體驗一下:
swift在github上的數(shù)據(jù).png
3.swift更加強大,更加廣泛的應(yīng)用
目前swift支持的平臺,除了自家的iOS, OS X, watchOS, 和 tvOS.還支持了Linux平臺。
New Platforms
We can’t wait to see the new places we can bring Swift—together. We truly believe that this language that we love can make software safer, faster, and easier to maintain. We’d love your help to bring Swift to even more computing platforms.
蘋果公司是支持大家把swift移植到別的平臺去的,日后必定有有能力的開發(fā)者,在別的新的平臺上使用swift。
水平有限,只是發(fā)表一下自己淺薄看法。如果你有不同想法,歡迎在下方評論來討論,謝謝!