This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CommonData.swift | |
// KadaiCheck | |
// | |
import UIKit | |
class CommonData: NSObject { | |
var fruitsArr: Array<CheckRecord> = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1,2,3,4,5,6,7,8,9,10] | |
//filter(){$0 % 2 == 0}. : 配列から2で割り切れるものを抽出 | |
//educe(0){$0+$1} : 初期値を0として、抽出値を全て足す | |
let nums = array.filter(){$0 % 2 == 0}.reduce(0){$0 + $1} | |
println(nums) | |
// -> 30 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
reduceを使って配列からDictionaryを作る方法 | |
url: http://qiita.com/_mpon/items/31d8058715bdc2be2ffa | |
*/ | |
let queries = ["id=3", "token=abc", "tag=5", "plus=3"] | |
let params = queries.reduce([String: String]()) { (var dict, q) in | |
println(dict) | |
println(q) | |
let v = q.componentsSeparatedByString("=") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//クロージャ例 | |
//ノーマルな書き方 | |
let myFunc = {(a: Int, b: Int) -> Int in | |
return a+b | |
} | |
let ans = myFunc(1,2) | |
println(ans) | |
let numbers = [4,7,2,8] | |
let array = map(numbers, {(let v:Int) -> Int in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//外部引数名は add # | |
func calc(#a: Int, #b: Int) -> Int { | |
return a+b | |
} | |
func calc(#c: Int, #d: Int) -> Int { | |
return c+d | |
} | |
func calc(#a: Int, #b: Int, #c: Int) -> Int { | |
return a+b+c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func makeArray<T>(items:T...) -> [T]{ | |
var array = [T]() | |
for item in items { | |
array += [item] | |
} | |
return array | |
} | |
let nums = makeArray(3,5,7,9) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CheckItem.swift | |
import Foundation | |
import RealmSwift | |
class CheckItem : Object { | |
dynamic var id : Int16 = 0 | |
dynamic var name : String = "" | |
dynamic var isCheck : Bool = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TableViewController.swift | |
// | |
import UIKit | |
class TableViewController: UITableViewController { | |
//共通で保持するデータ | |
var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AddFormViewController.swift | |
// KadaiCheck | |
// | |
// | |
import UIKit | |
class AddFormViewController: UIViewController { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CommonData.swift | |
// KadaiCheck | |
// | |
// | |
import UIKit | |
class CommonData: NSObject { | |