2012-11-08

Go



這篇記錄最近一個多月學習 Go 的心得。Go 的語法相對於 Object-C 簡潔,後置的資料型態變數宣告,可以懶惰省去資料型態宣告。

有兩件事情是我碰壁許久:

json.Marshal



執行結果會得到:


p1 is: {"FirstName":"John","LastName":"Doe"}.
p2 is: {}.


要輸出的成員變數必須大寫開頭才行,下面的 package 方法同樣套用。


Exported Functions


隨意撰碼都需要模組分割,追問題容易,讀碼速度快。Go 使用資料夾結構定義 package 封裝,捨棄 MakefileHow to Write Go Code 闡述如何做到模組化,所有細節皆有提到就是 Function name 首字要大寫沒提到[1],所以一直看到

./main.go:10: cannot refer to unexported name foo.foo1

程式碼如下:

foo.go

main.go

這是最近的心得。


Updated:
1. 在 The Go Programming Language Specification 的 Exported identifiers 有提到這些細節。

2012-05-09

Toggle network for iOS Simulator

Network fault-tolerant is important to asynchronous request. For iOS simulator can not toggle the network easily, because of its network ability is binding to its level. So that if you turn your host network off, then your iOS simulator network is also down. However, the host lost all network connection.

The firewall rule can help me do that smart, just block the site and port you would. You can use the below script:



You can change the host you want block in line 3 banHost.

2012-04-24

Git hooks Xcode version

Xcode has two fields to set version information to app. Version is for releasing number, build is for building number, find more information in Information Property List Key Reference.


Since Xcode 4.0 starting to support git version control, so that we could bind git tag and commit hash text with Xcode field. The steps in the pseudo-code are below:


  1. $ git commit -am "COMMIT LOG"
  2. trigger post-commit hooking
  3. Setting the tag number and new commit hash to plist.


In the real code is like below:


Put the code in a file to PROJECT_FOLDER/.git/hooks/post-commit, and make it executable.

2012-04-19

TEPopUp uses resizableImageWithCapInsets



TEPopUp show a pop-up view that stands on a translucent view, it can add something in the dialog view easily.


TEPopUp dialog use the api, UIImage resizableImageWithCapInsets:, it needs not a full size picture as its background picture, instead of a 28x28 pixel small picture. Obviously, this technical can reduce the who app size. The main core code cuts the area of pattern image, from the center point to right-bottom corner by UIEdgeInsetsMake. Then, the UIImage returns a new instance thats already expand image to appropriate size.

2012-01-10

UIScrollView 卡關排解

因為卡了三次,特別提醒自己。

若要做成兩頁,則 contentSize 要涵蓋兩頁寬度。