Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
KentarouKanno / AutoLayout + Keyboard ResizeView.swift
Created November 12, 2015 14:42
AutoLayout + Keyboard ResizeView
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var bottomLayout: NSLayoutConstraint!
let notificationCenter = NSNotificationCenter.defaultCenter()
override func viewDidLoad() {
super.viewDidLoad()
@KentarouKanno
KentarouKanno / AutoLayout + Keyboard ResizeView.swift
Created November 12, 2015 14:42
AutoLayout + Keyboard ResizeView
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var bottomLayout: NSLayoutConstraint!
let notificationCenter = NSNotificationCenter.defaultCenter()
override func viewDidLoad() {
super.viewDidLoad()

Switch

★ Int

let code = 1001

switch code {
case 200:
    print("Success")
case 300, 301, 302:
@KentarouKanno
KentarouKanno / for, for - in, for case.md
Last active May 1, 2016 03:01
for, for - in, for case

for , for - in , for case

★ for

// Swift2.1まで
for var i = 0 ; i < 10 ; i++ {
    print(i)
}

// Swift2.2以降は以下の書き方に変換されます

Property

★ Stored Propertyies

// Lazy Stored Propertyies
lazy var lazyProperty: String = ""

// Property Observers

flatMap

let stringArray = ["a","2","b","1","3"]

// nilを新しい配列に加えない
let intArray = stringArray.flatMap{ Int($0) }
//=> [2, 1, 3]

// .mapの場合(nilが入り、値もOptional)
// Int
extension Int {
func repeatFunc(task: () -> ()) {
for _ in 0..<self {
task()
}
}
}
@KentarouKanno
KentarouKanno / Optional.md
Last active April 9, 2016 01:35
Optional

Optional

★ Optional型

//=> Optional(1)

var optionalOne: Int? = 1
var optionalOne = 1 as Int?
var optionalOne: Int? = .Some(1)
var optionalOne: Optional<Int> = 1

enum

enum Season {
    case Spring
    case Summer
    case Autumn
    case Winter
}
@KentarouKanno
KentarouKanno / 特殊リテラル.swift
Last active November 16, 2015 22:16
Literal Expression
// 現在のファイル名
__FILE__
//=> /Users/******/Desktop/Swift_Practice/Swift_Practice/
// 現在の行数
__LINE__
// 現在のカラム数
__COLUMN__