This file contains 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
遞迴是程式設計師的最愛也最恨 | |
愛的是簡潔 | |
恨的是出包往往在無形之間(Stack Overflow) | |
以及效率非常緩慢 | |
所有的遞迴寫法一定可以用迴圈取代 | |
但換來的就是一連串冗長的程式碼了 | |
L. Peter Deutsch 程式設計師說過一段經典名句 |
This file contains 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 sortedTradingRecords = tradingRecords.sort { $0.time.compareAsNSDate < $1.time.compareAsNSDate } |
This file contains 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
import Foundation | |
/* | |
this extension cover these case | |
www.youtube.com/v/id | |
www.youtube.com?v=vid | |
http://www.youtube.com/watch?v=id&feature=youtu.be | |
http://www.youtube.com/watch?v=id | |
youtube.be/id |
This file contains 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
import Foundation | |
// string -> define date -> define string -> string | |
extension NSDate { | |
var formattedString: String{ | |
let formatter = NSDateFormatter() | |
// ex: 12.04 -> NSDate | |
formatter.dateFormat = "MM.dd" | |
formatter.timeZone = NSTimeZone(name: "Asia/Taipei") |
This file contains 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
//One attributed string method | |
let theInfoTitleString = "曼麗卡說明 Manli Card\n\n" | |
let theInfoTitleAttribute = [NSFontAttributeName: UIFont.systemFontOfSize(22), NSUnderlineStyleAttributeName: 1] | |
let theInfoDetailString = "是大魯閣草衙道專屬會員卡,更是全台首創結合購物集點、小額付款的一卡通會員卡,讓您一卡在手、暢遊草衙道!" | |
// let theAllInfoString = theInfoStringTitle + "\n" + theInfoStringDetail | |
let theInfoTitleAttributedString = NSMutableAttributedString(string: theInfoTitleString, attributes: theInfoTitleAttribute) | |
let theInfoDetailAttributedString = NSAttributedString(string: theInfoDetailString) |
This file contains 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
//產出用zip為key找 縣市/鄉鎮市區 | |
println(zipJson?.dictionaryValue.keys.array) | |
println(zipJson?.dictionaryValue.values.array) | |
for var i = 0; i < zipJson?.dictionaryValue.keys.array.count ; i++ { | |
let first = zipJson?.dictionaryValue.keys.array[i] | |
let second = zipJson?.dictionaryValue.values.array[i] | |
let third = zipJson?.dictionaryValue.values.array[i].dictionaryValue |
This file contains 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
{ | |
"基隆市": {"仁愛區": "200", "信義區": "201", "中正區": "202", "中山區": "203", "安樂區": "204", "暖暖區": "205", "七堵區": "206"}, | |
"台北市": {"中正區": "100", "大同區": "103", "中山區": "104", "松山區": "105", "大安區": "106", "萬華區": "108", "信義區": "110", "士林區": "111", "北投區": "112", "內湖區": "114", "南港區": "115", "文山區": "116"}, | |
"新北市": { | |
"萬里區": "207", "金山區": "208", "板橋區": "220", "汐止區": "221", "深坑區": "222", "石碇區": "223", | |
"瑞芳區": "224", "平溪區": "226", "雙溪區": "227", "貢寮區": "228", "新店區": "231", "坪林區": "232", | |
"烏來區": "233", "永和區": "234", "中和區": "235", "土城區": "236", "三峽區": "237", "樹林區": "238", | |
"鶯歌區": "239", "三重區": "241", "新莊區": "242", "泰山區": "243", "林口區": "244", "蘆洲區": "247", | |
"五股區": "248", "八里區": "249", "淡水區": "251", "三芝區": "252", "石門區": "253" | |
}, |
This file contains 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
{ | |
"929" : [ | |
"琉球鄉", | |
"屏東縣" | |
], | |
"508" : [ | |
"和美鎮", | |
"彰化縣" | |
], | |
"884" : [ |
This file contains 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
extension AppDelegate { | |
func findCurrentViewController() -> UIViewController{ | |
let rootVC = UIApplication.sharedApplication().keyWindow?.rootViewController | |
return findCurrentViewController(byTempTopVC: rootVC!) | |
} | |
func findCurrentViewController(byTempTopVC vc: UIViewController) -> UIViewController { | |
let presentedVC = vc.presentedViewController | |
OlderNewer