Created
May 7, 2017 08:18
-
-
Save tkymx/56ea94aacee0ae7acda55f38485974ee to your computer and use it in GitHub Desktop.
getToDay 何日前かを指定して日付をstringで取得、DateManager 日付と体重の組を管理(コンストラクタで乱数組作成)
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 getToDay(day : Double = 0) -> String { | |
let now = Date( timeInterval: 60*60*24*day, since: Date() as Date ) | |
let formatter = DateFormatter() | |
formatter.dateFormat = "yyyy-MM-dd" | |
return formatter.string(from: now as Date) | |
} | |
class DateManager { | |
var dateToWeight : Dictionary<String,String> = [:] | |
static let singleton = DateManager() | |
private init(){ | |
for i in 10...20 { | |
dateToWeight[getToDay(day:(Double)(-i))] = String((Int)(arc4random()) % 50+50); | |
} | |
} | |
func saveWeight(day :String , weight : String){ | |
dateToWeight[day] = weight; | |
} | |
func ToString() -> String { | |
var str : String = ""; | |
for (key, value) in dateToWeight { | |
str += key + value + "\n"; | |
} | |
return str; | |
} | |
func getWeight( day : String ) -> String { | |
if dateToWeight.contains(where:{ | |
key,value in | |
return key.contains(day)}){ | |
return dateToWeight[day]!; | |
} | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment