Swift開源了,有什麼好處?

昨天swift開源了,喜大淚奔的好消息!git

swift的官方網站https://swift.org
swift在github的開源地址https://github.com/apple/swiftgithub

今天早上J君問我,swift開源了有什麼好處呢?
我想從如下的幾個方面來回答他:swift

1.學習swift更加方便和簡單了

學習swift的時候,遇到問題,或者有一些想法的時候,你能夠打開swift的源碼參考一番,我相信會有很大的收穫。
舉個例子,咱們來看看swift中的Bool類型的定義和實現,是否是對你自定義一個類型的時候頗有幫助呢?app

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。而且還在快速增加中......
這表示了衆多開發者對swift這個語言的關注和熱情十分的高漲,而且全球的開發者都會爲swift貢獻本身的代碼和力量。你們看下圖體驗一下:學習

swift在github上的數據

3.swift更增強大,更加普遍的應用

目前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.ui

蘋果公司是支持你們把swift移植到別的平臺去的,往後一定有有能力的開發者,在別的新的平臺上使用swift。this

水平有限,只是發表一下本身淺薄見解。若是你有不一樣想法,歡迎在下方評論來討論,謝謝!spa

相關文章
相關標籤/搜索