Swift 入門指南 V1.00 - 單元 26 - 完成版的 Encryptor

Swift 入門指南 V1.00 - 單元 26 - 完成版的 Encryptor

剩下兩個還沒實作的方法 (method) 為 copyMethod() 及 clearMethod() ,程式如下

其中 clearMethod() 比較簡單,就是把 e 設定為 nil ,其他兩個文字欄位跟兩個屬性 (property) 都設定成空字串 (empty string) ,也就是把全部的設定歸零,重回啟動程式時的模樣。
至於 copyMethod() 則是利用 NSPasteboard 的 generalPasteboard() 建立與系統剪貼簿相通的 pasteBoard 物件 (object) ,先呼叫 clearContents() 方法清空剪貼簿的內容,再用 writeContents() 將編碼結果寫入系統剪貼簿。
來試看看囉

編碼結果貼上到「文字編輯」中

Clear 就全部清除了

這樣七個按鍵的功能都完成了,倒是還有些小遺憾,像是標題列應該要改一下,這要到 Storyboard 的地方,選取 Window 的圖示,然後右側屬性有設定 Title 的輸入欄位

這裡改成 Encryptor

然後屬性 output 是用來放輸出結果的,預設可以輸入任何文字,這裡我們一樣到屬性欄找到 Behavior ,從 Editable 改成 None

這樣 output 就會鎖起來了,重新執行結果如下

EncryptorMacOS 專案到此全部完成,下一個單元我們將其輸出成 Mac OS 的 App 。
中英文術語對照
方法 | method |
屬性 | property |
空字串 | empty string |
物件 | object |
訂閱:
張貼留言 (Atom)
window.___gcfg = { 'lang': 'zh-TW' };
沒有留言:
張貼留言