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 文件中直接导入

#import "UIImageView+UIImageView_FaceAwareFill.h"

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

[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里面的正则表达式给整合了。

这是一组对比

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

使用

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

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

#ifdef __OBJC__
/* ...other references... */
#import "RegExCategories.h"
#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

需要导入链接库:

libobjc.dylib

然后导入头文件:

#import "UIViewController+Swizzled.h"

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

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

然后就能看到输出:

2013-09-09 18:58:42.360 Testing[25399:c07] -> UINavigationController
2013-09-09 18:58:42.361 Testing[25399:c07] ---> RPViewController
2013-09-09 18:59:55.072 Testing[25399:c07] -----> RPSecondViewController
2013-09-09 18:59:57.367 Testing[25399:c07] -------> RPThirdViewController
2013-09-09 18:59:58.801 Testing[25399:c07] -----> RPSecondViewController
2013-09-09 19:00:00.282 Testing[25399:c07] -------> RPThirdViewController
2013-09-09 19:00:01.906 Testing[25399:c07] ---------> RPViewController
2013-09-09 19:00:03.515 Testing[25399:c07] -------> RPThirdViewController
2013-09-09 19:00:04.267 Testing[25399:c07] -----> RPSecondViewController
2013-09-09 19:00:05.041 Testing[25399:c07] ---> RPViewController
2013-09-09 19:00:07.193 Testing[25399:c07] -----> RPSecondViewController
2013-09-09 19:00:08.312 Testing[25399:c07] -------> RPThirdViewController
2013-09-09 19:00:09.396 Testing[25399:c07] ---------> RPViewController
2013-09-09 19:00:10.183 Testing[25399:c07] -----------> RPSecondViewController
2013-09-09 19:00:10.905 Testing[25399:c07] -------------> RPThirdViewController
2013-09-09 19:00:12.141 Testing[25399:c07] ---------------> RPViewController
2013-09-09 19:00:13.156 Testing[25399:c07] -----------------> RPSecondViewController

个人评价

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

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

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

你值得拥有!

NSDate-Escort

简介

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

加强NSDate

使用

/**
Returns the calendarIdentifier of calendars that is used by this library for date calculation.
@see AZ_setDefaultCalendarIdentifier: for more details.
*/
+ (NSString *)AZ_defaultCalendarIdentifier;
/**
Sets the calendarIdentifier of calendars that is used by this library for date calculation.
You can specify any calendarIdentifiers predefined by NSLocale. If you provide nil, the library uses
[NSCalendar currentCalendar]. Default value is nil. You can't provide individual calendars for individual date objects. If you need to perform such
complicated date calculations, you should rather create calendars on your own.
*/
+ (void)AZ_setDefaultCalendarIdentifier:(NSString *)calendarIdentifier; #pragma mark - Relative dates from the current date - (BOOL)isYesterday;
- (BOOL)isSameWeekAsDate:(NSDate *) aDate;
- (BOOL)isThisWeek;
- (BOOL)isNextWeek;
- (BOOL)isLastWeek;
- (BOOL)isSameMonthAsDate:(NSDate *) aDate;
- (BOOL)isThisMonth;
- (BOOL)isSameYearAsDate:(NSDate *) aDate;
- (BOOL)isThisYear;
- (BOOL)isNextYear;
- (BOOL)isLastYear;
- (BOOL)isEarlierThanDate:(NSDate *) aDate;
- (BOOL)isLaterThanDate:(NSDate *) aDate;
- (BOOL)isEarlierThanOrEqualDate:(NSDate *) aDate;
- (BOOL)isLaterThanOrEqualDate:(NSDate *) aDate;
- (BOOL)isInFuture;
- (BOOL)isInPast;
#pragma mark - Date roles
- (BOOL)isTypicallyWorkday;
- (BOOL)isTypicallyWeekend;
#pragma mark - Adjusting dates
- (NSDate *)dateByAddingYears:(NSInteger) dYears;
- (NSDate *)dateBySubtractingYears:(NSInteger) dYears;
- (NSDate *)dateByAddingMonths:(NSInteger) dMonths;
- (NSDate *)dateBySubtractingMonths:(NSInteger) dMonths;
- (NSDate *)dateByAddingDays:(NSInteger) dDays;
- (NSDate *)dateBySubtractingDays:(NSInteger) dDays;
- (NSDate *)dateByAddingHours:(NSInteger) dHours;
- (NSDate *)dateBySubtractingHours:(NSInteger) dHours;
- (NSDate *)dateByAddingMinutes:(NSInteger) dMinutes;
- (NSDate *)dateBySubtractingMinutes:(NSInteger) dMinutes;
- (NSDate *)dateAtStartOfDay;
- (NSDate *)dateAtEndOfDay;
- (NSDate *)dateAtStartOfWeek;
- (NSDate *)dateAtEndOfWeek;
- (NSDate *)dateAtStartOfMonth;
- (NSDate *)dateAtEndOfMonth;
- (NSDate *)dateAtStartOfYear;
- (NSDate *)dateAtEndOfYear;
#pragma mark - Retrieving intervals
- (NSInteger)minutesAfterDate:(NSDate *) aDate;
- (NSInteger)minutesBeforeDate:(NSDate *) aDate;
- (NSInteger)hoursAfterDate:(NSDate *) aDate;
- (NSInteger)hoursBeforeDate:(NSDate *) aDate;
- (NSInteger)daysAfterDate:(NSDate *) aDate;
- (NSInteger)daysBeforeDate:(NSDate *) aDate;
- (NSInteger)monthsAfterDate:(NSDate *) aDate;
- (NSInteger)monthsBeforeDate:(NSDate *) aDate;
/**
* return distance days
*/
- (NSInteger)distanceInDaysToDate:(NSDate *) aDate;
#pragma mark - Decomposing dates
/**
* return nearest hour
*/
@property(readonly) NSInteger nearestHour;
@property(readonly) NSInteger hour;
@property(readonly) NSInteger minute;
@property(readonly) NSInteger seconds;
@property(readonly) NSInteger day;
@property(readonly) NSInteger month;
@property(readonly) NSInteger week;
// in the Gregorian calendar, n is 7 and Sunday is represented by 1.
@property(readonly) NSInteger weekday;
@property(readonly) NSInteger firstDayOfWeekday;
@property(readonly) NSInteger lastDayOfWeekday;
// e.g. 2nd Tuesday of the month == 2
@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
模糊效果

[myImage gaussianBlurWithBias:0];

UIImage+Masking
蒙板效果

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

UIImage+Resizing
重置尺寸

  1. 上左

  2. 上中

  3. 上右

  4. 下左

  5. 下中

  6. 下右

  7. 左中

  8. 右中

  9. 中间

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

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

Scaling
缩放

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

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

UIImage+Rotating
旋转

UIImage* rotated1 = [myImage rotateInDegrees:217.0f];
UIImage* rotated2 = [myImage rotateInRadians:M_PI_2];
UIImage* flipped1 = [myImage verticalFlip];
UIImage* flipped2 = [myImage horizontalFlip];

UIImage+Reflection
重构图片

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

UIImage+Enhancing
提升

[myImage autoEnhance];
[myImage redEyeCorrection];

UIImage+Saving
保存类型

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

  1. BMP

  2. GIF

  3. JPG

  4. PNG

  5. TIFF

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

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

NYXProgressiveImageView

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

当然,我们可以使用SDWebImage

个人评价

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

MJPopupViewController

简介

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

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

使用

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

引入文件

#import "UIViewController+MJPopupViewController.h"

简单添加

[self presentPopupViewController:detailViewController animationType:MJPopupViewAnimationFade];

如果要消失

[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];

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

个人评价

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

UIColor+Colours

简介

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

UIColor提供更多颜色支持

使用

cocoapods安装,或者拖入文件

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

RGBA

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

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

字典也能取到值

  • kColoursRGBA_R

  • kColoursRGBA_G

  • kColoursRGBA_B

  • kColoursRGBA_A

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

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

个人评价

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

NSDate+Helper

简介

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

这也是一个扩展NSDate的 category

使用

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

NSString *displayString = [NSDate stringForDisplayFromDate:date];

这能显示出很多信息

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

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

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

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

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

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

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

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

还有

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

[@3 times:^{
NSLog(@"Hello!");
}];
// Hello!
// Hello!
// Hello! [@3 timesWithIndex:^(NSUInteger index) {
NSLog(@"Another version with number: %d", index);
}];
// Another version with number: 0
// Another version with number: 1
// Another version with number: 2 [@1 upto:4 do:^(NSInteger numbah) {
NSLog(@"Current number.. %d", numbah);
}];
// Current number.. 1
// Current number.. 2
// Current number.. 3
// Current number.. 4 [@7 downto:4 do:^(NSInteger numbah) {
NSLog(@"Current number.. %d", numbah);
}];
// Current number.. 7
// Current number.. 6
// Current number.. 5
// Current number.. 4 NSDate *firstOfDecember = [NSDate date]; // let's pretend it's 1st of December NSDate *firstOfNovember = [@30.days since:firstOfDecember];
// 2012-11-01 00:00:00 +0000 NSDate *christmas = [@7.days until:newYearsDay];
// 2012-12-25 00:00:00 +0000 NSDate *future = @24.days.fromNow;
// 2012-12-25 20:49:05 +0000 NSDate *past = @1.month.ago;
// 2012-11-01 20:50:28 +00:00

