Swift v3.0-PREVIEW-1 发布

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
查看查看713 回复回复1 收藏收藏 分享淘帖 转播转播 分享分享 微信
查看: 713|回复: 1
收起左侧

Swift v3.0-PREVIEW-1 发布

[复制链接]
cocoaswift 发表于 2016-6-21 23:28:58 | 显示全部楼层 |阅读模式
快来登录
获取优质的苹果资讯内容
收藏热门的iOS等技术干货
拷贝下载Swift Demo源代码
订阅梳理好了的知识点专辑
Swift,一种强大的开源编程语言,让大家都能开发出众的 App。

Swift v3.0-PREVIEW-1 发布

Swift v3.0-PREVIEW-1 发布 - 敏捷大拇指 - Swift v3.0-PREVIEW-1 发布


Swift是一款为iOS和OS X 应用打造的新式编程语言,它吸取了C语言和Objective-C语言的精华,同时完美兼容C语言。Swift采用了安全编程模式,增加了许多现代语言的特性,使编程工作更加简单,灵活,有趣。一款重新设计的语言,再加上成熟并且深受欢迎的Cocoa框架和Cocoa Touch框架,Swift为软件开发工作带来了无限遐想。




1、特点

  • 从它的语法中能看到Java Objective-C JavaScript C# Python等语言的影子
  • 语法简单、代码简洁、使用方便
  • 可与Objective-C混合使用(相互调用)
  • 提供了类似 Java 的名字空间(namespace)、泛型(generic)、运算对象重载(operator overloading)
  • 让应用开发更简单、更快、更稳定
  • 确保最终应用有着更好的质量





2、更新日志

  • SE-0093: Slice types now have a base property that allows public readonly access to their base collections.


  • Nested generic functions may now capture bindings from the environment, for example:


[Swift] 纯文本查看 复制代码
func outer<T>(t: T) -> T {
  func inner<U>(u: U) -> (T, U) {
    return (t, u)
  }
  return inner(u: (t, t)).0
}


  • Initializers are now inherited even if the base class or derived class is generic:


[Swift] 纯文本查看 复制代码
class Base<T> {
  let t: T

  init(t: T) {
    self.t = t
  }
}

class Derived<T> : Base<T> {
  // init(t: T) is now synthesized to call super.init(t: t)
}


  • SE-0081 "Move 'where' clause to end of declaration" is implemented, allowing you to write 'where' clauses after the signature for a declaration, but before its body. For example, before:


[Swift] 纯文本查看 复制代码
  func anyCommonElements<T : SequenceType, U : SequenceType 
                         where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element>
      (lhs: T, _ rhs: U) -> Bool
  {
      ...
  }


after:

[Swift] 纯文本查看 复制代码
  func anyCommonElements<T : SequenceType, U : SequenceType>(lhs: T, _ rhs: U) -> Bool
      where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element
  {
      ...
  }


The old form is still accepted for compatibility, but will eventually be rejected.

  • SE-0071: "Allow (most) keywords in member references" is implemented. This allows the use of members after a dot without backticks, e.g. "foo.default".


SE-0057: Objective-C lightweight generic classes are now imported as generic types in Swift. Because Objective-C generics are not represented at runtime, there are some limitations on what can be done with them in Swift:

1.

If an ObjC generic class is used in a checked as?, as!, or is cast, the generic parameters are not checked at runtime. The cast succeeds if the operand is an instance of the ObjC class, regardless of parameters.

[Swift] 纯文本查看 复制代码
let x = NSFoo<NSNumber>(value: NSNumber(integer: 0))
let y: AnyObject = x
let z = y as! NSFoo<NSString> // Succeeds


2.

Swift subclasses can only inherit an ObjC generic class if its generic parameters are fully specified.

[Swift] 纯文本查看 复制代码
// Error: Can't inherit ObjC generic class with unbound parameter T
class SwiftFoo1<T>: NSFoo<T> { }

// OK: Can inherit ObjC generic class with specific parameters
class SwiftFoo2<T>: NSFoo<NSString> { }


3.

Swift can extend ObjC generic classes, but the extensions cannot be constrained, and definitions inside the extension do not have access to the class's generic parameters.

[Swift] 纯文本查看 复制代码
extension NSFoo {
  // Error: Can't access generic param T
  func foo() -> T {
    return T()
  }
}

// Error: extension can't be constrained
extension NSFoo where T: NSString {
}


