Try!Swift India 2017: All you need is Swift

Post on 22-Jan-2018

330 views 0 download

Transcript of Try!Swift India 2017: All you need is Swift

All you need is

SwiftSafe | Expressive | Fast

Chris Bailey @Chris__Bailey

AB Vijay Kumar @abvijaykumar

We delivered >100 apps that change the way people work

We created Accelerators for iOS custom app delivery

We now bring everything together for enterprise wide integration of iOS app

services

In July 2014 Apple and IBM announced a partnership to transform enterprise mobility.

100+ Apps

14 Industries

50+ Clients

PUBLIC NETWORK CLOUD NETWORK ENTERPRISE NETWORK

Mobile App

EDGE SERVICES

LOAD BALANCER

CONNECTIVITY

ENTERPRISEAPPLICATION

Mobile Services Enterprise Integration

DevOps Services

MOBILE MIDDLEWARE

PUSN NOTIFICATION

MOBILE DATA STOREMOBILE SECURITY

API MANAGEMENT

STORAGE

MOBILE ANALYTICS

Data Services

NOTIFICATION SERVICEPROVIDER

API Services CLIENTFIREWALL

MOBILE APPLIFECYCLE

CONTINUOUSRELEASE

CONTINUOUS BUSINESSPLANNING

CONTINUOUSMONITORING & FEEDBACK

CONFIGURATIONMANAGEMENT CONTINUOUS

DEPLOYMENT

CACHING

ENTERPRISE DATA

ENTERPRISE DIRECTORY

API INTEGRATION

Rapid App Development

Full Stack Development

Scalable & High performance Mobile backend

Easy Integration with other Cloud Services & Backend System

Rapid App Development

Full Stack Development

Scalable & High performance Mobile backend

Easy Integration with other Cloud Services & Backend System

Mouse Maze Free: © Top Free Games

Mouse Maze Free: © Top Free Games

Mouse Maze Free: © Top Free Games

Mouse Maze Free: © Top Free Games

IBM Expert Seller

IBM Expert Seller

Icons made by Freepik from www.flaticon.com

Icons made by Freepik from www.flaticon.com

Icons made by Freepik from www.flaticon.com

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift

{ "name": "", "photo": "", "dateOfBirth": ""}

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift

Swiftparsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

Node.js

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

{ "name": "", "photo": "", "dateOfBirth": ""}

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Node.js

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Node.js

Data

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Node.js

Data String

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Node.js

Data String String of data

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Node.js

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Node.js

Date

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Node.js

Date String

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Node.js

Date String String

parsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"]

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

{ "name": "", "photo": "", "dateOfBirth": ""}

{ "name": "", "photo": "", "dateOfBirth": { "year": "month": "day": } }

Swift Node.js

Date String

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

{ "name": "", "photo": "", "dateOfBirth": ""}

{ "name": "", "photo": "", "dateOfBirth": { "year": "month": "day": }}

Swiftparsed = JSON.parse(data)

