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
| class AVC: UIViewController { | |
| weak var delegate: AVCDelegate? | |
| // TODO: implement | |
| func hello() { | |
| // 請 Main 幫忙做點事 | |
| self.delegate?.somethingFromA(self) | |
| } | |
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
| /// 範例中使用了 SVProgressHUD, SwiftyJSON | |
| /// 另外 UIAlertController 有 extension | |
| func request(_ path: String, method: HttpMethod = .get, parameters: [String: Any]? = nil, localizedStatus: String? = NSLocalizedString("資料處理中", comment: "呼叫API讀取狀態文字"), _ completion: @escaping (_ json: JSON) -> Void) { | |
| // 顯示 ActivityIndicator | |
| if let status = localizedStatus { SVProgressHUD.show(withStatus: status) } | |
| // 待會使用 GCD 版本所以要 Dispatch 到其他 thread | |
| DispatchQueue.global().async { | |
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
| import Foundation | |
| import UIKit | |
| print("==== Basic ====") | |
| // Automatic Reference Counting | |
| class A { | |
| func hello() -> String { | |
| return "world" |
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 requestSync(_ path: String, method: HttpMethod = .get, parameters: [String: Any]? = nil, localizedStatus: String? = nil) -> JSON? { | |
| var out: JSON? | |
| let semaphore = DispatchSemaphore(value: 0) | |
| self.request(_ path, method: method, parameters: parameters, localizedStatus: localizedStatus) { (json) in | |
| out = json | |
| semaphore.signal() | |
| } |
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
| // 就上面的案例重組一下 | |
| import UIKit | |
| struct FilmFestival { | |
| var Name: String = "" | |
| var FormattedPrice: Int = 0 | |
| } | |
| struct Ticketing { | |
| var Name: String = "" | |
| var FormattedPrice: Int = 0 |
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
| // | |
| // CropperView.swift | |
| // Gotyou | |
| // | |
| // Created by 默司 on 2016/12/15. | |
| // Copyright © 2016年 默司. All rights reserved. | |
| // | |
| import UIKit |
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
| // | |
| // NSObject.swift | |
| // QBDemo01 | |
| // | |
| // Created by 默司 on 2016/12/2. | |
| // Copyright © 2016年 默司. All rights reserved. | |
| // | |
| import Foundation |
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
| import Foundation | |
| struct User { | |
| var username: String? | |
| var password: String? | |
| } | |
| extension User { | |
| init(_ node: NodeAccessable) { | |
| self.username = node.child("username").string |
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
| // | |
| // Deserializable.swift | |
| // MapperDemo | |
| // | |
| // Created by 默司 on 2016/12/1. | |
| // Copyright © 2016年 默司. All rights reserved. | |
| // | |
| import Foundation | |
| import SwiftyJSON |
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
| // | |
| // BorderDesignable.swift | |
| // Gotyou | |
| // | |
| // Created by 默司 on 2016/11/28. | |
| // Copyright © 2016年 默司. All rights reserved. | |
| // | |
| import Foundation | |
| import UIKit |