4.

Foundation container classes NS[Mutable]Array, NS[Mutable]Set, and NS[Mutable]Dictionary are still imported as nongeneric classes for the time being.


  • As part of the changes for SE-0055 (see below), the pointee types of imported pointers (e.g. the id in id *) are no longer assumed to always be _Nullable even if annotated otherwise. However, an implicit or explicit annotation of_Null_unspecified on a pointee type is still imported as Optional.


SE-0055: The types UnsafePointer, UnsafeMutablePointer, AutoreleasingUnsafeMutablePointer, OpaquePointer,Selector, and Zone (formerly NSZone) now represent non-nullable pointers, i.e. pointers that are never nil. A nullable pointer is now represented using Optional, e.g. UnsafePointer<Int>? For types imported from C, non-object pointers (such as int *) now have their nullability taken into account.

One possible area of difficulty is passing a nullable pointer to a function that uses C variadics. Swift will not permit this directly, so as a workaround please use the following idiom to pass it as a pointer-sized integer value instead:

[Swift] 纯文本查看 复制代码
unsafeBitCast(nullablePointer, to: Int.self)


SE-0046 Function parameters now have consistent labelling across all function parameters. With this update the first parameter declarations will now match the existing behavior of the second and later parameters. This change makes the language simpler.

Functions that were written and called as follows

[Swift] 纯文本查看 复制代码
  func foo(x: Int, y: Int) {
  }
  foo(1, y: 2)

  func bar(a a: Int, b: Int) {
  }
  bar(a: 3, b: 4)


will now be written as (to achieve the same behavior):

[Swift] 纯文本查看 复制代码
    func foo(_ x: Int, y: Int) {}
    foo(1, y: 2)
    func bar(a: Int, b: Int) {}
    bar(a: 3, b: 4)


  • SE-0037 Comments are now treated as whitespace when determining whether an operator is prefix, postfix, or binary. For example, these now work:

[Swift] 纯文本查看 复制代码
  if /*comment*/!foo { ... }
  1 +/*comment*/2


This also means that comments can no longer appear between a unary operator and its argument.

[Swift] 纯文本查看 复制代码
  foo/* comment */! // no longer works


Any parse errors resulting from this change can be resolved by moving the comment outside of the expression.

  • SE-0031 The location of the inout attribute has been moved to after the : and before the parameter type.


[Swift] 纯文本查看 复制代码
  func foo(inout x: Int) {
  }


will now be written as:

[Swift] 纯文本查看 复制代码
  func foo(x: inout Int) {
  }


  • SE-0053 let is no longer accepted as a parameter attribute for functions. The compiler provides a fixit to remove it from the function declaration.


  • SE-0003 var is no longer accepted as a parameter attribute for functions. The compiler provides a fixit to create a shadow copy in the function body.


[Swift] 纯文本查看 复制代码
  func foo(var x: Int) {
  }


will now be written as:

[Swift] 纯文本查看 复制代码
  func foo(x: Int) {
    var x = x
  }


  • The "none" members of imported NS_OPTIONS option sets are marked as unavailable when they are imported. Use [] to make an empty option set, instead of a None member.


  • SE-0043 landed, adding the ability to declare variables in multiple patterns in cases.


  • Renamification landed, so the Clang importer imports ObjC symbols substantially differently. Someone should expand on this point.


  • SE-0040 landed, changing attributes from using = in parameters lists to using :, aligning with function call syntax.


  • Generic typealiases are now supported, e.g.:


[Swift] 纯文本查看 复制代码
    typealias StringDictionary<T> = Dictionary<String, T>
    typealias IntFunction<T> = (T) -> Int
    typealias MatchingTriple<T> = (T, T, T)
    typealias BackwardTriple<T1, T2, T3> = (T3, T2, T1)


etc.
  • The @noescape attribute has been extended to be a more general type attribute. You can now declare values of@noescape function type, e.g. in manually curried function signatures. You can now also declare local variables of@noescape type, and use @noescape in typealiases. For example, this is now valid code:


[Swift] 纯文本查看 复制代码
    func apply<T, U>(@noescape f: T -> U,
                     @noescape g: (@noescape T -> U) -> U) -> U {
      return g(f)
    }


  • SE-0034 has renamed the #line directive (which resets the logical source location for diagnostics and debug information) to #sourceLocation.


  • Curried function syntax has been removed, and now produces a compile-time error.


  • Generic signatures can now contain superclass requirements with generic parameter types, for example:


