Swift開(kāi)源了,有什么好處?
swift開(kāi)源了,喜大淚奔的好消息!
swift的官方網(wǎng)站https://swift.org
swift在github的開(kāi)源地址https://github.com/apple/swift
今天早上J君問(wèn)我,swift開(kāi)源了有什么好處呢?
我想從以下的幾個(gè)方面來(lái)回答他:
1.學(xué)習(xí)swift更加方便和簡(jiǎn)單了
學(xué)習(xí)swift的時(shí)候,遇到問(wèn)題,或者有一些想法的時(shí)候,你可以打開(kāi)swift的源碼參考一番,我相信會(huì)有很大的收獲。
舉個(gè)例子,我們來(lái)看看swift中的Bool類(lèi)型的定義和實(shí)現(xiàn),是不是對(duì)你自定義一個(gè)類(lèi)型的時(shí)候很有幫助呢?
- 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會(huì)變得更加的完善
swift開(kāi)源不到一天的時(shí)間,swift項(xiàng)目在github收到了13087個(gè)star,1351個(gè)fork。并且還在快速增長(zhǎng)中......
這表示了眾多開(kāi)發(fā)者對(duì)swift這個(gè)語(yǔ)言的關(guān)注和熱情十分的高漲,并且全球的開(kāi)發(fā)者都會(huì)為swift貢獻(xiàn)自己的代碼和力量。大家看下圖體驗(yàn)一下:
swift在github上的數(shù)據(jù).png
3.swift更加強(qiáng)大,更加廣泛的應(yīng)用
目前swift支持的平臺(tái),除了自家的iOS, OS X, watchOS, 和 tvOS.還支持了Linux平臺(tái)。
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.
蘋(píng)果公司是支持大家把swift移植到別的平臺(tái)去的,日后必定有有能力的開(kāi)發(fā)者,在別的新的平臺(tái)上使用swift。
水平有限,只是發(fā)表一下自己淺薄看法。如果你有不同想法,歡迎在下方評(píng)論來(lái)討論,謝謝!