Swift开源了,有什么好处?

移动开发
学习swift的时候,遇到问题,或者有一些想法的时候,你可以打开swift的源码参考一番,我相信会有很大的收获。

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

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

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

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

学习swift的时候,遇到问题,或者有一些想法的时候,你可以打开swift的源码参考一番,我相信会有很大的收获。

举个例子,我们来看看swift中的Bool类型的定义和实现,是不是对你自定义一个类型的时候很有帮助呢?

  1. public struct Bool { 
  2.   internal var _value: Builtin.Int1 
  3.  
  4.   /// Default-initialize Boolean value to `false`. 
  5.   @_transparent 
  6.   public init() { 
  7.     let zero: Int8 = 0 
  8.     self._value = Builtin.trunc_Int8_Int1(zero._value) 
  9.   } 
  10.  
  11.   @_transparent 
  12.   internal init(_ v: Builtin.Int1) { self._value = v } 
  13.  
  14. extension Bool : _BuiltinBooleanLiteralConvertible, BooleanLiteralConvertible { 
  15.   @_transparent 
  16.   public init(_builtinBooleanLiteral value: Builtin.Int1) { 
  17.     self._value = value 
  18.   } 
  19.  
  20.   /// Create an instance initialized to `value`. 
  21.   @_transparent 
  22.   public init(booleanLiteral value: Bool) { 
  23.     self = value 
  24.   } 
  25.  
  26. extension Bool : BooleanType { 
  27.   @_transparent 
  28.   @warn_unused_result 
  29.   public func _getBuiltinLogicValue() -> Builtin.Int1 { 
  30.     return _value 
  31.   } 
  32.  
  33.   /// Identical to `self`. 
  34.   @_transparent public var boolValue: Bool { return self } 
  35.  
  36.   /// Construct an instance representing the same logical value as 
  37.   /// `value`. 
  38.   public init<T : BooleanType>(_ value: T) { 
  39.     self = value.boolValue 
  40.   } 
  41.  
  42. extension Bool : CustomStringConvertible { 
  43.   /// A textual representation of `self`. 
  44.   public var description: String { 
  45.     return self ? "true" : "false" 
  46.   } 
  47.  
  48. // This is a magic entrypoint known to the compiler. 
  49. @_transparent 
  50. public // COMPILER_INTRINSIC 
  51. func _getBool(v: Builtin.Int1) -> Bool { return Bool(v) } 
  52.  
  53. @_transparent 
  54. extension Bool : Equatable, Hashable { 
  55.   /// The hash value. 
  56.   /// 
  57.   /// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`. 
  58.   /// 
  59.   /// - Note: the hash value is not guaranteed to be stable across 
  60.   ///   different invocations of the same program.  Do not persist the 
  61.   ///   hash value across program runs. 
  62.   public var hashValue: Int { 
  63.     return self ? 1 : 0 
  64.   } 
  65.  
  66. //===----------------------------------------------------------------------===// 
  67. // Operators 
  68. //===----------------------------------------------------------------------===// 
  69.  
  70. // Unary logical complement. 
  71. @_transparent 
  72. @warn_unused_result 
  73. public prefix func !(a: Bool) -> Bool { 
  74.   return Bool(Builtin.xor_Int1(a._value, true._value)) 
  75.  
  76. @_transparent 
  77. @warn_unused_result 
  78. public func ==(lhs: Bool, rhs: Bool) -> Bool { 
  79.   return Bool(Builtin.cmp_eq_Int1(lhs._value, rhs._value)) 

2.swift会变得更加的完善

swift开源不到一天的时间,swift项目在github收到了13087个star,1351个fork。并且还在快速增长中......

这表示了众多开发者对swift这个语言的关注和热情十分的高涨,并且全球的开发者都会为swift贡献自己的代码和力量。大家看下图体验一下:

swift在github上的数据.png

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。

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

责任编辑:倪明 来源: 简书
相关推荐

2013-03-19 09:40:44

CookiesCookies跟踪个人隐私

2013-09-23 14:54:54

编程语言开发

2020-09-11 09:42:28

云安全云计算

2020-04-21 22:25:43

智能垃圾物联网IOT

2021-11-10 23:31:21

混合云云计算数据

2021-03-04 11:01:43

服务器虚拟化IT

2022-08-08 14:18:34

物联网铝行业工业 4.0

2021-08-26 16:06:35

物联网网关路由器物联网

2022-07-27 11:21:27

服务器IT 基础架构

2013-07-24 09:36:03

产品上线产品着陆页

2023-12-25 09:47:40

区块链运输业供应链管理

2010-11-23 09:29:49

Lync微软

2018-05-04 14:11:34

SwiftPython开发

2021-02-19 23:55:15

PythonPythonic数据

2018-08-27 06:58:06

无线路由器WiFi网络

2015-07-01 13:50:29

Swift开源思考

2010-01-05 14:33:09

.NET Framew

2017-02-06 17:00:09

TensorFlowHadoop开源

2017-02-07 09:30:49

TensorFlowHadoop开源

2022-06-07 08:39:35

RPCHTTP
点赞
收藏

51CTO技术栈公众号