2015年12月22日 星期二

用xib換掉storyboard

一、先到info.plist中把Main storyboard file base name這個tag拿掉

二、再到appDelegate的didFinishLaunchingWithOptions中加入rootViewController
例如
let navigationVC: UINavigationController = UINavigationController(rootViewController: yourViewController)
        
let frame = UIScreen.mainScreen().bounds
window = UIWindow(frame: frame)
        
window!.rootViewController = navigationVC
window!.makeKeyAndVisible()

2015年12月2日 星期三

是否需要在用來建TableView Cell的xib中指定file's owner?

不用,
xib是一個圖形與程式的連接控制介面,xib裡面放的UI物件,
file's owner是外部的控制器,所以你的cell不能在xib裡面跟外面同時存在。

意思是,你在xib裡面直接拉UI (cell也是一種UI)
外面用view controller指給file's owner來存取使用。

將狀態列文字改為白色(iOS 7.0以上適用)

先到info.plist中新增一行View controller-based status bar appearance 並設為 no

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent

2015年7月27日 星期一

為何int的負數會比正數多1

因為C語言中做了一個規定
當最高位的bit為1而其他都為0的時候,這個1既表示負號又表示它的數值。
以32bit為例,有號數的int範圍為
正: 2147483647 ~ 0  負: -1 ~ -2147483648

如此定義有二個好處,
一是計算方便,當你用2的補數往上做加法時,可以直接依二進制計算,不用另外調整正負號。
二是避免重覆定義0, 因為+0跟-0是同一個數,不需要分正負。

2015年7月24日 星期五

使用之前的cookie

//儲存
let urlEnconded = sessionId!.stringByAddingPercentEncodingWithAllowedCharacters(
                NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]").invertedSet)!
            let properties = [NSHTTPCookieDomain: WebURL.URL_MIGME_SERVER,
                NSHTTPCookiePath: "\\",
                NSHTTPCookieName: "eid",
                NSHTTPCookieValue: urlEnconded + MigboClient.cookiePrefix]
            if let cookie = NSHTTPCookie(properties: properties) {
                NSHTTPCookieStorage.sharedHTTPCookieStorage().setCookie(cookie)
                System.setShareProperties(DefaultConfig.SHARE_SYS_COOKIES, value: properties)

            }

//使用
var url = NSURL(string: "yourUrl")
mutableRequest = NSMutableURLRequest(URL:url)
var cookies = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as! [NSHTTPCookie]
var headers = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies)
mutableRequest!.allHTTPHeaderFields = headers

self._webview.loadRequest(mutableRequest ?? NSURLRequest(URL:url))

2015年7月22日 星期三

String pool 概念

String Pool是為了解決太多內容同樣的String物件,造成記憶體空間浪費的問題,
實作上建立了一個hashMap,把字串內容轉換為key值來查找String物件實體,如果有則拿來用,如果沒有才new一個新的。

reflection概念


Reflection, 用在 Java 身上指的 是我們可以於執行期載入、探知、使用編譯期間完全未知的 classes。

Java 反射機制 - 侯捷

iOS也可以實現reflection的機制,關鍵字如下:
objc_getClass
objc_property_t
class_copyPropertyList
class_replaceMethod