github:https://github.com/koknine (终于改成以前的了)

当前移动互联网行业太火爆,移动端的需求日益增长,很多开发人员每天都应对着各种需求,作为一名iOS开发人员,对于需求来说,我们要做到的是实现,而对于自己来说,我们需要做到的是写出高质量的代码。

于是,全球的大神们开源了很多高质量、可复用的代码,给予了芸芸众生(心中一万个感谢)。例如我们常用的 AFNetworking,SDWebImage,Masonry 等等,这些第三方库内容强大,性能很高,为大家带来了很多福利。

在开发过程当中,适当合理的使用这些第三方库能帮我们节省很多的时间。这些优秀的第三方库就如同教科书一样,当我们深入挖掘的时候,才能获得更高的提升。

好了,吹了半天牛,我们现在到底要做什么呢?其实我想说的是,合理的使用第三方库能大大的提升开发效率,也许我们自己研究做动画弄半天,还不如开源动画好用,这样的情况很多时候我们是不得不承认的。与其与之较劲,不如我们先使用它们的框架,然后再做深入探究,这样方能更好的掌握。

网上很多好的整理,我这里引用一下:刚刚在线博客,里面有很多整理好的内容,非常好的干货。感谢原作者的内容,其中有一个整理的是iOS开发好用的 category,能帮我们节省很多精力,接下来我就先一一分析github上面这些category,翻译其中重要的内容。

声明:本人翻译并不能做到百分之百准确,内容如果有误,欢迎下方评论指导,谢谢!

UIImageView_FaceAwareFill

简介

地址:https://github.com/Julioacarrettoni/UIImageView_FaceAwareFill

This category applies Aspect Fill content mode to an image and if faces are detected it centers them instead of centering the image just by its geometrical center.这个 category 使用了 Aspect Fill 的模式来显示图片并且当人脸被检测到时,它会就以脸部中心替代图片的集合中心。

使用

pch 文件中直接导入

  1. #import "UIImageView+UIImageView_FaceAwareFill.h"

设置完一个UIImageView的属性以后直接

  1. [self.imageView faceAwareFill];

然后就完了。。。。。

个人评价

看到没有,大神的提供的方法就是如此狂拽炫酷叼霸天,就是如此的简单。

NSRegularEx+ObjCRegex

简介
地址:https://github.com/bendytree/Objective-C-RegEx-Categories

This project simplifies regular expressions in Objective-C and Swift.
这个猛,直接把objective-cswift里面的正则表达式给整合了。

这是一组对比

  1. // Without this library
  2. NSString* string = @"I have 2 dogs.";
  3. NSRegularExpression *regex = [NSRegularExpression regular ExpressionWithPattern:@"\\d+" options:NSRegularExpressionCaseInsensitive error:&error];
  4. NSTextCheckingResult *match = [regex firstMatchInString:string options:0 range:NSMakeRange(0, [string length])];
  5. BOOL isMatch = match != nil;
  6. // With this library
  7. BOOL isMatch = [@"I have 2 dogs." isMatch:RX(@"\\d+")];

使用

安装过程就不赘述了,要么是cocoapods,要么直接拖进去。

老规矩,在 pch 文件中添加:

  1. #ifdef __OBJC__
  2. /* ...other references... */
  3. #import "RegExCategories.h"
  4. #endif

当然,你的工程需要开启ARC

Swift支持
这个就需要一个桥接文件,百度即可,Swift引用 OC 的三方都是需要一个桥接文件。

后面的教程就不翻译了,直接去看代码吧,少年。

个人评价还在为正则表达式而纠结吗?还在调试正则表达式问题吗?没错,走过路过不要错误,这里有你想要的一切。

NSObject+AutoCoding

简介

地址:https://github.com/nicklockwood/AutoCoding

这个是一个NSObject的 category,提供了对NSCodingNSCopying的自动支持。这意味着你不要写initWithCoder:encodeWithCoder:了,这个直接承包了。

当然,怎么用还是要看自己的,它并不能读懂你的思维。还有举个例子,你应该避免使用结构体因为它并不遵循NSCoding协议,而是通过NSValue

支持很多版本

支持ARCMRC

线程安全

使用

直接把AutoCoding.hAutoCoding.m拖进工程。

其实自己写归档和反归档也没有那么复杂,这里就不做详细介绍了。

个人评价

这个其实还好,不过其中的机制很不错,值得一看,后面有时间我再翻译。

UILabel-ContentSize

简介

来源:https://github.com/mergesort/UILabel-ContentSize

使用

通过传入的字符串来改变UILabelSize

直接把.h.m文件导入工程吧。

个人评价

正如同作者所说的,总是会忘记操作细节,不如直接写成 category。

UIViewController-Swizzled

简介

来源:https://github.com/RuiAAPeres/UIViewController-Swizzled

这个能帮你管理你的应用。当你正在做复杂的行为以及刚接手工程的时候这个会变得特别好用。使用这个 category 能看到你现在所在的UIViewController,还有展示你进入的层次。

使用

老规矩,要么直接拖入,要么用cocoapods

需要导入链接库:

  1. libobjc.dylib

然后导入头文件:

  1. #import "UIViewController+Swizzled.h"

AppDelegate中,你需要在方法- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法里面加入SWIZZ_IT 开启。如果因为什么原因你想要停止,只需要添加UN_SWIZZ_IT 

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. SWIZZ_IT;
  4. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  5. [self.window makeKeyAndVisible];
  6. // Your code...
  7. return YES;
  8. }

然后就能看到输出:

  1. 2013-09-09 18:58:42.360 Testing[25399:c07] -> UINavigationController
  2. 2013-09-09 18:58:42.361 Testing[25399:c07] ---> RPViewController
  3. 2013-09-09 18:59:55.072 Testing[25399:c07] -----> RPSecondViewController
  4. 2013-09-09 18:59:57.367 Testing[25399:c07] -------> RPThirdViewController
  5. 2013-09-09 18:59:58.801 Testing[25399:c07] -----> RPSecondViewController
  6. 2013-09-09 19:00:00.282 Testing[25399:c07] -------> RPThirdViewController
  7. 2013-09-09 19:00:01.906 Testing[25399:c07] ---------> RPViewController
  8. 2013-09-09 19:00:03.515 Testing[25399:c07] -------> RPThirdViewController
  9. 2013-09-09 19:00:04.267 Testing[25399:c07] -----> RPSecondViewController
  10. 2013-09-09 19:00:05.041 Testing[25399:c07] ---> RPViewController
  11. 2013-09-09 19:00:07.193 Testing[25399:c07] -----> RPSecondViewController
  12. 2013-09-09 19:00:08.312 Testing[25399:c07] -------> RPThirdViewController
  13. 2013-09-09 19:00:09.396 Testing[25399:c07] ---------> RPViewController
  14. 2013-09-09 19:00:10.183 Testing[25399:c07] -----------> RPSecondViewController
  15. 2013-09-09 19:00:10.905 Testing[25399:c07] -------------> RPThirdViewController
  16. 2013-09-09 19:00:12.141 Testing[25399:c07] ---------------> RPViewController
  17. 2013-09-09 19:00:13.156 Testing[25399:c07] -----------------> RPSecondViewController

个人评价

当你刚接手一个新的项目的时候,无数个文件。

这是什么鬼?程序怎么运行的?那个类是干嘛用的?为什么运行到了这里,还有,文件怎么找?要疯掉了。。。

有了此神器,天黑都不怕,一步一步是爪牙,是魔鬼的步伐,程序的运行一清二楚,简直出门旅行,居家必备之良药。

你值得拥有!

NSDate-Escort

简介

来源:https://github.com/azu/NSDate-Escort

加强NSDate

使用

  1. /**
  2. Returns the calendarIdentifier of calendars that is used by this library for date calculation.
  3. @see AZ_setDefaultCalendarIdentifier: for more details.
  4. */
  5. + (NSString *)AZ_defaultCalendarIdentifier;
  6. /**
  7. Sets the calendarIdentifier of calendars that is used by this library for date calculation.
  8. You can specify any calendarIdentifiers predefined by NSLocale. If you provide nil, the library uses
  9. [NSCalendar currentCalendar]. Default value is nil.
  10. You can't provide individual calendars for individual date objects. If you need to perform such
  11. complicated date calculations, you should rather create calendars on your own.
  12. */
  13. + (void)AZ_setDefaultCalendarIdentifier:(NSString *)calendarIdentifier;
  14. #pragma mark - Relative dates from the current date
  15. - (BOOL)isYesterday;
  16. - (BOOL)isSameWeekAsDate:(NSDate *) aDate;
  17. - (BOOL)isThisWeek;
  18. - (BOOL)isNextWeek;
  19. - (BOOL)isLastWeek;
  20. - (BOOL)isSameMonthAsDate:(NSDate *) aDate;
  21. - (BOOL)isThisMonth;
  22. - (BOOL)isSameYearAsDate:(NSDate *) aDate;
  23. - (BOOL)isThisYear;
  24. - (BOOL)isNextYear;
  25. - (BOOL)isLastYear;
  26. - (BOOL)isEarlierThanDate:(NSDate *) aDate;
  27. - (BOOL)isLaterThanDate:(NSDate *) aDate;
  28. - (BOOL)isEarlierThanOrEqualDate:(NSDate *) aDate;
  29. - (BOOL)isLaterThanOrEqualDate:(NSDate *) aDate;
  30. - (BOOL)isInFuture;
  31. - (BOOL)isInPast;
  32. #pragma mark - Date roles
  33. - (BOOL)isTypicallyWorkday;
  34. - (BOOL)isTypicallyWeekend;
  35. #pragma mark - Adjusting dates
  36. - (NSDate *)dateByAddingYears:(NSInteger) dYears;
  37. - (NSDate *)dateBySubtractingYears:(NSInteger) dYears;
  38. - (NSDate *)dateByAddingMonths:(NSInteger) dMonths;
  39. - (NSDate *)dateBySubtractingMonths:(NSInteger) dMonths;
  40. - (NSDate *)dateByAddingDays:(NSInteger) dDays;
  41. - (NSDate *)dateBySubtractingDays:(NSInteger) dDays;
  42. - (NSDate *)dateByAddingHours:(NSInteger) dHours;
  43. - (NSDate *)dateBySubtractingHours:(NSInteger) dHours;
  44. - (NSDate *)dateByAddingMinutes:(NSInteger) dMinutes;
  45. - (NSDate *)dateBySubtractingMinutes:(NSInteger) dMinutes;
  46. - (NSDate *)dateAtStartOfDay;
  47. - (NSDate *)dateAtEndOfDay;
  48. - (NSDate *)dateAtStartOfWeek;
  49. - (NSDate *)dateAtEndOfWeek;
  50. - (NSDate *)dateAtStartOfMonth;
  51. - (NSDate *)dateAtEndOfMonth;
  52. - (NSDate *)dateAtStartOfYear;
  53. - (NSDate *)dateAtEndOfYear;
  54. #pragma mark - Retrieving intervals
  55. - (NSInteger)minutesAfterDate:(NSDate *) aDate;
  56. - (NSInteger)minutesBeforeDate:(NSDate *) aDate;
  57. - (NSInteger)hoursAfterDate:(NSDate *) aDate;
  58. - (NSInteger)hoursBeforeDate:(NSDate *) aDate;
  59. - (NSInteger)daysAfterDate:(NSDate *) aDate;
  60. - (NSInteger)daysBeforeDate:(NSDate *) aDate;
  61. - (NSInteger)monthsAfterDate:(NSDate *) aDate;
  62. - (NSInteger)monthsBeforeDate:(NSDate *) aDate;
  63. /**
  64. * return distance days
  65. */
  66. - (NSInteger)distanceInDaysToDate:(NSDate *) aDate;
  67. #pragma mark - Decomposing dates
  68. /**
  69. * return nearest hour
  70. */
  71. @property(readonly) NSInteger nearestHour;
  72. @property(readonly) NSInteger hour;
  73. @property(readonly) NSInteger minute;
  74. @property(readonly) NSInteger seconds;
  75. @property(readonly) NSInteger day;
  76. @property(readonly) NSInteger month;
  77. @property(readonly) NSInteger week;
  78. // in the Gregorian calendar, n is 7 and Sunday is represented by 1.
  79. @property(readonly) NSInteger weekday;
  80. @property(readonly) NSInteger firstDayOfWeekday;
  81. @property(readonly) NSInteger lastDayOfWeekday;
  82. // e.g. 2nd Tuesday of the month == 2
  83. @property(readonly) NSInteger nthWeekday;

个人评价

无需多说,看方法名字就知道有什么作用了,回想起之前处理时间的日子。。。多么痛的领悟,果然那句话很对:磨刀不误砍柴工。

UIView+Toast

简介

来源:https://github.com/scalessec/Toast

使用

注意导入QuartzCore

图片已经实例代码源地址都有,就几个参数

  • makeToast 要显示的内容

  • duration 持续时间

  • position 放置的位置

  • title 标题

  • image 放置的图片

  • makeToastActivity 显示 toast

个人评价

简单好用,清晰明了。

NYXImagesKit

简介

来源:https://github.com/Nyx0uf/NYXImagesKit

NYXImagesKit是一个重组了多个有用的UIImage categories的iOS项目,可对图像/图片进行多个处理,比如筛选、模糊、优化、蒙版、调整大小、旋转以及保存等等。同时还提供了一个UIImageView子类从URL异步加载图片,并在下载完毕时展示图片。

使用

首先打开NYXImagesKit.xcodeproj然后运行库,之后把库和头文件导入到你的工程里面,最后要链接以下的框架:

  • Accelerate

  • AssetsLibrary

  • ImageIO

  • MobileCoreServices

  • QuartzCore

  • CoreImage

UIImage+Blurring
模糊效果

  1. [myImage gaussianBlurWithBias:0];

UIImage+Masking
蒙板效果

  1. UIImage* masked = [myImage maskWithImage:[UIImage imageNamed:@"mask.png"]];

UIImage+Resizing
重置尺寸

  1. 上左

  2. 上中

  3. 上右

  4. 下左

  5. 下中

  6. 下右

  7. 左中

  8. 右中

  9. 中间

  1. UIImage* cropped = [myImage cropToSize:(CGSize){width, height} usingMode:NYXCropModeCenter];

