5. IBM Swift Package Catalog
• https://swiftpkgs.ng.bluemix.net/
• Find, explore and share packages
from the open-source Swift
ecosystem
• Explore dependencies
• Submit your own packages
5
6. Kitura Web Framework
What is it?
• New, modular, package-based web framework
written in Swift
Why is this cool?
• Empower a new generation of native mobile
developers to write and deploy code into the
Cloud.
Developer Benefits ?
• Delivers core technologies needed to
stand up enterprise apps on the server
• Enables developers to create a web
application in Swift and deploy these
servers on Linux and the Cloud.
http://github.com/ibm-swift/kitura 6
7. IBM Swift Sandbox
• Interactive sandbox for
rapid prototyping and
experimentation in Swift
• Saves your work
• Supports multiple
versions of Swift
• Responsive design
7
https://swiftlang.ng.bluemix.net/
8. Swift 3.0
• Major release
• Not source-compatible with Swift 2.2
• Fundamental changes to the language and standard library
• Swift package manager – Linux & Darwin
9. Language changes
• Removal of C-style for-loops
• Removal of increment/decrement operators
• New function to find first element passing a predicate
• Consistent label behavior for first parameter
10. Language changes
• New API guidelines
• Keywords in member references
• Case labels with multiple patterns
• Generic type-aliasing
11. C-Style code (Swift 2.2)
func arithmeticSeries(a: Int, d: Int, n: Int) -> [Int] {
var series: [Int] = []
for var i = 0; i < n; i++ {
series += [a + i*d]
}
return series
}
arithmeticSeries(1, d: 3, n: 10)
12. C-style constructs removed
//this works on all Swift versions
func arithmeticSeries(a: Int, d: Int, n: Int) -> [Int] {
var series: [Int] = []
for i in 0..<n {
series += [a+i*d]
}
return series
}
print(arithmeticSeries(1, d: 3, n: 10))
13. Sequence iteration - stdlib
func arithmeticSeries(a: Int, d: Int, n: Int) -> [Int] {
var series: [Int] = []
for x in sequence(first: a, next: {$0+d}).prefix(n){
series += [x]
}
return series
}
print(arithmeticSeries(a: 1, d: 3, n: 10))
14. Sequence.first(where:)
Finding the first element that satisfies a predicate
let series = arithmeticSeries(a: 1, d: 3, n: 10)
//first double digit element
series.first(where: {$0 > 9})
15. Consistent label behavior for first parameter
Until Swift 2.2
func sum (x a: Int, y b: Int, z c: Int) -> Int {
return a + b + c
}
>> sum (x: 10, y: 20, z: 30)
16. Consistent label behavior for first parameter
Until Swift 2.2
func sum (a: Int, y b: Int, z c: Int) -> Int {
return a + b + c
}
>> sum (10, y: 20, z: 30)
17. Consistent label behavior for first parameter
Until Swift 2.2
func sum (a: Int, b: Int, c: Int) -> Int {
return a + b + c
}
>> sum (10, b: 20, c: 30)
18. Consistent label behavior for first parameter
In Swift 3.0
func sum (a: Int, b: Int, c: Int) -> Int {
return a + b + c
}
>> sum (a: 10, b: 20, c: 30)
19. Consistent label behavior for first parameter
In Swift 3.0 – to save your clients/users from doing extra work
func sum (_ a: Int, b: Int, c: Int) -> Int {
return a + b + c
}
>> sum (10, b: 20, c: 30)
20. Power of Enums
public enum Video {
case Public(Int, Int, String)
case Private(String)
case Optional(String, Int)
}
21. Power of Enums
public enum Video {
case Public(Int, Int, String)
case Private(String)
case Optional(String, Int)
}
22. Power of Enums
extension Video {
func getName() -> String {
switch self {
case let .Public(_, _, s) :
return s
case let .Private(s):
return s
case let .Optional(s, _):
return s
}
}
}
23. Lower camel case – New API guideline
public enum Video {
case public(Int, Int, String)
case private(String)
case optional(String, Int)
}
public enum Video {
case `public`(Int, Int, String)
case `private`(String)
case `optional`(String, Int)
}
24. Keywords in member references
extension Video {
func getName() -> String {
switch self {
case let .public(_, _, s) :
return s
case let .private(s):
return s
case let .optional(s, _):
return s
}
}
}
//backticks not needed while referencing member!
25. Case labels with multiple patterns
extension Video {
func getName() -> String {
switch self {
case let .public(_, _, s),
let .private(s),
let .optional(s, _):
return s
}
}
}
29. Generic Type aliases
Will your function reverse function reverse (“swift”, 3.14, 100) ?
How would you do that?
30. Swift Package Manager
A successful modern language needs an efficient package manager
• A tool for managing distribution of Swift code
• Integrated with the Swift build system
• Downloading, compiling and linking dependencies
• Baby step towards matching CocoaPods & Carthage
31. Swift Package Manager
• Modules
• Packages
Manifest file
Git based for now
• Products
Library or executable
• Dependencies
Semantic version management
What is it ?
Kitura is a new, modular, package-based web framework written in the Swift language for use in standing up a web server written in Swift on both OSX and Linux.
Why is this cool ?
Now that Swift is open source, a number of included projects are coming together (swift, swift package manager, libdispatch, swift foundation) that makes the development of a Swift-based web server stack both inevitable as well as incredibly valuable means to empower a new generation of native mobile developers to write and deploy code into the Cloud as well.
Developer Benefits ?
Once you have a new language that runs on a server, many developers want to be able to quickly and easily create a web server written in that language. The swift language and runtime does not include a web framework that can be used to easily create a web server. IBM has created this project to enable developers to create a web application in Swift and deploy these servers on Linux and the Cloud.
IBM Message
We are leading the development of this web framework and will work with the community to evolve this framework over time as Swift on Linux evolves.
Other Details