• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Swift开源了,有什么好处?

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

昨天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贡献自己的代码和力量。大家看下图体验一下:

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。

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
swift导入.a和.h文件发布时间:2022-07-18
下一篇:
iosswift判断uiviewcontroller时pushpresent进来的还是pop进来的发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap