WWDC 2017
Session video and resources: https://developer.apple.com/videos/play/wwdc2017/402/
- Toolchain support for more refactors in XCode
- Swift Package Manager
- New Manifest API
- Expand the scope of private needs, meaning that
private
flag will expose variables to the same file forextensions
. No need to usefileprivate
anymore
- Usage of things like
[UIControl & SomeProtocol]
. Allowing to compose certain classes with certain protocols rather than trying to conform toUIControl
and make them conform toSomeProtocol
- Swift 3.2 allows Swift 3 syntax that has changed in Swift 4
- Smoother migration to Swift 4
- Per-target Swift compiler option
Swift 3.2
orSwift 4.0
- Project Settings -> Shared Project Settings -> Build System -> New Build System
- Precompiled bridging headers speed up the build process
- Shared build for coverage testing
- No additional build on top to generate coverage
- Indexing while building
- Build process now updates the index
- Small overhead on the build time
Good to watch understanding swift performance from the last year
- Large values are allocated in the heap and heap allocation is slow, costly
- COW (Copy on write) optimizes large chunks of value types and allow to use same buffer if no modification is done (read only operation)
- Stack allocation for generic buffers and unspecialized generic code
- Compiler level optimization for unused code pieces
- Swift 3 automatically infers
@objc
if there is an instance ofNSObject
. This does some autogeneration for obj-c specific signatures. These methods are not detected if they are not even used. @objc
marking is suggested on extensions and specific functions.- Migrator for minimal inference
- Migrator will mark inferred obj-c chunks as deprecated
- Check the console for these kind of warnings (
@objc
)
- Change Swift 3
@objc
inference to default after your refactor and optimization is done
- Swift symbols take a lot of space
- Symbol Stripping (reduces app size)
Strip Swift Symbols
isYes
by default- View symbols with
xcrun dyldinfo --
(TBD)
- Unicode correctness by default
- In Swift a
Character
is a grapheme meaning that every character is a single representation.count = 1
- In Swift a
- In Swift 4, strings are collection of characters
somestring.{}
rather thansomestring.characters.{}
- String Slicing
let s = "one, two, three" s.split(seperator: ",") -> ["one", "two", "three"] : [Substring]
Substring
is a new type to avoid memory leaks. E.g: Prevent holding the whole buffer for a small part of a huge string. Wrap this into aString
again after the operation is done.
- Multi-line String Literals
- Triple Quoted Strings
"""
let test = """ Bla Bla Bla """
- Triple Quoted Strings
associatedtype
extensions for protocols to avoidIterator.element
and useElement
- Generic Subscripts
- Ownership
- Multi-threaded Enforcement
- Threat sanitizer cathes these errors
- This will be a warning in Swift 3.2, will be an error in future releases
- More reliable performance
- Lots of optimization in libraries, compiler lvl etc.
- Compile time enforcement is enabled by default