NYXCropMode是一个枚举类型,能在头文件里面找到,表示不同的类型

Scaling
缩放

你有两种方法来缩放图片,这两种方法都能保持原图片比例

  1. UIImage* scaled1 = [myImage scaleByFactor:0.5f];
  2. UIImage* scaled2 = [myImage scaleToFitSize:(CGSize){width, height}];

UIImage+Rotating
旋转

  1. UIImage* rotated1 = [myImage rotateInDegrees:217.0f];
  2. UIImage* rotated2 = [myImage rotateInRadians:M_PI_2];
  3. UIImage* flipped1 = [myImage verticalFlip];
  4. UIImage* flipped2 = [myImage horizontalFlip];

UIImage+Reflection
重构图片

  1. UIImage* reflected = [myImage reflectedImageWithHeight:myImage.size.height fromAlpha:0.0f toAlpha:0.5f];

UIImage+Enhancing
提升

  1. [myImage autoEnhance];
  2. [myImage redEyeCorrection];

UIImage+Saving
保存类型

这个能把图片存到一个地址或者相册,支持五种类型

  1. BMP

  2. GIF

  3. JPG

  4. PNG

  5. TIFF

要用这个就必须导入ImageIO.frameworkMobileCoreServices.framework还有AssertsLibrary.framework

  1. [myImage saveToURL:url type:NYXImageTypeJPEG backgroundFillColor:nil];
  2. [myImage saveToPath:path type:NYXImageTypeTIFF backgroundFillColor:[UIColor yellowColor]];
  3. [myImage saveToPhotosAlbum];

NYXProgressiveImageView

这个是继承UIImageView的一个类,能异步加载图片和缓存。

当然,我们可以使用SDWebImage

个人评价

这个针对于图片处理,很好很强大。

MJPopupViewController

简介

来源:https://github.com/martinjuhasz/MJPopupViewController

这个是给UIViewController提供过渡效果的。

使用

Source目录下的文件夹拖入工程,然后导入QuartzCore.framework

引入文件

  1. #import "UIViewController+MJPopupViewController.h"

简单添加

  1. [self presentPopupViewController:detailViewController animationType:MJPopupViewAnimationFade];

如果要消失

  1. [self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];

在实例工程中可以看到更多的使用方法。

个人评价

一个非常简单容易使用的过渡效果,有需求的时候可以使用。

UIColor+Colours

简介

来源:https://github.com/bennyguitar/Colours

UIColor提供更多颜色支持

使用

cocoapods安装,或者拖入文件

颜色过多,就不一一列举了。

RGBA

通过数组可以取出UIColor的四个参数,都是NSNumber类型,记得他们都是0-1的数,不是0-255

  1. NSArray *colorArray = [[UIColor seafoamColor] rgbaArray];
  2. UIColor *newColor = [UIColor colorFromRGBAArray:colorArray];

字典也能取到值

  • kColoursRGBA_R

  • kColoursRGBA_G

  • kColoursRGBA_B

  • kColoursRGBA_A

  1. NSDictionary *colorDict = [[UIColor seafoamColor] rgbaDictionary];
  2. UIColor *newColor = [UIColor colorFromRGBADictionary:colorDict];
  3. // You can also get a single component like so:
  4. NSNumber *r = colorDict[kColoursRGBA_R];

后面还有很多方法,不一一列举了。

个人评价

实际开发中,一般 UI 设计出来各种颜色,位置都确定了,所以不好说这个用的多不多。

NSDate+Helper

简介

来源:https://github.com/billymeltdown/nsdate-helper

这也是一个扩展NSDate的 category

使用

使用方便,stringForDisplayFromDate能非常便捷的显示出很多信息。

  1. NSString *displayString = [NSDate stringForDisplayFromDate:date];

这能显示出很多信息

  • ‘3:42 AM’ – 如果时间是在今天半夜

  • ‘Tuesday’ – 如果时间是在这个星期

  • ‘Mar 1’ – 如果日期是在今年

  • ‘Mar 1, 2008’ – else ;-)

另外的方法能显示几天之前这样的信息

  1. NSDate *date = [NSDate date];
  2. [date daysAgo]; // provides an NSComponent-based NSUInteger describing days ago.
  3. [date daysAgoAgainstMidnight]; // better version of daysAgo, works off midnight (hat-tip: "sburlot":http://github.com/sburlot)
  4. [date stringDaysAgo]; // 'Today', 'Yesterday', or 'N days ago'.

构造date formatters很纠结?缺少to_s(:db)?我也是,NSDate (Helper)有些静态方法能够在两者之间转换,而且能支持数据库的时间戳。

  1. NSDate *date = [NSDate dateFromString:@"2009-03-01 12:15:23"];
  2. NSString *dbDateString = [NSDate stringFromDate:date]; // returns '2009-03-01 12:15:23'