NSArray / NSSet

// All of these methods return a modified copy of the array.
// They're not modifying the source array. NSArray *cars = @[@"Testarossa", @"F50", @"F458 Italia"]; // or NSSet [cars each:^(id object) {
NSLog(@"Car: %@", object);
}];
// Car: Testarossa
// Car: F50
// Car: F458 Italia [cars eachWithIndex:^(id object, NSUInteger index) {
NSLog(@"Car: %@ index: %i", object, index);
}];
// Car: Testarossa index: 0
// Car: F50 index: 1
// Car: F458 Italia index: 2 [cars each:^(id object) {
NSLog(@"Car: %@", object);
} options:NSEnumerationReverse];
// Car: F458 Italia
// Car: F50
// Car: Testarossa [cars eachWithIndex:^(id object, NSUInteger index) {
NSLog(@"Car: %@ index: %i", object, index);
} options:NSEnumerationReverse];
// Car: F458 Italia index: 2
// Car: F50 index: 1
// Car: Testarossa index: 0 [cars map:^(NSString* car) {
return car.lowercaseString;
}];
// testarossa, f50, f458 italia // Or, a more common example:
[cars map:^(NSString* carName) {
return [[Car alloc] initWithName:carName];
}];
// array of Car objects NSArray *mixedData = @[ @1, @"Objective Sugar!", @"Github", @4, @"5"]; [mixedData select:^BOOL(id object) {
return ([object class] == [NSString class]);
}];
// Objective Sugar, Github, 5 [mixedData reject:^BOOL(id object) {
return ([object class] == [NSString class]);
}];
// 1, 4 NSArray *numbers = @[ @5, @2, @7, @1 ];
[numbers sort];
// 1, 2, 5, 7 cars.sample
// 458 Italia
cars.sample
// F50

