45
Hamamatsu.swift @ IT

Hamamatsu.swift @浜松IT合同勉強会

Embed Size (px)

Citation preview

Hamamatsu.swift@ IT

Takuya

• iOS Android (PHP

• Swift 1 ( 2015/5/18)

• Android

• Hamamatsu.swift

@Licht_x

Hamamatsu.swift

• OSC Hamanako 2016

(2016 1 23 ( ))

• Hamamatsu.swift #1 2016/02/27( )

• 1 4

• 5

Swift

Swift

• Swift iOS OS X

WWDC 2014 OS

Objective-C

Objective-C++ C

• Swift Xcode Playgrounds

• LLVM

Swift is Open Source

Swift is Open Source

• WWDC 2015

• Apache Licence 2.0 GitHub

(https://github.com/apple/swift)

• 2010 7 18

LLVM Chris Lattner

First Commit is 2010/7/18

• Github Initial commit

OpenSource

• Foundation

• libdispatch

• XCTest

• Package Manager

• LLDB Swift

• SourceKit(

)

Linux Support

• Ubuntu 15.10,14.04

• https://swift.org/download/

• swiftdocker/docker-swifthttps://github.com/swiftdocker/docker-swift

Swift for Windows (cygwin, msvc, mingw)• Windows

• Swift for Windows https://github.com/

tinysun212/swift-windows)

Swift on Android• Swift Android

swift/Android.md https://github.com/apple/swift/blob/master/docs/Android.md

• Android

Web Framework

• Web FrameworkSwift

• Rails Express

Framework

Web Framework

Perfect [http://perfect.org/]

Kitura - IBM[https://github.com/ibm-swift/kitura]

Swifton [https://github.com/necolt/Swifton]

Express [https://github.com/crossroadlabs/Express]

vapor [https://github.com/qutheory/vapor]

blackfish [https://github.com/elliottminns/blackfish]

Slimane [https://github.com/noppoMan/Slimane]

Objective-C → Swift

• ObjC→Swift

http://techblog.yahoo.co.jp/ios/objc2swift/

• Xcode

Swift ObjC

ObjC Swift

Command Line Tool

http://techlife.cookpad.com/entry/2015/11/09/150248

Swift

Hello World

• print(”Hello World!”)

• WWDC2016

Variable

• let : =

• var : =

• let pi: Double = 3.141592

• let pi = 3.141592 //

for loopvar numbers = [100, 200, 300] var sum = 0 for var i = 0; i < numbers.count; i++ { sum += numbers[i] } //Swift3 Swift2.2 Deprecated

for i in 0..<numbers.count { sum += numbers[i] }

for number in numbers { sum += number }

Switch

switch num { case 0: message = "case 0" case 1, 2, 3: message = "case 1 or 2 or 3" default: break }

Cast

var object : Any = "message" var message = object as String

Java

Object object = "message"; String message = (String) object;

Method

func countUp(number : Int) -> Int { return number + 1 }

var result = countUp(1) print(result) // => 2

Extends

class NamedShape: Shape { var name: String = ""

override func description() -> String { return “ \(name)" + super.description()

} }

Optional

nil

nil

• ?

!

Declaration

var hoge: String?

var fuga: String

Print

var hoge: String? print(hoge) # => nil

var fuga: String print(fuga) # =>

Optional()

var hoge: String? = "Hello World" print(hoge) # => Optional("Hello World”)

var fuga: String = "Hello World" print(fuga) # => Hello World

UnWrap

• Optional ( )

• Forced Unwrapping ( )

• Optional Binding ( )

• Optional Chaining ( )

Forced Unwrapping

var optional: Int? = 10

print(optional) // => Optional(10)

print(optional!) // => 10

Optional Binding

var hobby: String?

if let hobby = hobby { print(hobby) }else { print("no hobby") }

Optional Chaining

var human: Human? = Human()

human?.name

human?.hello()

nil

nil nil

guard

var human: Human? = Human()

guard let human = human else { return }

human.hello()//unwrap

Extension

extension String { var isHiragana: Bool { return unicodeScalars.reduce(!isEmpty) { (result, unicode) -> Bool in return result && 0x3040 <= unicode.value && unicode.value < 0x30A0 } } }

“ ”.isHiragana

//true

Swift 3.0

Remove the ++ and -- operators

let a = ++x let b = x++ let c = --x let d = x-- // Before: x++ // After: x += 1

Remove C-style for-loops with conditions and incrementers// Before: for var i = 0 ; i < 10 ; i++ { } // After: for i in 0..<10 { } // Before: for var i = 0 ; i <= 10 ; i++ { } // After: for i in 0...<10 { }

Swift

Swift

Hamamatsu.swift

Hamamatsu.swift

• Swift

• iOS

• Swift

• OSC @Licht_x

7/30( )

• Hamamatsu.swift #5

• 13:00 ~ 17:00

• http://hamamatsu-swift.connpass.com/event/33834/