还有

  1. NSString *otherDateString = [NSDate stringFromDate:date withFormat:@"EEEE"]; // use any format you like

个人评价

这个也不错,更多功能可以在.h文件里面找,命名很规范。

ObjectiveSugar

简介

来源:https://github.com/supermarin/ObjectiveSugar

语法糖功能

使用

使用cocoapods,然后导入头文件#import <ObjectiveSugar/ObjectiveSugar.h>

NSNumber

  1. [@3 times:^{
  2. NSLog(@"Hello!");
  3. }];
  4. // Hello!
  5. // Hello!
  6. // Hello!
  7. [@3 timesWithIndex:^(NSUInteger index) {
  8. NSLog(@"Another version with number: %d", index);
  9. }];
  10. // Another version with number: 0
  11. // Another version with number: 1
  12. // Another version with number: 2
  13. [@1 upto:4 do:^(NSInteger numbah) {
  14. NSLog(@"Current number.. %d", numbah);
  15. }];
  16. // Current number.. 1
  17. // Current number.. 2
  18. // Current number.. 3
  19. // Current number.. 4
  20. [@7 downto:4 do:^(NSInteger numbah) {
  21. NSLog(@"Current number.. %d", numbah);
  22. }];
  23. // Current number.. 7
  24. // Current number.. 6
  25. // Current number.. 5
  26. // Current number.. 4
  27. NSDate *firstOfDecember = [NSDate date]; // let's pretend it's 1st of December
  28. NSDate *firstOfNovember = [@30.days since:firstOfDecember];
  29. // 2012-11-01 00:00:00 +0000
  30. NSDate *christmas = [@7.days until:newYearsDay];
  31. // 2012-12-25 00:00:00 +0000
  32. NSDate *future = @24.days.fromNow;
  33. // 2012-12-25 20:49:05 +0000
  34. NSDate *past = @1.month.ago;
  35. // 2012-11-01 20:50:28 +00:00

NSArray / NSSet

  1. // All of these methods return a modified copy of the array.
  2. // They're not modifying the source array.
  3. NSArray *cars = @[@"Testarossa", @"F50", @"F458 Italia"]; // or NSSet
  4. [cars each:^(id object) {
  5. NSLog(@"Car: %@", object);
  6. }];
  7. // Car: Testarossa
  8. // Car: F50
  9. // Car: F458 Italia
  10. [cars eachWithIndex:^(id object, NSUInteger index) {
  11. NSLog(@"Car: %@ index: %i", object, index);
  12. }];
  13. // Car: Testarossa index: 0
  14. // Car: F50 index: 1
  15. // Car: F458 Italia index: 2
  16. [cars each:^(id object) {
  17. NSLog(@"Car: %@", object);
  18. } options:NSEnumerationReverse];
  19. // Car: F458 Italia
  20. // Car: F50
  21. // Car: Testarossa
  22. [cars eachWithIndex:^(id object, NSUInteger index) {
  23. NSLog(@"Car: %@ index: %i", object, index);
  24. } options:NSEnumerationReverse];
  25. // Car: F458 Italia index: 2
  26. // Car: F50 index: 1
  27. // Car: Testarossa index: 0
  28. [cars map:^(NSString* car) {
  29. return car.lowercaseString;
  30. }];
  31. // testarossa, f50, f458 italia
  32. // Or, a more common example:
  33. [cars map:^(NSString* carName) {
  34. return [[Car alloc] initWithName:carName];
  35. }];
  36. // array of Car objects
  37. NSArray *mixedData = @[ @1, @"Objective Sugar!", @"Github", @4, @"5"];
  38. [mixedData select:^BOOL(id object) {
  39. return ([object class] == [NSString class]);
  40. }];
  41. // Objective Sugar, Github, 5
  42. [mixedData reject:^BOOL(id object) {
  43. return ([object class] == [NSString class]);
  44. }];
  45. // 1, 4
  46. NSArray *numbers = @[ @5, @2, @7, @1 ];
  47. [numbers sort];
  48. // 1, 2, 5, 7
  49. cars.sample
  50. // 458 Italia
  51. cars.sample
  52. // F50