NSArrayonly

NSArray *numbers = @[@1, @2, @3, @4, @5, @6];

// index from 2 to 4
numbers[@"2..4"];
// [@3, @4, @5] // index from 2 to 4 (excluded)
numbers[@"2...4"];
// [@3, @4] // With NSRange location: 2, length: 4
numbers[@"2,4"];
// [@3, @4, @5, @6] NSValue *range = [NSValue valueWithRange:NSMakeRange(2, 4)];
numbers[range];
// [@3, @4, @5, @6] [numbers reverse];
// [@6, @5, @4, @3, @2, @1] NSArray *fruits = @[ @"banana", @"mango", @"apple", @"pear" ]; [fruits includes:@"apple"];
// YES [fruits take:3];
// banana, mango, apple [fruits takeWhile:^BOOL(id fruit) {
return ![fruit isEqualToString:@"apple"];
}];
// banana, mango NSArray *nestedArray = @[ @[ @1, @2, @3 ], @[ @4, @5, @6, @[ @7, @8 ] ], @9, @10 ];
[nestedArray flatten];
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 NSArray *abc = @[ @"a", @"b", @"c" ];
[abc join];
// abc [abc join:@"-"];
// a-b-c NSArray *mixedData = @[ @1, @"Objective Sugar!", @"Github", @4, @"5"]; [mixedData detect:^BOOL(id object) {
return ([object class] == [NSString class]);
}];
// Objective Sugar // TODO: Make a better / simpler example of this
NSArray *landlockedCountries = @[ @"Bolivia", @"Paraguay", @"Austria", @"Switzerland", @"Hungary" ];
NSArray *europeanCountries = @[ @"France", @"Germany", @"Austria", @"Spain", @"Hungary", @"Poland", @"Switzerland" ]; [landlockedCountries intersectionWithArray:europeanCountries];
// landlockedEuropeanCountries = Austria, Switzerland, Hungary [landlockedCountries unionWithArray:europeanCountries];
// landlockedOrEuropean = Bolivia, Paraguay, Austria, Switzerland, Hungary, France, Germany, Spain, Poland [landlockedCountries relativeComplement:europeanCountries];
// nonEuropeanLandlockedCountries = Bolivia, Paraguay [europeanCountries relativeComplement:landlockedCountries];
// notLandlockedEuropeanCountries = France, Germany, Spain, Poland [landlockedCountries symmetricDifference:europeanCountries];
// uniqueCountries = Bolivia, Paraguay, France, Germany, Spain, Poland

