2017年3月27日 星期一

Swift : Let & Var, ! & ? Optional (Wrapped & unwrapped) 驚嘆號 問號

發現以單一功能性app的小型開發學習法,過於缺乏系統性與效率,於是在網路上找到了CS193P這個課程,我打算上完這一系列的課程,並且在學習過程中持續複習C++的資結。

這個課程可以在iTune U找到且免費。其包含了所有課程 slides & homeworks,我也將會全部完成。

Let. 1 notes:

  • Let & Var
The let keyword defines a constant:
let theAnswer = 42
The theAnswer cannot be changed afterwards. <-- This is why anything optional or weak can't be written using let. They need to change during runtime and must be wrote using var.
The var defines an ordinary variable:
What is interesting:
The value of a constant doesn’t need to be known at compile time, but you must assign it a value exactly once.
Another strange feature:
You can use almost any character you like for constant and variable names, including Unicode characters:
let 🐶🐮 = "dog cow"
credit: community wiki @stackoverflow 
  • ! & ? Optional (Wrapped & unwrapped)
In a type declaration the ! is similar to the ?. Both are an optional, but the ! is an "implicitly unwrapped" optional, meaning that you do not have to unwrap it to access the value (but it can still be nil).
This is basically the behavior we already had in objective-c. A value can be nil, and you have to check for it, but you can also just access the value directly as if it wasn't an optional (with the important difference that if you don't check for nil you'll get a runtime error)
// Cannot be nil
var x: Int = 1

// The type here is not "Int", it's "Optional Int"
var y: Int? = 2

// The type here is "Implicitly Unwrapped Optional Int"
var z: Int! = 3

Usage:

// you can add x and z
x + z == 4

// ...but not x and y, because y needs to be unwrapped
x + y // error

// to add x and y you need to do:
x + y!

// but you *should* do this:
if let y_val = y {
    x + y_val
}
credit: Jiaaro  

Swift GitBook about Optional
  • Computed properties 
我自己程式中的應用:
    var displayValue: Double {
        get {
            return Double(display.text!)!
        }
        set {
            display.text = String(newValue)
        }
    }
當使用displayValue 時,判定其作用在於get值或是set值,並且進行相對應的implementation,像是回傳一個casting完的值,或是將特定值casting完並輸出。此處的newValue是個需要注意的特殊用法,代表任何與本函數同樣性質的物件(?)

supplement:
useful materials


2017年3月24日 星期五

iOS app: toDo list

今天要做簡單的toDo list。

  • Process:

Add constrains 
Prototype cell 
datasource & delegate option on table view
self (in a closure)
let vs var
append

what's a delegate?
override?

集合:UITableViewDelegate / UITableViewDataSource
功能:UITableViewDataSource : 
numberOfRowsInSection, 
cellForRowAt, 
commit editingStyle(左滑刪除鍵),
viewDidAppear

  • Demo:



  • tips:

command + ' / ' :快速鍵整行註解
command + ' [ ' or ' ] ' :快速鍵整行左右縮排

  • 思考點

科技業第一個工作的重要性、影響性?

2017年3月23日 星期四

iOS: info.plist, Mac's structure, API

今天遇到的問題:


  • info.plist:
An information property list file is a structured text file that contains essential configuration information for a bundled executable. 
所謂的 Info.plist 就是專案內一個已經結構化好的資料清單,其中存放該專案最基本的設定資料以及相關參數,當然使用者也可以透過 Add Row 來增新欄位添加資訊。

plist常用選項介紹
empty app 建立方式 git
empty app 建立方式 git 直接嵌入

  • Mac's structure:
credit: 黑麥克
  • API:
應用程式介面英語:Application Programming Interface,簡稱:API),又稱為應用編程介面,就是軟體系統不同組成部分銜接的約定。由於近年來軟體的規模日益龐大,常常需要把複雜的系統劃分成小的組成部分,編程介面的設計十分重要。程式設計的實踐中,編程介面的設計首先要使軟體系統的職責得到合理劃分。良好的介面設計可以降低系統各部分的相互依賴,提高組成單元的內聚性,降低組成單元間的耦合程度,從而提高系統的維護性和擴充功能性。(wiki)


簡單來說 API大都以library和function的形式存在,但這些function是別人設計給大家用的,目的是讓大家更容易開發軟體,而別人 = 系統、平台、環境提供者。
所以Microsoft寫了Windows API 方便大家寫win程式HTML5要求各瀏覽器提供api 讓網頁開發者可以透過瀏覽器去做更多底層的事情 像是檔案讀寫。 (ptt: StarTouching)

  • Core Data:
Core Data 是一個儲存資料的框架,它的底層本質上還是使用 SQLite 資料庫,它提供簡單易用的方式讓你儲存資料,而不用撰寫複雜的 SQL 語法。如果你的專案有使用 Core Data,可以在該 App 的 Document 目錄中找到 sqlite 檔案。

Core Data 是以空間換取時間,意思是比較佔記憶體空間,但速度比較快;另外一個好處是,使用 Core Data 的程式碼比較簡單易讀,不會有複雜的 SQL 語法,官方的說法是,會減少 50~70% 的程式碼。 (credit: TonyCube)

2017年3月21日 星期二

初步學習計畫_170322

目前的想法是分為兩個主軸:個人喜好以及基礎實力

基礎實力的部分,由之前考資工所的範圍進行複習,並且更加注重實作與應用。

個人喜好的部分,就由自己專案主題所需要的能力去進行海綿式學習。在那之前,先搞清楚terminal, scratch, dev tool , git等基礎工具,是首要目標。

as Huli said, 學程式學的應該是「心法、內功」,而不是表面的限制

find it hard to start_170322

最近持續累積的除了英文、健身與閱讀外,最想要精進的就是程式語言的實力。
我發現這條自學的路其實並不容易,雖然資源多倒認為時間完全不夠用,但是自學缺乏系統化的學習方式以及時間分配。

而這之間也包含了,我是否要往有興趣的方向,已有明確目的性主題的個人專案去發展,亦或是在求職的要求能力中去找到學習的平衡點?

此時我會想,會不會是亞洲教育底下的線性思維造就了我這份不安的感覺,或許學習一直以來都不該只是線性的,但我仍然認為自己在眾多資源中找尋、探索之下浪費了眾多時間,卻不認為自己有著進步。

完美主義的困境就是常常想了太遠而不去執行,看著遠處“可能的困難”就忘記先踏出了第一步。

我打算開始把每一個學習的過程記錄下來,用微小且持續的累績,來瞭解自己的學習歷程並且加以調整自己的方向。