前言:做爲初級程序員,想要提升本身的水平,其中一個有效的學習方法就是學習別人好的項目。本篇開始會陸續更新本人對github上開源的一個很不錯的項目的一點點學習積累。也就是,探究着別人寫的源碼,我學到了新的什麼東西?本人愚拙,並且碼齡很少,也就三年左右,水平不高,若有挫解,還望指正。本人樂愛學習,樂於分享,廣結良緣,願意交流。固然,高手能夠飄過。html
Coding-iOS項目網址:https://github.com/Coding/Coding-iOS 讀者感興趣的能夠本身去下載,固然項目不少第三方框架是沒有直接集成進來的,讀者自行經過該項目的提示處理。ios
另外還有官網介紹:https://coding.net/u/coding/p/Coding-iOS/git#rdgit
內容概要:程序員
一、關於MobClick,友盟統計的使用github
二、關於Google Analytics緩存
三、關於Debug框架
四、關於RDVTabBarControllerpost
五、關於GCC語法學習
六、關於TMCache的使用網站
七、關於TTTAttributedLabel的使用
正文:
2016年3月21日
文件:BaseViewController.m
一、下面代碼添加友盟統計,設置狀態欄,代碼設置豎屏。
1 - (void)viewWillAppear:(BOOL)animated 2 { 3 [super viewWillAppear:animated]; 4 // hy:友盟統計,https://github.com/liyoro/UMAnalytics 5 // hy:標哥的博客:http://www.henishuo.com/ios-umeng-push/ 6 [MobClick beginLogPageView:[NSString stringWithUTF8String:object_getClassName(self)]]; 7 // hy:設置狀態欄 8 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; 9 10 // hy:若是不是豎屏、不支持豎屏或是橫屏 11 if (self.interfaceOrientation != UIInterfaceOrientationPortrait 12 && !([self supportedInterfaceOrientations] & UIInterfaceOrientationMaskLandscapeLeft)) { 13 // hy:設置成豎屏 14 [self forceChangeToOrientation:UIInterfaceOrientationPortrait]; 15 } 16 } 17 ...... 18 - (void)forceChangeToOrientation:(UIInterfaceOrientation)interfaceOrientation{ 19 [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:interfaceOrientation] forKey:@"orientation"]; 20 }
文件:MobClick.h 是友盟統計的SDK接口文件。具體使用之後補充,先知道這個類是這麼回事。
二、下面代碼中用了Google Analytics。
關於集成這個Google Analytics的SDK學習的網站:https://www.raywenderlich.com/53459/google-analytics-ios (外國網站)
對應的國內翻譯網站:http://www.cocoachina.com/industry/20140108/7674.html
1 - (void)viewDidLoad{ 2 [super viewDidLoad]; 3 self.view.backgroundColor = kColorTableBG; 4 // hy:這裏又代碼設置豎屏 5 if (self.interfaceOrientation != UIInterfaceOrientationPortrait 6 && !([self supportedInterfaceOrientations] & UIInterfaceOrientationMaskLandscapeLeft)) { 7 [self forceChangeToOrientation:UIInterfaceOrientationPortrait]; 8 } 9 // hy:添加了google analytics,Google提供的免費的使用者分析服務 10 // GA 11 id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker]; 12 [tracker set:kGAIScreenName value:[NSString stringWithUTF8String:object_getClassName(self)]]; 13 [tracker send:[[GAIDictionaryBuilder createScreenView] build]]; 14 }
三、下面代碼用了宏定義Debug打印模式
- (void)tabBarItemClicked{ DebugLog(@"\ntabBarItemClicked : %@", NSStringFromClass([self class])); }
而後我command+click跳轉到下面代碼:
1 #define DebugLog(s, ...) NSLog(@"%s(%d): %@", __FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])
而後我就本身建立新的Simple Project使用了一下:
四、文件夾:RDVTabBarController
由於在項目源碼中,RootTabViewController : RDVTabBarController<RDVTabBarControllerDelegate>,因此進一步探索RDVTabBarController,發現這個是第三方框架
並且github上點贊量蠻高的,網址是:https://github.com/robbdimitrov/RDVTabBarController 。記錄之後學習學習該源碼作了什麼?
3月24日:
五、在CodingBannersView.m文件中能夠發現一枚"GCC語法":
六、關於TMCache的使用:
在Coding-iOS這個項目中,經過pod集成了TMCache這個框架,因而我就對這個框架進行了瞭解:
TMCache的github地址:https://github.com/tumblr/TMCache
TMCache 是 Tumblr 公司開發的一個快速,無死鎖的並行對象緩存,支持 iOS 和 OS X 系統。
示例代碼:
UIImage *img = [[UIImage alloc] initWithData:data scale:[[UIScreen mainScreen] scale]];
[[PINCache sharedCache] setObject:img forKey:@"image" block:nil]; // returns immediately
[[PINCache sharedCache] objectForKey:@"image"
block:^(PINCache *cache, NSString *key, id object) {
UIImage *image = (UIImage *)object;
NSLog(@"image scale: %f", image.scale);
}];
不過如今已經中止更新了。
而後再來看Coding-iOS這個項目中的一個TMCacheExtend.h和TMCacheExtend.m文件。
1 #import <Foundation/Foundation.h> 2 #import "TMCache.h" 3 4 @interface TMCache (Extension) 5 6 + (instancetype)TemporaryCache; 7 + (instancetype)PermanentCache; 8 9 @end
1 #import "TMCacheExtend.h" 2 3 #define kTemporaryCache @"com.dv.cache.temporary" 4 #define kPermanentCache @"com.dv.cache.permanentCache" 5 6 @implementation TMCache (Extension) 7 8 + (instancetype)TemporaryCache{ 9 return [[TMCache sharedCache] initWithName:kTemporaryCache]; 10 } 11 + (instancetype)PermanentCache { 12 return [[TMCache sharedCache] initWithName:kPermanentCache]; 13 } 14 15 @end
看的出這個拓展(但不是類別,僅僅是普通類,使用了便利構造器的用法),便利出了兩個方法:temporary(臨時的)、permanent Cache(永久的緩存)
而後在CSSearchModel.m文件中,只用了臨時緩存的方法TemporaryCache。
七、關於TTTAttributedLabel的使用
這個是點贊超過5K的第三方框架,github網址是:https://github.com/TTTAttributedLabel/TTTAttributedLabel ,簡略的中文博客介紹能夠看看:http://each.dog/2015/01/14/read-tttattributedlabel.html ,而後來看看Coding源碼中UITTTAttributedLabel.h是對TTTAttributedLabel的一個繼承拓展,而後多出被使用,其中CSSearchCell.h中就被使用,導入和遵循了協議,在CSSearchCell.m文件中第32行聲明瞭屬性,而後建立了這個UITTTAttributedLabel對象:
若是讀者意猶未盡,能夠繼續閱讀本人學習Coding-iOS第二篇《學習Coding-iOS開源項目日誌(二)》。