NSMutableArray

NSMutableArray *people = @[ @"Alice", @"Benjamin", @"Christopher" ];

[people push:@"Daniel"]; // Alice, Benjamin, Christopher, Daniel

[people pop]; // Daniel
// people = Alice, Benjamin, Christopher [people pop:2]; // Benjamin, Christopher
// people = Alice [people concat:@[ @"Evan", @"Frank", @"Gavin" ]];
// people = Alice, Evan, Frank, Gavin [people keepIf:^BOOL(id object) {
return [object characterAtIndex:0] == 'E';
}];
// people = Evan

NSDictionary

NSDictionary *dict = @{ @"one" : @1, @"two" : @2, @"three" : @3 };

[dict each:^(id key, id value){
NSLog(@"Key: %@, Value: %@", key, value);
}];
// Key: one, Value: 1
// Key: two, Value: 2
// Key: three, Value: 3 [dict eachKey:^(id key) {
NSLog(@"Key: %@", key);
}];
// Key: one
// Key: two
// Key: three [dict eachValue:^(id value) {
NSLog(@"Value: %@", value);
}];
// Value: 1
// Value: 2
// Value: 3 NSDictionary *errors = @{
@"username" : @[ @"already taken" ],
@"password" : @[ @"is too short (minimum is 8 characters)", @"not complex enough" ],
@"email" : @[ @"can't be blank" ];
}; [errors map:^(id attribute, id reasons) {
return NSStringWithFormat(@"%@ %@", attribute, [reasons join:@", "]);
}];
// username already taken
// password is too short (minimum is 8 characters), not complex enough
// email can't be blank [errors hasKey:@"email"]
// true
[errors hasKey:@"Alcatraz"]
// false

