Swift开源了,有什么好处?

昨天swift开源了,喜大泪奔的好消息!

swift的官方网站https://swift.org
swift在github的开源地址https://github.com/apple/swift

今天早上J君问我,swift开源了有什么好处呢?
我想从以下的几个方面来回答他:

1.学习swift更加方便和简单了

学习swift的时候,遇到问题,或者有一些想法的时候,你可以打开swift的源码参考一番,我相信会有很大的收获。
举个例子,我们来看看swift中的Bool类型的定义和实现,是不是对你自定义一个类型的时候很有帮助呢?

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.

苹果公司是支持大家把swift移植到别的平台去的,日后必定有有能力的开发者,在别的新的平台上使用swift。

水平有限,只是发表一下自己浅薄看法。如果你有不同想法,欢迎在下方评论来讨论,谢谢!

posted @ 2015-12-04 15:10  求真求道  阅读(3698)  评论(2编辑  收藏  举报