Skip to content

Instantly share code, notes, and snippets.

let dict = ["key1":"value1","key2":"value2","key3":"value3"]
// 変数を宣言(初期値を設定)
var value1: String = "defaultValue"
// 値が取得できれば代入
if let tmpValue = dict["key"] {
value1 = tmpValue
}
// ~= パターンマッチ(左辺の範囲内に右辺が有ればtrue)
200 //=> Contains
300 //=> Not Contains
let status = 299
//=> Contains
if (200 ..< 300) ~= status {
@KentarouKanno
KentarouKanno / MessageManager.swift
Last active October 27, 2015 21:42
アプリ内で使用するメッセージを管理するクラス
// 使用例
let errorMessage = MessageManager.LoginView.IDMaxLengthError
//=> IDは10桁で入力してください。
struct MessageManager {
/** 入力画面 */
struct InputView {

for - in (forEach)

--- 番号配列 ---

let numArray = ["1","2","3","4","5"]

★ 前から取り出し

for num in numArray {
let array: [String] = []
let array: Array<String> = []
let array = [String]()
if array.count != 0 {
// 配列が存在する時の処理
}
@KentarouKanno
KentarouKanno / UITableView Simple Template.md
Last active December 7, 2023 19:02
UITableView Simple Template

UITableView Simple Template

  • Small Sample
import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
@KentarouKanno
KentarouKanno / UITableView Section Template.md
Last active February 12, 2017 09:41
UITableView Section Template

UITableView Section Template

★ Template - 1

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    @IBOutlet weak var tableView: UITableView!
@KentarouKanno
KentarouKanno / CGGeometry.md
Last active September 10, 2016 09:23
CGGeometry

CGGeometry

★ CGPoint

let point: CGPoint = CGPointMake(0, 0)
let point: CGPoint = CGPoint(x: 0, y: 0)

var x = point.x
var y = point.y
@KentarouKanno
KentarouKanno / Array filter.md
Last active April 6, 2017 14:33
Array filter

Array filter

★ クロージャに指定した条件を満たす要素からなる新しい配列を返す関数

let numList = [1 ,2 ,3 ,4 ,5]

// 偶数のみを抽出して返す
let evenList = numList.filter {(val:Int) -> Bool in
    return val % 2 == 0
}
@KentarouKanno
KentarouKanno / map.md
Last active December 31, 2015 01:58
map

Array map

★ クロージャが返した値の配列を返す。

let numList = [1 ,2 ,3 ,4 ,5]

let value = numList.map ({(val:Int) -> Int in
    // 配列の値に1を加えたものを返す
 return val + 1