NSString

NSString *sentence = NSStringWithFormat(@"This is a text-with-argument %@", @1234);
// This is a text-with-argument 1234 [sentence split];
// array = this, is, a, text-with-argument, 1234 [sentence split:@"-"]
// array = this is a text, with, argument 1234 [sentence containsString:@"this is a"];
// YES

C

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

个人评价

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

Kiwi

简介

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

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

使用

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"

NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:0];
NSString *ago = [date timeAgo];
NSLog(@"Output is: \"%@\"", ago);
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

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

还能使用枚举

label.text = [NSString fontAwesomeIconStringForEnum:FAGithub];

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

个人评价

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

NSObject-AutoDescription

简介

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

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

使用

#import "NAUser.h"
#import "NSObject+AutoDescription.h" @implementation NAUser - (NSString *)description
{
return [self autoDescription];
} @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. [iOS]数据库第三方框架FMDB详细讲解

    [iOS]数据库第三方框架FMDB详细讲解 初识FMDB iOS中原生的SQLite API在进行数据存储的时候,需要使用C语言中的函数,操作比较麻烦.于是,就出现了一系列将SQLite API进行封 ...

  2. epoll的原理和使用方法

    设想一个场景:有100万用户同一时候与一个进程保持着TCP连接,而每个时刻仅仅有几十个或几百个TCP连接时活跃的(接收到TCP包),也就是说,在每一时刻,进程值须要处理这100万连接中的一小部分连接. ...

  3. eclipse 集成maven插件

    本文转载自:http://www.blogjava.net/fancydeepin/archive/2012/07/13/eclipse_maven3_plugin.html 环境准备: eclips ...

  4. 【转载】cocos2d-x2.2.3和android的平台环境

    这两天试图按照教程来学习写游戏移植到的横版过关Android在.在网上找了很多教程,但版本号变化.所使用的工具有细微的差别.所以,现在我们还没有准备好,阅读后,下面的文章.最后能够顺利您的手机上跑起来 ...

  5. SWTBOK測试实践系列(4) -- 软件測试技术的黑白之道

    白盒測试和黑盒測试往往是项目中最受争议的两种測试类型,每一个人偏爱各不同.现实生活中行业人员大多喜欢白盒測试而忽视黑盒測试,那么项目中又应该怎样平衡这两类測试呢?我们先来看两个案例. 案例一: 某移动 ...

  6. Play Framework Web开发教程(33): 结构化页面-组合使用模板

    和你编写代码相似,你编写的页面也能够由多个小的片段组合而成,这些小的片段本身也能够由更小的片段构成.这些小片段一般是能够在其他页面反复使用的:有些部分能够用在全部页面,而有些部分是某些页面特定的.本篇 ...

  7. openssl 非对称加密算法DSA命令详解

    1.DSA算法概述 DSA算法是美国的国家标准数字签名算法,它只能用户数字签名,而不能用户数据加密和密钥交换. DSA与RSA的生成方式不同,RSA是使用openssl提供的指令一次性的生成密钥(包括 ...

  8. Stm32高级定时器(一)

    Stm32高级定时器(一) 1 定时器的用途 2 高级定时器框图 3 时基单元 4 通道 1 定时器的用途 已知一个波形求另一个未知波形(信号长度和占空比) 已知波形的信号长度和占空比产生一个相应的波 ...

  9. (转)Java 代码优化过程的实例介绍

    简介: 通过笔者经历的一个项目实例,本文介绍了 Java 代码优化的过程,总结了优化 Java 程序的一些最佳实践,分析了进行优化的方法,并解释了性能提升的原因.从多个角度分析导致性能低的原因,并逐个 ...

  10. iOS_SN_Socket网络编程(一)

    1.Socket简介 首先让我们通过一张图知道socket在哪里? socket在哪里 Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口. 2.TCP和UDP的区别 在这里就 ...