name = parsed["name"] photo = parsed["photo"] dateOfBirth = parsed["dateOfBirth"] year = dateOfBirth["year"] month = dateOfBirth["month"] day = dateOfBirth[“day"]

Node.js

Date Strings

I have to learn Node.js? (or Ruby, Python, Java, etc)

Swift

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

Swift Swift

KITURA

struct Profile { var name: String var photo: Data var dateOfBirth: Date}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

Swift Swift

KITURA

Codable

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

Swift Swift

KITURA

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

Shared

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

Swift Swift

let encoder = JSONEncoder() let data = try encoder.encode(profile)

KITURA

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

Swift Swift

let decoder = JSONDecoder() let person = try decoder.decode(Person.self, from: jsonData)

KITURA

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

{ "name": "", "photo": "", "dateOfBirth": ""}

{ "name": "", "photo": "", "dateOfBirth": ""}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

Swift Swift

KITURA

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

Swift Swift

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

KITURA

struct Profile: Codable { var name: String var photo: Data var dateOfBirth: Date}

Deploy Deploy

KITURA

Deploy DeployGenerate

KITURA

Icons made by Freepik from www.flaticon.com

Icons made by Freepik from www.flaticon.com

Fetch the Profile for a user from the Backend

var urlComponents = URLComponents()urlComponents.scheme = "https"urlComponents.host = "myhost.myserver.com"urlComponents.path = “/profile"

Set up Backend URL

var urlComponents = URLComponents()urlComponents.scheme = "https"urlComponents.host = "myhost.myserver.com"urlComponents.path = “/profile"

let userIdItem = URLQueryItem(name: "id", value: "\(userId)")urlComponents.queryItems = [userIdItem]guard let url = urlComponents.url else { fatalError("Could not create URL from components") }

Set up Person ID

var urlComponents = URLComponents()urlComponents.scheme = "https"urlComponents.host = "myhost.myserver.com"urlComponents.path = “/profile"

let userIdItem = URLQueryItem(name: "id", value: "\(userId)")urlComponents.queryItems = [userIdItem]guard let url = urlComponents.url else { fatalError("Could not create URL from components") } var request = URLRequest(url: url)request.httpMethod = "GET"

Set up “GET” request

var urlComponents = URLComponents()urlComponents.scheme = "https"urlComponents.host = "myhost.myserver.com"urlComponents.path = “/profile"

let userIdItem = URLQueryItem(name: "id", value: "\(userId)")urlComponents.queryItems = [userIdItem]guard let url = urlComponents.url else { fatalError("Could not create URL from components") } var request = URLRequest(url: url)request.httpMethod = "GET" let session = URLSession(configuration: URLSessionConfiguration.default)let task = session.dataTask(with: request) { (responseData, response, responseError) in }task.resume()

Set up URLSession

var urlComponents = URLComponents()urlComponents.scheme = "https"urlComponents.host = "myhost.myserver.com"urlComponents.path = “/profile"

let userIdItem = URLQueryItem(name: "id", value: "\(userId)")urlComponents.queryItems = [userIdItem]guard let url = urlComponents.url else { fatalError("Could not create URL from components") } var request = URLRequest(url: url)request.httpMethod = "GET" let session = URLSession(configuration: URLSessionConfiguration.default)let task = session.dataTask(with: request) { (responseData, response, responseError) in }task.resume()

Web RequestWeb Response

Error

Call URLSession

var urlComponents = URLComponents()urlComponents.scheme = "https"urlComponents.host = "myhost.myserver.com"urlComponents.path = “/profile"

let userIdItem = URLQueryItem(name: "id", value: "\(userId)")urlComponents.queryItems = [userIdItem]guard let url = urlComponents.url else { fatalError("Could not create URL from components") } var request = URLRequest(url: url)request.httpMethod = "GET" let session = URLSession(configuration: URLSessionConfiguration.default)let task = session.dataTask(with: request) { (responseData, response, responseError) in DispatchQueue.main.async { guard responseError == nil else { completion?(.failure(responseError!)) } guard let jsonData = responseData else { let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: “No data"]) as Error completion?(.failure(error)) } } }task.resume()

Error Checking

var urlComponents = URLComponents()urlComponents.scheme = "https"urlComponents.host = "myhost.myserver.com"urlComponents.path = “/profile"

let userIdItem = URLQueryItem(name: "id", value: "\(userId)")urlComponents.queryItems = [userIdItem]guard let url = urlComponents.url else { fatalError("Could not create URL from components") } var request = URLRequest(url: url)request.httpMethod = "GET" let session = URLSession(configuration: URLSessionConfiguration.default)let task = session.dataTask(with: request) { (responseData, response, responseError) in DispatchQueue.main.async { guard responseError == nil else { completion?(.failure(responseError!)) } guard let jsonData = responseData else { let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: “No data"]) as Error completion?(.failure(error)) } let decoder = JSONDecoder() do { let person = try decoder.decode(Profile.self, from: jsonData) completion?(.success(person)) } catch { completion?(.failure(error)) } }}task.resume()

Convert Response

router.get(“/profile", handler: getProfile)

func getProfile(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) { guard let contentType = request.headers["Content-Type"], contentType.hasPrefix("application/json") else { response.status(.unsupportedMediaType) response.send(error) return next() } let name = request.parameters["name"] ?? "" let encoder = JSONEncoder() let profile = profileStore[name] var data: Data

do { data = try encoder.encode(profile) } catch let error { response.status(.unprocessableEntity) response.send(error) next() } response.send(data) next() }

router.get(“/profile", handler: getProfile)

func getProfile(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) { guard let contentType = request.headers["Content-Type"], contentType.hasPrefix("application/json") else { response.status(.unsupportedMediaType) response.send(error) return next() } let name = request.parameters["name"] ?? "" let encoder = JSONEncoder() let profile = profileStore[name] var data: Data

do { data = try encoder.encode(profile) } catch let error { response.status(.unprocessableEntity) response.send(error) next() } response.send(data) next() }

Web Request

router.get(“/profile", handler: getProfile)

func getProfile(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) { guard let contentType = request.headers["Content-Type"], contentType.hasPrefix("application/json") else { response.status(.unsupportedMediaType) response.send(error) return next() } let name = request.parameters["name"] ?? "" let encoder = JSONEncoder() let profile = profileStore[name] var data: Data

do { data = try encoder.encode(profile) } catch let error { response.status(.unprocessableEntity) response.send(error) next() } response.send(data) next() }

Web RequestWeb Response

router.get(“/profile", handler: getProfile)

func getProfile(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) { guard let contentType = request.headers["Content-Type"], contentType.hasPrefix("application/json") else { response.status(.unsupportedMediaType) response.send(error) return next() } let name = request.parameters["name"] ?? "" let encoder = JSONEncoder() let profile = profileStore[name] var data: Data

do { data = try encoder.encode(profile) } catch let error { response.status(.unprocessableEntity) response.send(error) next() } response.send(data) next() }

Web RequestWeb Response

Validate and Convert parameters

router.get(“/profile", handler: getProfile)

func getProfile(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) { guard let contentType = request.headers["Content-Type"], contentType.hasPrefix("application/json") else { response.status(.unsupportedMediaType) response.send(error) return next() } let name = request.parameters["name"] ?? "" let encoder = JSONEncoder() let profile = profileStore[name] var data: Data

do { data = try encoder.encode(profile) } catch let error { response.status(.unprocessableEntity) response.send(error) next() } response.send(data) next() }

Web RequestWeb Response

Validate and Convert parameters

Encode and Send Result

I have to learn Web Programming?

KITURA+

Kitura 2.0KituraKit

KITURAKITvar urlComponents = URLComponents()urlComponents.scheme = "https"urlComponents.host = "myhost.myserver.com"urlComponents.path = “/profile"

let userIdItem = URLQueryItem(name: "id", value: "\(userId)")urlComponents.queryItems = [userIdItem]guard let url = urlComponents.url else { fatalError("Could not create URL from components") } var request = URLRequest(url: url)request.httpMethod = "GET" let session = URLSession(configuration: URLSessionConfiguration.default)let task = session.dataTask(with: request) { (responseData, response, responseError) in DispatchQueue.main.async { guard responseError == nil else { completion?(.failure(responseError!)) } guard let jsonData = responseData else { let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: “No data"]) as Error completion?(.failure(error)) } let decoder = JSONDecoder() do { let person = try decoder.decode(Person.self, from: jsonData) completion?(.success(person)) } catch { completion?(.failure(error)) } }}task.resume()

guard let backend = KituraKit(baseURL: "http://localhost:8080") else { print("Error creating KituraKit client") return}

KITURAKIT

guard let backend = KituraKit(baseURL: "http://localhost:8080") else { print("Error creating KituraKit client") return}

backend.get("/profile", id: userId) { (profile: Profile?, error: RequestError?) in ...

}

KITURAKIT

guard let backend = KituraKit(baseURL: "http://localhost:8080") else { print("Error creating KituraKit client") return}

backend.get("/profile", id: userId) { (profile: Profile?, error: RequestError?) in ...

}

KITURAKIT

Swift Type (Identifier)

guard let backend = KituraKit(baseURL: "http://localhost:8080") else { print("Error creating KituraKit client") return}

backend.get("/profile", id: userId) { (profile: Profile?, error: RequestError?) in ...

}

KITURAKIT

Swift Type (Codable)

Swift Type (Identifier)

guard let backend = KituraKit(baseURL: "http://localhost:8080") else { print("Error creating KituraKit client") return}

backend.get("/profile", id: userId) { (profile: Profile?, error: RequestError?) in ...

}

KITURAKIT

Swift Type (Codable)

Swift Type (RequestError)Swift Type

(Identifier)

KITURAKITURA 2.0

router.get(“/profile", handler: getProfile)

func getProfile(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) { guard let contentType = request.headers["Content-Type"], contentType.hasPrefix("application/json") else { response.status(.unsupportedMediaType) response.send(error) return next() } let name = request.parameters["name"] ?? "" let encoder = JSONEncoder() let profile = profileStore[name] var data: Data

do { data = try encoder.encode(profile) } catch let error { response.status(.unprocessableEntity) response.send(error) next() } response.send(data) next() }

router.get(“/profile”) { (userId: Int, respondWith: @escaping (Profile?, RequestError?) -> Void) in ...

}

KITURAKITURA 2.0

router.get(“/profile”) { (userId: Int, respondWith: @escaping (Profile?, RequestError?) -> Void) in ...

} Swift Type (Identifier)

KITURAKITURA 2.0

router.get(“/profile”) { (userId: Int, respondWith: @escaping (Profile?, RequestError?) -> Void) in ...

}

Swift Type (Codable)

Swift Type (Identifier)

KITURAKITURA 2.0

router.get(“/profile”) { (userId: Int, respondWith: @escaping (Profile?, RequestError?) -> Void) in ...

}

Swift Type (Codable)

Swift Type (RequestError)

Swift Type (Identifier)

KITURAKITURA 2.0

Icons made by Freepik from www.flaticon.com

Icons made by Freepik from www.flaticon.com

Can I use it in for real apps?

Commercial Support for Swift and Kitura

from

from

IBM Cloud

Commercial Support for Swift and Kitura

Become a SwiftStack Developer Today

kitura.io

Become a SwiftStack Developer Today

kitura.ioswift-at-ibm-slack .mybluemix.net

Become a SwiftStack Developer Today

kitura.io github.com/ibm-swiftswift-at-ibm-slack .mybluemix.net

Join IBM http://ibmreferrals.reppify.com/