NSArrayonly

  1. NSArray *numbers = @[@1, @2, @3, @4, @5, @6];
  2. // index from 2 to 4
  3. numbers[@"2..4"];
  4. // [@3, @4, @5]
  5. // index from 2 to 4 (excluded)
  6. numbers[@"2...4"];
  7. // [@3, @4]
  8. // With NSRange location: 2, length: 4
  9. numbers[@"2,4"];
  10. // [@3, @4, @5, @6]
  11. NSValue *range = [NSValue valueWithRange:NSMakeRange(2, 4)];
  12. numbers[range];
  13. // [@3, @4, @5, @6]
  14. [numbers reverse];
  15. // [@6, @5, @4, @3, @2, @1]
  16. NSArray *fruits = @[ @"banana", @"mango", @"apple", @"pear" ];
  17. [fruits includes:@"apple"];
  18. // YES
  19. [fruits take:3];
  20. // banana, mango, apple
  21. [fruits takeWhile:^BOOL(id fruit) {
  22. return ![fruit isEqualToString:@"apple"];
  23. }];
  24. // banana, mango
  25. NSArray *nestedArray = @[ @[ @1, @2, @3 ], @[ @4, @5, @6, @[ @7, @8 ] ], @9, @10 ];
  26. [nestedArray flatten];
  27. // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  28. NSArray *abc = @[ @"a", @"b", @"c" ];
  29. [abc join];
  30. // abc
  31. [abc join:@"-"];
  32. // a-b-c
  33. NSArray *mixedData = @[ @1, @"Objective Sugar!", @"Github", @4, @"5"];
  34. [mixedData detect:^BOOL(id object) {
  35. return ([object class] == [NSString class]);
  36. }];
  37. // Objective Sugar
  38. // TODO: Make a better / simpler example of this
  39. NSArray *landlockedCountries = @[ @"Bolivia", @"Paraguay", @"Austria", @"Switzerland", @"Hungary" ];
  40. NSArray *europeanCountries = @[ @"France", @"Germany", @"Austria", @"Spain", @"Hungary", @"Poland", @"Switzerland" ];
  41. [landlockedCountries intersectionWithArray:europeanCountries];
  42. // landlockedEuropeanCountries = Austria, Switzerland, Hungary
  43. [landlockedCountries unionWithArray:europeanCountries];
  44. // landlockedOrEuropean = Bolivia, Paraguay, Austria, Switzerland, Hungary, France, Germany, Spain, Poland
  45. [landlockedCountries relativeComplement:europeanCountries];
  46. // nonEuropeanLandlockedCountries = Bolivia, Paraguay
  47. [europeanCountries relativeComplement:landlockedCountries];
  48. // notLandlockedEuropeanCountries = France, Germany, Spain, Poland
  49. [landlockedCountries symmetricDifference:europeanCountries];
  50. // uniqueCountries = Bolivia, Paraguay, France, Germany, Spain, Poland

NSMutableArray

  1. NSMutableArray *people = @[ @"Alice", @"Benjamin", @"Christopher" ];
  2. [people push:@"Daniel"]; // Alice, Benjamin, Christopher, Daniel
  3. [people pop]; // Daniel
  4. // people = Alice, Benjamin, Christopher
  5. [people pop:2]; // Benjamin, Christopher
  6. // people = Alice
  7. [people concat:@[ @"Evan", @"Frank", @"Gavin" ]];
  8. // people = Alice, Evan, Frank, Gavin
  9. [people keepIf:^BOOL(id object) {
  10. return [object characterAtIndex:0] == 'E';
  11. }];
  12. // people = Evan

NSDictionary

  1. NSDictionary *dict = @{ @"one" : @1, @"two" : @2, @"three" : @3 };
  2. [dict each:^(id key, id value){
  3. NSLog(@"Key: %@, Value: %@", key, value);
  4. }];
  5. // Key: one, Value: 1
  6. // Key: two, Value: 2
  7. // Key: three, Value: 3
  8. [dict eachKey:^(id key) {
  9. NSLog(@"Key: %@", key);
  10. }];
  11. // Key: one
  12. // Key: two
  13. // Key: three
  14. [dict eachValue:^(id value) {
  15. NSLog(@"Value: %@", value);
  16. }];
  17. // Value: 1
  18. // Value: 2
  19. // Value: 3
  20. NSDictionary *errors = @{
  21. @"username" : @[ @"already taken" ],
  22. @"password" : @[ @"is too short (minimum is 8 characters)", @"not complex enough" ],
  23. @"email" : @[ @"can't be blank" ];
  24. };
  25. [errors map:^(id attribute, id reasons) {
  26. return NSStringWithFormat(@"%@ %@", attribute, [reasons join:@", "]);
  27. }];
  28. // username already taken
  29. // password is too short (minimum is 8 characters), not complex enough
  30. // email can't be blank
  31. [errors hasKey:@"email"]
  32. // true
  33. [errors hasKey:@"Alcatraz"]
  34. // false

NSString

  1. NSString *sentence = NSStringWithFormat(@"This is a text-with-argument %@", @1234);
  2. // This is a text-with-argument 1234
  3. [sentence split];
  4. // array = this, is, a, text-with-argument, 1234
  5. [sentence split:@"-"]
  6. // array = this is a text, with, argument 1234
  7. [sentence containsString:@"this is a"];
  8. // YES

