对Swift标准库、 Foundation、UIKit 提供了很多高级扩展函数,包括以下内容:
- NSObject
- Bool
- Int
- Double
- String
- NSAttritedString
- Array
- Dictioanry
- NSDate
- NSTimer
- CGRect
- UIViewController
- UIView
- UITextView
- UILabel
- UIImageView
- UIImage
- Block Objects
- UIDevice
- NSUserDefauts
- NSURL EZ function and variables
示例代码:
通过索引获取对象
1 | var myArray = [ "charmander" , "bulbasaur" , "squirtle" ] |
随机获取对象
1 | var myArray = [ "charmander" , "bulbasaur" , "squirtle" ] |
通过对象获取索引
1 | var myArray = [ "charmander" , "bulbasaur" , "squirtle" , "charmander" ] |
2 | print(myArray.indexesOf( "charmander" )) |
检查数组中是否包含另一个数组
1 | var myArray = [ "charmander" , "bulbasaur" , "squirtle" ] |
2 | print(myArray.containsArray([ "charmander" , "bulbasaur" ])) |
3 | print(myArray.containsArray([ "string" ])) |
切换布尔值
初始化颜色
1 | let myColor = UIColor(r: 100 , g: 100 , b: 100 ) |
延迟执行代码
1 | Timer.runThisAfterDelay(seconds: 2 ) { () -> () in |
2 | print( "Prints this 2 seconds later in main queue" ) |
每秒执行代码
2 | Timer.runThisEvery(seconds: 1 ) { (timer) -> Void in |
3 | print( "Will print every second" ) |
获取项目版本信息
3 | print(ez.appVersionAndBuild) |
检测屏幕截图
1 | ez.detectScreenShot { () -> () in |
2 | print( "User took a screen shot" ) |
更多请参见开源代码主页。