




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、OverViewCocoa開發(fā)現(xiàn)狀ReactiveCocoaMVVMDemo使用經(jīng)驗(yàn)Cocoa開發(fā)現(xiàn)狀需要考慮的情況是否已經(jīng)登錄是否已經(jīng)贊過贊的過程中不能操作與服務(wù)端交互完成后改變贊的狀態(tài)- (void)likeButtonTappedif (self.hasLoggedIn) else / popup a login view- (void)likeButtonTappedif (self.hasLoggedIn) if (!self.isLiking) else/ popup a login view- (void)likeButtonTappedif (self.hasLoggedIn)
2、 if (!self.isLiking) if (self.hasLiked) else else/ popup a login view-(void)likeButtonTappedif (self.hasLoggedIn) if (!self.isLiking) if (self.hasLiked)self.isLikingself.api=YES;plete:self.isLiking = NO; self.likeButton.highlighted = NO;plete: else self.isLiking = YES; self.apiself.isLiking = NO;sel
3、f.likeButton.highlighted = YES; else / popup a login viewStateThe Art of Unix Programming“編程的本質(zhì)是控制復(fù)雜度”State能有效增加復(fù)雜度BOOL visible;2 statesBOOL enabled;4 statesBOOL highlighted;8 statesBOOL selected;16 statesState是一種緩存“There are only two hard things in Computer Science: cache invalidation and naming th
4、ings”Phil Karlton如何消滅/減少State?搞定產(chǎn)品經(jīng)理只做簡單的App改行換一種編程思路?ReactiveCocoa走出舒適區(qū)Shunryu Suzuki“In the beginners mind there are many possibilities, in the experts mind there are few.”Input - Process - OutputInput鍵盤輸入點(diǎn)擊手勢(shì)操作網(wǎng)絡(luò)請(qǐng)求磁盤DelegatetableView:didSelectRowAtIndexPathBlock Callbackplete:(NSArray*)-Actionlog
5、outButtonTapped:TimerstimerWithTimeInterval:selector:userInfo:repeats:KVOOutputUI的變化Model的變化網(wǎng)絡(luò)請(qǐng)求CrashSignalviewWillAppearuserLoggedInfetchLatestData&CombineLatestRACSignalcombineLatest:viewWillAppearSignal, loggedInSignal subscribeNext:(id x) / fetch latestdata;networkErrorserverErrorpresentError|me
6、rgeRACSignalmerge:netErrorSignal, serverErrorSignal subscribeNext:(id x) / present Error;filtermapanyNumberSignal filter:BOOL(NSNumber *number) return number intValue % 2;&|&mand通常用來表示某個(gè)Action常常跟UIControl綁定使用有幾個(gè)重要屬性executingexecutionSignalserrorsMVVMMVVMDemoRACObserve(self, shouldPopLoginView) subsc
7、ribeNext:(id x) / pop up login view;RAC(self, likeButton.highlighted) = mand.executionSignalsswitchToLatestmap:id(id value) / handle result return YES; / or NO;self.mand = mand allocinitWithEnabled:mand.executing not signalBlock:RACSignal *(id input) if (!self.hasLoggedIn) self.shouldPopLoginView =
8、YES;mand execute:nil; else return nil;登錄用戶名登錄登錄用戶名登錄RAC(self.loginButton, enabled) = formValid;RACSignal *formValid = RACSignalcombineLatest: self.usernameField.rac_textSignal, self.passwordField.rac_textSignal,reduce:(NSString *name, NSString *password) return name.length & password.length;登錄用戶名登錄R
9、ACSignal *textColor = executing map:(NSNumber *x) return x.boolValue ? gray : black;RAC(self.usernameField.textColor) = textColor; RAC(self.passwordField.textColor) = textColor;RACSignal *notProcessing = executing map:(NSNumber *x) return (!x.boolValue);RAC(self.usernameField.enabled) = notProcessin
10、g; RAC(self.password.enabled) = notProcessing;iPhotoiPhotoRACObserve(viewModel, indexPath) subscribeNext:(NSIndexPath *indexPath) self.collectionViewscrollToItemAtIndexPath:indexPath;CellViewModel *cvm = viewModel.cellViewModelsindexPath.row;cvm.active = YES; CellViewModel *lastActiveCVM =viewModel.
11、lastActiveCellViewModel;lastActiveCVM.active = NO;viewModel.lastActiveCellViewModel = cvm;iPhoto- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView/ 根據(jù)scrollView算出indexPath viewModel.indexPath = indexPath;- (void)collectionView:(UICollectionView *)collectionViewdidSelectItemAtIndexPath:(
12、NSIndexPath *)indexPath/ 處理viewModel.indexPath = indexPath;注意事項(xiàng)使用經(jīng)驗(yàn)解題思路性能調(diào)試內(nèi)存使用sendNextScheduler使用property還是signalProperty TableView的處理RAC在花瓣的使用場景解題思路百思不得解想到法,但好像不夠RAC算了,時(shí)間有限,還是回到熟悉的編程模式吧性能subscribeNext很慢,比純KVO慢了1個(gè)數(shù)量級(jí)接收到變化比較慢,比純KVO慢了大約5倍調(diào)試signal subscribeNext:(id x);調(diào)試signal subscribeNext:(id x);sendNext由于ObjectiveC語言的限制,無法得知next的值到底是哪種類型,使用起來略有不便,需要看注釋/代碼,才能知道傳的是什么值,然后手動(dòng)轉(zhuǎn)一下。SchedulerdeliverOn:subscribeOn:使用property還是signalProperty如無必要,使用正常的property即可,外部可以對(duì)它RACObserve或KVOTableView的處理把每個(gè)TableViewCell視為一個(gè)獨(dú)立的View,也給它提供一個(gè)cellViewModel,而這個(gè)c
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- GB/T 23595.7-2025LED用稀土熒光粉試驗(yàn)方法第7部分:熱猝滅性能的測(cè)定
- 外貿(mào)合作合同協(xié)議書樣本
- 教學(xué)計(jì)劃執(zhí)行情況
- 餐飲店承包經(jīng)營合同模板
- 科技成果轉(zhuǎn)化知識(shí)產(chǎn)權(quán)共享合同范文
- 標(biāo)準(zhǔn)離婚合同范本:輕松擬定離婚協(xié)議
- 標(biāo)準(zhǔn)版臨時(shí)工勞動(dòng)合同模板
- 租賃設(shè)備的標(biāo)準(zhǔn)合同范本
- 8《大自然謝謝您》教學(xué)設(shè)計(jì)-2023-2024學(xué)年道德與法治一年級(jí)下冊(cè)統(tǒng)編版
- 八年級(jí)語文下冊(cè)教學(xué)總結(jié)
- 《學(xué)寫文學(xué)短評(píng)》課件 高中語文統(tǒng)編版必修上冊(cè)
- 《中藥的性能》課件
- 大型商業(yè)綜合體消防安全管理規(guī)則培訓(xùn)
- GB/T 44569.1-2024土工合成材料內(nèi)部節(jié)點(diǎn)強(qiáng)度的測(cè)定第1部分:土工格室
- 《傳承非遺手藝》 教案 2024-2025學(xué)年湘美版(2024)初中美術(shù)七年級(jí)上冊(cè)
- 建筑總工程師招聘面試題與參考回答2025年
- 2024年地理知識(shí)競賽試題200題及答案
- 中國西安旅游行業(yè)市場全景調(diào)研及未來趨勢(shì)研判報(bào)告
- 中債違約債券估值方法(2020年版)
- 《經(jīng)典常談》課件
- 四川省2024年中考數(shù)學(xué)試卷十七套合卷【附答案】
評(píng)論
0/150
提交評(píng)論