2013年12月25日 星期三
2013年12月16日 星期一
[iOS] posing class
看到了一個有趣的少用的技術 posing
http://www.tutorialspoint.com/objective_c/objective_c_posing.htm
http://www.cnblogs.com/IT-Chris/archive/2013/03/10/2953176.html
裡面提到
hmm.... 在某些情況下確實可以用用看
可以很輕鬆的阻斷加入要做的事情@@
2013年11月16日 星期六
[iOS] Web api with CoreData
像是 AFIncrementalStore
但是其實我沒有用過
現在也沒有空去改用
原因是.... 遇到太多的廠商開的api是在亂七八糟....
因此還是得自己針對案子去設計model
不過最近遇到下面的問題
-> 當 api 有 paging的功能,卻設計了一個 infinite scroll view
一般來說我常用的作法是
api -> 接到的data 直接存在 CoreData中
view -> 透過 NSFetchedResultsController 拿 CoreData的資料
但是如果加上了 page呢?
page意味著說每頁的資料在每次拿可能都不一樣
api 是"一頁一頁"的呈現資料
但是 UI 設計的是一個 infinite scroll view
並不會知道轉到了哪一頁(往往後端又想保留每頁可以動態調整資料數量的權力),即便是每個資料都有id
例如cache了10的資料,
當下次在開啟時,api 應該要更新哪些資料?第一頁?一到十頁?
似乎都不太對,
因此,試想了一下規則
1. 用一個Global 變數去儲存該api 已經拿到第n的頁數 (假設頁數為連續)
2. 離開app時(或剛進入app時),清除掉所有跟page api 有關的object
3. 如果設計需要,在離開該頁面時,清除掉所有跟page api 有關的object
造成的結果會是
在這次開啟app的狀況下,使用者會看到cache的結果,頁面資料只會拿一次(不會更新資料,因為global 變數去記錄該api已經拿到第幾頁)
在下次開啟該app 則會清除上次看過的資料,然後重新向server拿新資料
這樣應該可以解決大部分的問題吧
[iOS] Core Data 的 思
https://github.com/robbiehanson/XMPPFramework
XMPPFramework / Extensions / CoreDataStorage
中得到想法或靈感
其中比較重要的是
他利用多執行續去執行 core data (在 apple 的guide line 中其實不建議用多執行續去做)
我將這個方法套用在我現在的專案上
1. model control 動作後,會呼叫 sub thread 上的 NSManagedObjectContent (moc) 做動作
2. VC 上,用的是 Main thread moc 產生的 NSFetchedResultsController 來操縱 View
一開始看起來都還ok
不過最近卻發現一些問題
2013年9月22日 星期日
2013年6月28日 星期五
[Obj-C] Thread Synchronization
有空在好好看一下
http://nextstep.sdf-eu.org/clocFAQ/#sync
基本上應該還是會用到
畢竟multi-thread的狀況會很多
不過可能要去了解一下其他advanced threading concepts
2013年6月5日 星期三
2013年5月30日 星期四
[iOS] CGContextShowTextAtPoint & non-ASCII
由於 CGContextShowTextAtPoint 不能畫出 非ascii的字
所以只能用 NSString drawAtPoint...
不過換過去之後記得要
在 drawAtPoint 前後夾上
UIGraphicsPushContext(_composedImageContext);
[text drawAtPoint:(CGPointMake(0, expectedLabelSize.height / 2.0)) withFont:[UIFontfontWithName:fontName size:60.0]];
UIGraphicsPopContext();
把畫紙推到最前面去畫 然後再推回來
2013年5月11日 星期六
[Obj-C] 保留字的介紹
http://www.learn-cocos2d.com/2011/10/complete-list-objectivec-20-compiler-directives/#encode
下次應該會思考一下 @defs & @encode用的時機....
[Obj-C] Obj-C Optimization: IMP Cacheing Deluxe
http://www.mulle-kybernetik.com/artikel/Optimization/opti-3-imp-deluxe.html
看到一些技法
如果跳過直接使用 CF function
似乎就可以快很多....
(toNOTE 裡面的一些迴圈處理似乎可以用這個加速)
[Obj-C] private
http://stackoverflow.com/questions/2158660/why-doesnt-objective-c-support-private-methods
英文不好 要花點時間看.... orz
不過討論 private 與 public 感覺是有趣的 XD
2013年4月19日 星期五
[iOS] Core Data - Data type - allow external Stroge
http://bluecrowbar.com/blog/2011/08/coredata-external.html
如果遇到儲存資源可能會比較大的話
就需要勾選
他會幫你處理,如果data太大,他會自動用file system 作檔案,然後關聯到uri,以避免直接存入DB中
2013年4月10日 星期三
didReceiveMemoryWarning for 5 & 6
- (void)didReceiveMemoryWarning; // Called when the parent application receives a memory warning. On iOS 6.0 it will no longer clear the view by default.
……. 看來對於 iOS 5.x 還有多餘的方式要處理了
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
if ([self isViewLoaded] && [self.view window] == nil)
{
// Add code to preserve data stored in the views that might be
// needed later.
// Add code to clean up other strong references to the view in
// the view hierarchy.
self.view = nil;
}
最近才知道 iOS 6.x 要加入這些code
然後Xcode還不會自動產生 = ="
不過遇到了一些詭異的問題....
iOS 5.x 在某些狀況下 wm兩次會crash....
還不知道發生了什麼事情orz
2013年3月31日 星期日
[ObjC] objc_setAssociatedObject
之前遇到的問題是 …… Category 怎樣新增變數在物件中....
我那時只知道 dynomic … 然後就不知道下一步了
今天看到別人分享了這個
https://github.com/MugunthKumar/UIKitCategoryAdditions
想說之前就有遇到因為static 所以同時間只能使用一個Alert的問題
不過看來他10個月前就改好了orz....
anyway 重點是...
objc_setAssociatedObject
之後如果有遇到類似需求會用這個做作看
不過還有一點不是很清楚
其中第二個param 建議是用一個static的char值,看到到有討論區的說法是他只是指標位置
還是不了解如果當實體化兩個物件時,還是會共用到同一個static的值,會互相影響到嘛?