C

  1. unless(_messages) {
  2. // The body is only executed if the condition is false
  3. _messages = [self initializeMessages];
  4. }
  5. int iterations = 10;
  6. until(iterations == 0) {
  7. // The body is executed until the condition is false
  8. // 10 9 8 7 6 5 4 3 2 1
  9. printf("%d ", iterations);
  10. iterations--;
  11. }
  12. printf("\n");
  13. iterations = 10;
  14. do {
  15. // The body is executed at least once until the condition is false
  16. // Will print: Executed!
  17. printf("Executed!\n");
  18. } until(true);

个人评价

这是什么黑科技,简直改变 OC 语法,简化更多语法,简直停不下来。

Kiwi

简介

来源:https://github.com/kiwi-bdd/Kiwi

Kiwi的作用是用来过来更方便的测试程序,可读性更高。

使用

  1. pod "Kiwi"

详细需要看文档。

个人评价

又是一个黑科技,用的时候再查看文档吧。

ViewUtils

简介

来源:https://github.com/nicklockwood/ViewUtils

目的
扩展UIView的 category,有几个方面:

  • 载入Nib- 不需要UIViewController就能载入视图

  • 布局 - 能独立设置位置或者宽/高

  • 搜索 - 检索子视图,通过类,tag 或者正则表达式

  • 响应者 - 找到一个 view 的第一响应者

线程安全
这个只能在主线程使用

使用

把两个文件拖入工程

方法封装了系统的UIView,很多都是非常实用且增加了安全性能。

还能单独修改frame的值。

个人评价
封装UIView的通用功能,安全性得到提高,还能单独修改frame,增加了很多便利。

NSDate-TimeAgo

简介

来源:https://github.com/kevinlawler/NSDate-TimeAgo

可以显示当前时间是多久以前,不过这个已经并入了另一个库里面

使用

导入#import "NSDate+TimeAgo.h"

  1. NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:0];
  2. NSString *ago = [date timeAgo];
  3. NSLog(@"Output is: \"%@\"", ago);
  4. 2011-11-12 17:19:25.608 Proj[0:0] Output is: "41 years ago"

还有两种方法

  • dateTimeAgo - 返回{value} {unit} ago 这种格式

  • dateTimeUntilNow - 返回昨天/今早/上个星期/这个月,没有上面的精确但是更自然。

个人评价

如果只需要很简单的功能,这个就能满足,如果需要对时间更强大处理

访问:https://github.com/MatthewYork/DateTools

iOS-FontAwesome

简介

来源:https://github.com/alexdrone/ios-fontawesome

添加字体,还有图片

使用

首先,在工程里面必须有FontAwesome.ttf,而且在plist文件中的UIAppFonts必须包换一个String item名字叫FontAwesome.ttf

然后再导入NSString+FontAwesome

  1. UILabel *label = [...]
  2. label.font = [UIFont fontWithName:kFontAwesomeFamilyName size:20];

还能使用枚举

  1. label.text = [NSString fontAwesomeIconStringForEnum:FAGithub];

当然,最重要还是查看文档,里面提供各种字体。

个人评价

确实很不错,很多种类型的字体,还有图片的,总之很给力。

NSObject-AutoDescription

简介

来源:https://github.com/djmadcat/NSObject-AutoDescription

增加对NSArrayNSDictionary还有NSSet的描述支持

使用

  1. #import "NAUser.h"
  2. #import "NSObject+AutoDescription.h"
  3. @implementation NAUser
  4. - (NSString *)description
  5. {
  6. return [self autoDescription];
  7. }
  8. @end

个人评价

小而美,有需求的话可以用下。

CGRectPositioning

简介

来源:https://github.com/mvx24/CGRectPositioning

这个是个宏文件

可以对CGRect很方便的处理

使用

看名字就能知道了,把CGRectPositioning.h导入工程,里面全是宏

个人评价

代码布局的时候,使用这个就能很方便

MZTimerLabel

来源:https://github.com/mineschan/MZTimerLabel

倒计时专用label,处理登录获取短信倒计时可用

个人评价

刚刚发现的好货,先存起来,配合时间相关方法,可以根据接口请求的时间戳做一些操作