[Swift] 纯文本查看 复制代码
func f<Food : Chunks<Meat>, Meat : Molerat>(f: Food, m: Meat) {}


  • Section markers are created in ELF binaries through special objects during link time. These objects allow for the deletion of swift.ld and the use of non-BFD linkers. A new argument to swiftc is provided to select the linker used, and the gold linker is set as the default for arm-based platforms.


  • Catch blocks in rethrows functions may now throw errors. For example:


[Swift] 纯文本查看 复制代码
func process(f: () throws -> Int) rethrows -> Int {
    do {
        return try f()
    } catch is SomeError {
        throw OtherError()
    }
}


  • Throwing closure arguments of a rethrowing function may now be optional. For example:


[Swift] 纯文本查看 复制代码
func executeClosureIfNotNil(closure: (() throws -> Void)?) rethrows {
    try closure?()
}


  • SE-0064 The Objective-C selectors for the getter or setter of a property can now be referenced with #selector. For example:


[Swift] 纯文本查看 复制代码
let sel1 = #selector(getter: UIView.backgroundColor) // sel1 has type Selector
let sel2 = #selector(setter: UIView.backgroundColor) // sel2 has type Selector


  • SE-0062: A key-path can now be formed with #keyPath. For example:


[Swift] 纯文本查看 复制代码
person.valueForKeyPath(#keyPath(Person.bestFriend.lastName))





3、下载






Swift 3.0 相关内容:

宣告Swift3结束和Swift4开启

Swift 3中的新特性 What's New in Swift 3 ?

包括了Swift 3的Xcode 8新特性 new features in Xcode 8

Swift 3.0 都改变了什么语法?

是时候适配 Swift 3 了吗——专访 LINE iOS 开发工程师王巍

Swift 3 API 设计准则 Swift 3 API Design Guidelines

Swift 3.0 API设计准则 详细内容解读 Swift 3.0 API Design Guidelines

Swift 3.0 Preview 1 Released! Swift 3.0开发者预览版(第一版)发布

苹果开发者大会纪要,Swift 3.0:print("WWDC@2016 by swifthumb.com");

苹果发布Swift 3.0首个预览版:核心代码又有改进哦!Swift进军路线图

Swift v3.0-PREVIEW-1 发布

Swift 3.0预告:将Objc库转换成更符合Swift语法风格的形式

Swift 3.0预测:扩展性更强、类型系统重构、完善泛型

我们期待的 Swift 3.0 将会是什么样?

令人意外:苹果应用极少采用Swift语言开发,等Swift 3.0强制?


都看到这里了,就把这篇资料推荐给您的好朋友吧,让他们也感受一下。

回帖是一种美德,也是对楼主发帖的尊重和支持。您的赞赏是我前进的方向。

*声明:敏捷大拇指是全球最大的Swift开发者社区、苹果粉丝家园、智能移动门户,所载内容仅限于传递更多最新信息,并不意味赞同其观点或证实其描述;内容仅供参考,并非绝对正确的建议。本站不对上述信息的真实性、合法性、完整性做出保证;转载请注明来源并加上本站链接,敏捷大拇指将保留所有法律权益。如有疑问或建议,邮件至marketing@swifthumb.com

*联系:微信公众平台:“swifthumb” / 腾讯微博:@swifthumb / 新浪微博:@swifthumb / 官方QQ一群:343549891(满) / 官方QQ二群:245285613 ,需要报上用户名才会被同意进群,请先注册敏捷大拇指

评分

参与人数 1金钱 +10 贡献 +10 专家分 +10 收起 理由
Anewczs + 10 + 10 + 10 32个赞!专家给力!

查看全部评分

本帖被以下淘专辑推荐:

买定离手 发表于 2016-6-22 11:33:21 | 显示全部楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

淘帖专辑
我要发帖

分享扩散

都看到这里了,就把这资料推荐给您的好朋友吧,让他们也感受一下。
您的每一位朋友访问此永久链接后,您都将获得相应的金钱积分奖励
热门推荐

合作伙伴

Swift小苹果

  • 北京治世天下科技有限公司
  • ©2014-2016 敏捷大拇指
  • 京ICP备14029482号
  • Powered by Discuz! X3.1 Licensed
  • swifthumb Wechat Code
  •   
快速回复 返回顶部 返回列表