fb-script
2017年5月8日 星期一
簡化 UIView 動畫串接 (使用 Swift 3)
一般來說在使用 UIView.animate 要做動畫串接時,最無腦就這樣用
2016年11月3日 星期四
2016年10月26日 星期三
2016年9月11日 星期日
CoreData with swift 2 筆記 - Migration (2) 「半自動」Mapping File and Migration Policy
接上一篇,這次筆記「半自動」模式,計畫如下:
1. 建立一 Use Core Data 專案
2. 建立 Person Entity
3. 在 Person 建立 fullname 欄位
4. 簡單的先在自動產生的 ViewController 中加入一比資料,以空格分開 firstname 和 lastname
5. 首次執行並確定資料新增
6. 刪除新增資料的程式碼
7. 建立一新版本的 Data Model:Model2
8. 在 Model2 中將 fullname 欄位刪除,並加入 firstname 和 lastname 欄位
9. 建立 Model1 到 Model2 的 Mapping File
10. 建立 fullname 欄位的 Migration Policy File:將 fullname 依照空格拆為 firstname 及 lastname
11. 將 Migration Policy 設定給 Mapping File
12. 設定 options 啟動 NSMigratePersistentStoresAutomaticallyOption
13. 第二次執行並確認 .sqlite schema 和資料有成功變更
2016年9月9日 星期五
CoreData with swift 2 筆記 - Migration (1) 「全自動」lightweight migration
承接上一篇,當 NSPersistentStoreCoordinator 在做 addPersistentStoreWithType 時,會將 .sqlite 檔和 data model 做 ORM 的動作,可是如果該 .sqlite 內資料庫的資料和 data model 對不上的時候會怎樣?這種情況會發生在裝置已經安裝過 APP 了,而專案的 data model 有做了變更,使得 data model 和 .sqlite 的內容對不上,此時在預設自動產生的程式碼中,就會將錯誤列出來並呼叫 abort() 將 APP 結束
do {
try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
} catch {
// Report any error we got.
// ...
abort()
}
不解決了話, APP 要馬就是不能更新 data model,要馬就是瘋狂的 Crash…
2016年9月3日 星期六
CoreData with swift 2 筆記 - Xcode 自動生成程式碼
- 假設專案名稱叫做
CoreDataBloggerDemo,在專案創建的時候有勾選Use Core Data的條件下的解析 - 從 xcode 自動生成的 Core Data 程式碼的
// MARK: - Core Data stack以下開始
這段程式碼是自動生成在
AppDelegate.swift中,所以要做存取都要使用此物件來存取,獲得此物件方式為
(UIApplication.sharedApplication().delegate) as! AppDelegate
2016年9月1日 星期四
CoreData with swift 2 筆記 - 創建
CoreData 創建
在新建專案的時候,勾選Use Core Data的選項
- 有沒有勾選這個選項主要差異有兩點,如果有勾選了話
- 1.在 AppDelegate.swift 中會自動產生
// MARK: - Core Data stack之後的程式碼,主要是在建立 PersistentStoreCoordinator 和 ManagedObjectContext 物件 - 2.會自動創建
專案名稱.xcdatamodelId的檔案
2015年10月21日 星期三
iOS swift 2 使用 CocoaAsyncSocket 建立 TCP byte array 通訊
AsyncSocket 下載位置
因為專案是 swift 專案,要使用 objecitive-c 的函式庫要在 Header 檔中 import
1.複製AsyncSocket.m 及AsyncSocket.h 到專案中,xcode 會問你是否建立 Bridge file,確定建立
2.在 你的專案名稱-Bridging-Header.h檔中加入#import "AsyncSocket.h"
3.建立連線物件var socket: AsyncSocket = AsyncSocket(delegate: 委派對象)
2015年10月20日 星期二
iOS NSData 轉 UInt8 array
extension NSData {
func getByteArray() -> [UInt8]? {
var byteArray: [UInt8] = [UInt8]()
for(var i = 0;i < self.length; i++) {
var temp: UInt8 = 0
self.getBytes(&temp, range: NSRange(location: i, length: 1))
byteArray.append(temp)
}
return byteArray
}
}
iOS CoreBluetooth swift 2 連線客製化藍芽 BLE 模組 - ( 3 ) 通訊
終於到的這個階段
這階段主要目的是要得知哪幾個特徵值是和客製化藍芽裝置通訊的介面,在上一階段可以看到每個 characteristic 的 property 屬性有些一權限,例如 Read / Wirte / Notify … 等等
2015年10月19日 星期一
iOS CoreBluetooth swift 2 連線客製化藍芽 BLE 模組 - ( 2 ) 連線
要和藍芽裝置進行連線,需要幾個物件來實作
1. 掃描到藍芽裝置時的 centralManager
2. 藍芽裝置的 peripheral
所以先加入一個新的 ViewController 在點擊 tableView 的時候去切換 segue,並把 centralManger 和要連線的藍芽 peripheral 送過去
這邊建立一個 BTDeviceConfigViewController 的 ViewController 和對應的 storyboard 視圖
2015年10月12日 星期一
iOS CoreBluetooth swift 2 連線客製化藍芽 BLE 模組 - ( 1 ) 掃描
1.先拉一個 UIViewController 並用 NavigationController embed 起來,在 Navigation Bar 上面加個 title 和 UIBarButtonItem,這邊是選擇 Refresh 的 System Item 樣式,並且在剩下的範圍加上一個 UITableview 當作掃描後顯示藍芽裝置的列表

iOS CoreBluetooth swift 2 連線客製化藍芽 BLE 模組 - ( 0 ) 大綱
使用 CoreBluetooth 連線可以大致分為幾個步驟
- 1.掃描
- 這個步驟主要是掃描周邊有哪些藍芽裝置,在這個步驟會拿到藍芽裝置的 UUID、Name、RSSI 和是否可以連線
- 2.連線並獲得服務資訊
- 選定某個裝置連線後,獲得該裝置所提供的服務(CBService),並使用服務獲得可以對藍芽裝置做 io 的特徵值(CBCharacteristic)
- 3.找出可以寫入裝置的特徵值
- 依照特徵值的屬性或UUID來判斷那個特徵值可以寫入給藍芽模組
- 4.找出可以獲得裝置回傳的特徵值
- 依照特徵值的屬性或UUID來判斷那個特徵值獲得模組的 Notify 事件
2015年9月19日 星期六
iOS平滑移動切換 ViewController,使用 Storyboard、ScrollView、Container View、AutoLayout
這次要介紹一個讓 ViewController 之間像平滑移動相片的方式來切換顯示的方法
首先、先建立一個空白的專案,使用 SingleViewProject
1.建立專案