Swift

45
Swift Best practises for iOS/OSX developers Quentin deQuelen

Transcript of Swift

SwiftBest practises for iOS/OSX developers

Quentin deQuelen

Histoire

Un langage fait par Apple pour Apple

Sortie officiel

WWDC14

Disponible pour les plateformes

Différence avec l’Objective-c

NSArray *unsortedArray = @[@"Ahmed", @"Marwa", @"Siva", @"Paul", @"Otto", @"Sam", @"Candy"]; NSSortDescriptor* sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:NO selector:@selector(localizedCompare:)]; NSArray* sortedArray = [unsortedArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; //SortedArray = [Siva, Sam, Paul, Otto, Marwa, Candy, Ahmed]

Différence avec l’Objective-c

let names = ["Ahmed", "Marwa", "Siva", "Paul", "Otto", "Sam", "Candy"] reversed = sort(names, {>}) // reversed = [Siva, Sam, Paul, Otto, Marwa, Candy, Ahmed]

Swift + Objective-C

#ifndef RandomailApp_Bridging_Header_h #define RandomailApp_Bridging_Header_h

#import <UIKit/UIKit.h> #import "DTCoreText.h"

#endif

Une base commune

Cocoa frameworks

Cocoa touch frameworks

IDE : Xcode

IDE : Playground

Librairies et Kits

Agrégateur de librairies

SwiftToolbox

Gestionnaire de dépendances

CocoaPods

Cocoapods : exemple

$ sudo gem install cocoa pods

$ nano Podfile

Cocoapods : exemple

platform :ios, '8.0'

pod 'Alamofire' pod 'MaterialKit' pod 'Toucan' pod 'SwiftyJSON' pod 'SwiftyUserDefaults' pod 'KeychainSwift' pod 'JLToast' pod 'Spring' pod 'GoogleAnalytics-iOS-SDK', '~> 3.10'

Cocoapods : exemple

platform :ios, '8.0'

pod 'Alamofire' pod 'MaterialKit' pod 'Toucan' pod 'SwiftyJSON' pod 'SwiftyUserDefaults' pod 'KeychainSwift' pod 'JLToast' pod 'Spring' pod 'GoogleAnalytics-iOS-SDK', '~> 3.10'

Cocoapods : exempleuse_frameworks!

platform :ios, '8.0'

pod 'Alamofire' pod 'MaterialKit' pod 'Toucan' pod 'SwiftyJSON' pod 'SwiftyUserDefaults' pod 'KeychainSwift' pod 'JLToast' pod 'Spring' pod 'GoogleAnalytics-iOS-SDK', '~> 3.10'

Cocoapods : exemple

$ pod install

App.xcodeproj -> App.xcworkspace

$ open App.xcworkspace

Alamofire

// Fetch Request Alamofire.request(.POST, urlString, parameters: bodyParameters, encoding: encoding) .validate(statusCode: 200..<300) .responseJSON{(request, response, JSON, error) in println("HTTP Response Body: \(JSON)") if (error == nil) { println("HTTP Response Body: \(JSON)") successful(true) } else { successful(false) println("HTTP HTTP Request failed: \(error)") } }

Alamofire

SwiftyJSON - Avantlet jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwitter, options: NSJSONReadingOptions.MutableContainers, error: nil) if let statusesArray = jsonObject as? NSArray{ if let aStatus = statusesArray[0] as? NSDictionary{ if let user = aStatus["user"] as? NSDictionary{ if let userName = user["name"] as? NSDictionary{ //Finally We Got The Name } } } }

SwiftyJSON - Avantlet jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwitter, options: NSJSONReadingOptions.MutableContainers, error: nil) if let statusesArray = jsonObject as? NSArray{ if let aStatus = statusesArray[0] as? NSDictionary{ if let user = aStatus["user"] as? NSDictionary{ if let userName = user["name"] as? NSDictionary{ //Finally We Got The Name } } } }

SwiftyJSON - Après

let json = JSON(data: dataFromNetworking) if let userName = json[0]["user"]["name"].string{ //Now you got your value }

Kit de développement

SceneKit

Kit de développement

SceneKit

Objet 3D

Animation 3D

Textures

Cameras

Morphing

Kit de développement

SpriteKit

Kit de développement

SpriteKit

Objet 2D

Animation 2D

OpenGL

Kit de développement

HealthKit

Kit de développement

Santé

Fitness

Données privées HealthKit

Kit de développement

ResearchKit

ResearchKit

Kit de développement

Recherche médicale

Lié à HealthKit

Données centralisées

Open source

Kit de développement

HomeKit

HomeKit

Kit de développement

Connexion à un objet connecté

Lie des action aux objets

Normalisation des communications

Normalisation des actions

Kit de développement

WatchKit

WatchKit

Kit de développement

Vues et animations

Taptic Engine

Audio et vidéo

Alert

Kit de développement

import SceneKit import SpriteKit import HealthKit import ResearchKit import HomeKit import WatchKit import UIKit import Foundation

Design

Vue en drag en drop

Objets graphiques

Démo

One more thing

Swift 2

Open Source

Question ?

Plus d’information

Swift Language Documentation

http://developer.apple.com/swift

Apple Developer Forums

http://developer.apple.com/forums

Quentin de Quelen

Swift Evangelist

[email protected]