Giter VIP home page Giter VIP logo

linkblock's Introduction

#LinkBlock LinkBlock icon

What is this?

  • 这是一个objc扩展集合链式编程,为的是告别换行和[],用最简短的一句话尽可能多的完成功能。
  • 框架封装原生Fundation最基本功能和最常见功能。
  • 持续更新
  • This is objective-c link block , to chain programming.
  • Frame encapsulation of native Foundation is the most basic and the most common functions.
  • Continuously updated ##Simple to use LinkBlock ;
LinkBlock.h

##Shit CGRectMake()

//Such written before 
//手绘UI动不动就要创建4,5个变量,而这明明是可以省略的步骤
UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame= CGRectMake(20, 20, 150, 80);
UIColor *color = [UIColor colorWithRed:255/255.0 green:22/255.0 blue:150/255.0 alpha:1.0];
btn.backgroundColor = color;
[btn setTitle:@"click change color" forState:UIControlStateNormal];
[self.view addSubview:btn];

##Bye CGRectMake(),just a.b.c...

//如果使用链式编程的方式,大部分工作可以在思路不断的情况下一气呵成
//now just using one line.Most work can be wrapped up in the idea of ​​ongoing cases
btn.viewSetFrame(20,20,150,80).viewBGColor(@"0xff22cc".strToColorFromHexStr())
.viewAddToView(self.view).btnTitle(@"click change color", UIControlStateNormal);

##Very good string functions

//去空格和换行,并打印
@" 吴 倩 莲 的 风 和 欲 啊 \r\n 藏 了 多 少 梦 ".strClearSpaceAndWrap().nslog();
//字符串比较大小
@"123".strCompare(@"111");
//对数字敏感的字符串比较
@"abc1.txt".strCompareNumberSensitive(@"abc2.txt");

//字符串常量直接转颜色
@"0xff22cc".strToColorFromHexStr();
@"#ff22cc".strToColorFromHexStr();
@"ff22cc".strToColorFromHexStr();

//正则表达式替换_xxx_为[xxx]
@"name=_boom_".strRegexReplace(@"(_)(\\w+)(_)" , @"[$2]").nslog();
//正则表达式验证是否为邮箱
@"[email protected]".strRegexIsMatch(@"^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$") ? @"YES email".nslog() : @"NO email".nslog();


//数组过滤
NSArray* arrForFilter = @[ @{@"name":@"ali", @"age":@(123)} ,
@{@"name":@"bli", @"age":@(0)}   ,
@{@"name":@"cli", @"age":@(12)}  ,
@{@"name":@"dli", @"age":@(-45)}  ];
//过滤age<0的数据
arrForFilter.arrFilter(@"age<0").nslog();
//过滤age<0的数据
[arrForFilter arrEnumerateWithPredicateFormat:@"age>-1 and age<100"
usingBlock:^(NSObject* obj, NSUInteger idx, BOOL *stop) {
obj.nslog();
}];

##NSDictionary get value safely

dict.dictGetNoNSNull(@"key");
dict.dictGetBOOLNoNullType(@"key");
dict.dictGetArrNoNullType(@"key");
dict.dictGetViewNoNullType(@"key");

##Do animation quickly

view.viewAnimateShakeHorizental(0.5);
btn.viewAnimateRemove();
btn.viewAnimateFlipFromTop(0.5,1,YES);
... ...

##end()

//如果你想在链条结尾获取绝对真实的对象值(继承NSObject)你需要在最后使用end()
//因为你可能得到的是LinkError对象
//If you want get real type of vale.you should using 'end()' at chain end.
//Because you may get LinkError
NSString *str2 = str1.strAppend(str0).strAt(15).end();

##What is LinkError

  • 由于objc是有弱类型语言特征的语言,block是作为了扩展的属性,才可以被'.'出来。当中间一个链条返回的对象是nil,或者非预期的类型,那么下一根链条就会断裂,报错。为了让链条能够在安全的情况下容错走通,那么引入一个新的单例的类型LinkError 。这个对象响应所有扩展属性的调用,功能仅仅返回自己到下一根链条以供传递。所以end()方法的使用对于获取链条末尾的返回值至关重要。
  • LinkError can respond to all extension property,it just return self to next chain.And not break,not throw an exception.

##Bug-mail address,join us address [email protected] ##希望大家都支持链式编程这种编程方式

  • 做天朝良好的程序员

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.