OS快速开发必备的更多相关文章

  1. 【Android】快速开发偷懒必备(二) 支持DataBinding啦~爽炸,一行实现花式列表[申明:来源于网络]

    [Android]快速开发偷懒必备(二) 支持DataBinding啦~爽炸,一行实现花式列表[申明:来源于网络] 地址:http://blog.csdn.net/zxt0601/article/de ...

  2. (转载)Android快速开发偷懒必备,一句话搞定所有ViewGroup的Adapter . 支持自定义ViewGroup

    [置顶] [Android]快速开发偷懒必备,一句话搞定所有ViewGroup的Adapter . 支持自定义ViewGroup 标签: androidAdapter快速开发0耦合 2016-12-1 ...

  3. (私人收藏)[开发必备]最全JQuery离线快速查找手册(可查询可学习,带实例)

    [开发必备]最全JQuery离线快速查找手册(可查询可学习,带实例) https://pan.baidu.com/s/16bUd4iA3p0c5RHbzaC60IQe4zh

  4. (私人收藏)[开发必备]HTML5最全快速查找离线手册(可查询可学习,带实例)

    [开发必备]HTML5最全快速查找离线手册(可查询可学习,带实例) HTML5最全快速查找离线手册:https://pan.baidu.com/s/19seE8TJQSx4IsWgXtKQS0Aj9y ...

  5. (私人收藏)[开发必备]最全Java离线快速查找手册(可查询可学习,带实例)

    (私人收藏)[开发必备]最全Java离线快速查找手册(可查询可学习,带实例) https://pan.baidu.com/s/1L54VuFwCdKVnQGVc8vD1TQnwmj java手册 Ja ...

  6. Mac开发必备工具(二)—— iTerm 2

    iTerm 2 简介 iTerm 2 is a terminal emulator for Mac OS X that does amazing things. iTerm 2 有很多能够提升效率的实 ...

  7. 全栈开发必备的10款Sublime Text 插件

    Sublime Text 具有漂亮的用户界面和强大的功能,例如代码缩略图,多重选择,快捷命令等.Sublime Text 更妙的是它的可扩展性.所以,这里挑选了全栈开发必备的10款 Sublime T ...

  8. 全栈开发必备的10款 Sublime Text 插件

    Sublime Text 具有漂亮的用户界面和强大的功能,例如代码缩略图,多重选择,快捷命令等.Sublime Text 更妙的是它的可扩展性.所以,这里挑选了全栈开发必备的10款 Sublime T ...

  9. 开源框架】Android之史上最全最简单最有用的第三方开源库收集整理,有助于快速开发

    [原][开源框架]Android之史上最全最简单最有用的第三方开源库收集整理,有助于快速开发,欢迎各位... 时间 2015-01-05 10:08:18 我是程序猿,我为自己代言 原文  http: ...

随机推荐

  1. DirectX Sample-Blobs实现原理

    这个例子的实现主要包括两步: 1.计算三维采样坐标和color,实现代码是for( i = 0; i < NUM_Blobs; ++i )那个循环,计算完成以后g_pTexGBuffer[0]保 ...

  2. 关于时间的操作(JavaScript版)——依据不同区时显示对应的时间

    如今项目基本上告一段落了,难得有一定的闲暇,今天利用数小时完毕了一个功能模块--依据不同区时显示对应的时间,这方面网上基本没有现成的样例,如今将代码粘贴例如以下: <!DOCTYPE HTML ...

  3. 操作系统——IO缓存技术

    一.为什么引入缓存技术 为了解决cpu速度和外部设备速度不匹配的问题. 降低了io对cpu的中断的次数.每进行一次IO设备的时间都非常长,所以把数据先放入缓冲区,再进行IO操作. 二.缓冲技术的实现 ...

  4. traceroute原理

    traceroute原理 ICMP ICMP全称为Internet Control Message Protocol,即,网络控制报文协议. 当一个IP数据报发送失败时,最后一个路由器会向发送发传递一 ...

  5. CentOS 6.5 升级内核 kernel

    本文适用于CentOS 6.5, CentOS 6.6,亲测可行,估计也适用于其他Linux发行版. 1. 准备工作 1.1 下载源码包 Linux内核版本有两种:稳定版和开发版 ,Linux内核版本 ...

  6. Java中Thread类的start()和run()的区别

    1.start()方法来启动线程,真正实现了多线程运行,这时无需等待run方法体代码执行完毕而直接继续执行下面的代码. 通 过调用Thread类的start()方法来启动一个线程,这时此线程是处于就绪 ...

  7. 如何解决DE0-Nano的EPCS16 无法下载的问题:NO EPCS LAYOUT DATA --- LOOKING FOR SECTION [EPCS-XXXXXX]

    在用NIOS的flashprogram对EPCSx进行烧录程序时,出现了No EPCS layout data --- looking for section [EPCS-XXXXXX]的错误,在网上 ...

  8. 编译U-boot时,make[1]: *** 没有规则可以创建mkimage.o”

    执行完make smdk2440_config 对Uboot重行编译怎么会出现这样的错误 make[1]: Entering directory `/home/win/S3-ARM/Part4/ubo ...

  9. 一致性哈希与java实现

    一致性哈希算法是分布式系统中常用的算法.比如,一个分布式的存储系统,要将数据存储到具体的节点上,如果采用普通的hash方法,将数据映射到具体的节点上,如key%N,key是数据的key,N是机器节点数 ...

  10. c#字符串方法

    作者: 常浩 staticvoid Main(string[] args) { string s =""; //(1)字符访问(下标访问s[i]) s ="ABCD&qu ...