- 技術
CocoaPods ? 可以試試更輕量的 Carthage
之前在設置新專案的環境的時候, 發現在 Swift 環境下的 CocoaPods, 實在是需要設定蠻多東西的。諸如如果是Objective-C的Library需要設置 Bridge 檔案, 是否為 Swift 環境需要額外增加Flag 參數等等。已經不再是幾行指令加上Podfile就可以搞定環境的美好舊時光。(Xcode 6.3.1 以前的版本, 現在 CocoaPods 還是一樣好用啊!)於是在
- 技術
Swift - CoreBluetooth 藍牙開發
import CoreBluetooth Step2. 實現 CBPeripheralManagerDelegate 需要實現功能 peripheralManagerDidUpdateState , 並將對應的功能填入對應狀態變化的時候。 extension ViewController: CBPeripheralManagerDelegate { &
- 技術
Swift - Animating View Properties 動畫教學
func fade( toImage: UIImage, showEffects: Bool ) { //Create & set up temp view let tempView = UIImageView(frame: bgImageView.frame) tempView.image = toImage tempView.alpha = 0.0 tempView.center.y
- 技術
Swift - Core Data 新增、查詢、刪除、更新
private var appDelegate = UIApplication.shared.delegate as! AppDelegate private let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext 透過 appDelegate.saveContext
- 技術
Swift - 將資料儲存成本地端Json / Plist 檔案
Swift 4簡化了Swift 3中使用的整個JSON壓縮和序列化過程。現在你只需要使自定義類型實現Codable協定 – 它會將Encodable和Decodable兩者結合 – 這樣會讓你的工作更便利 。 機器設定 : Swift4 + iOS11 + Xcode9 public struct Sticker: Codable { public init( name: String, birt
- 技術
Swift - 如何在本地端儲存 & 讀取資料
本地端儲存以及讀取資料, Swift 是透過FileManager來做存取以及讀取的動作,本機端資料因為iOS 採用 Sandbox架構的緣故, 可使用來作為讀/存檔案的資料夾為Document。 所以第一步 找到 Document資料夾的 URL 機器設定 : Swift4 + iOS11 + Xcode9 import Foundation public extension FileManag
- 技術
[Swift] - Clousure cheatsheet
Note: if the passed-in closure is going to outlive the scope of the method, e.g. if you are saving it to a property, it needs to be annotated with @escaping.
- 技術
Swift — @escaping
在 Swift 3 中, closures 預設為 @noescape 的形式, 並將 Swift 2中的 noescape 關鍵字 deprecated。
- 技術
Swift - for用法
for用法: for迴圈是控制項的重要功能, 主要是用來控制重複性的運算以及功能。 機器設定 : Swift4 + iOS11 + Xcode9 瞭解for用法前, 先讓我們了解一下 Range ( ... ) Range let closedRange = 0...5 let halfOpenRange = 0..<5 closedRange 代表著 0 -5 (包含) halfOpenR
- 技術
Swift — inout 關鍵字
如果你想要一個函數可以修改參數的值,並且想要在這些修改在函數調用結束後仍然存在,那 麽就應該把這個參數定義為輸入輸出參數(In-Out Parameters)。
- 技術
Swift — Regex
func Matches(for regex: String, in text: String) -> [String] { do { let regex = try NSRegularExpression(pattern: regex) let nsString = text as NSString let results = regex.matches(in: text, range:
- 技術
Swift - tuple用法
機器設定 : Swift4 + iOS11 + Xcode9 tuple用法: Tuple 是輕量化的 struct,常用於傳遞個數大於一的值組。 tuple的用法如下 如果有用過 C++/Python的 tuple, 對於Swift的tuple 應該不陌生, tuple 賦值 let coordinates = (2, 3) let coordinatesDouble = (2.3, 3.5)
- 技術
Swift - UINavigationController 如何放大標題
機器設定 : Swift4 + iOS11 + Xcode9 UINavigationController 有內建參數可以將標題放大 [caption id="attachment_315" align="alignnone" width="368"] 標題 - Before[/caption] &n
- 技術
Swift — ?? 空合運算符
let defaultColorName = “red”