RHBKit 1.0.959

RHBKit 1.0.959

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2018 年 8 月
SPM支持 SPM

Lazar Otasevic 维护。



RHBKit 1.0.959

RHBKit

CI Status Version License Platform

内容

核心,所有平台

  • 数据堆栈和获取数据包装器
  • 用于背景获取数据的通用表格视图数据源
  • 操作和队列
  • 预测和运算符
  • 加密检查器
  • 内存诊断
  • Objective-C 延迟,单例和转换
  • 可变协议
  • 实用工具,调试,析构函数
  • 本地扩展

额外功能,平台子集

  • 方向跟踪器 {ios, watchos}
  • UIKit:表格数据源,应用设置,伪造进度视图 {ios, tvos}
  • 针对各种平台的本地扩展

示例和代码段 [Swift]

通用数据源和背景获取

dataStack.backgroundFetch(fetchRequest) { [weak self] controller, mainContext in
    self?.tableViewDataSource = TableViewDataSource(controller, mainContext)
    self?.tableView.reloadData()
}

最佳加速度计方向跟踪器,适用于 watchos

orientationTracker.startTracking { [weak self] tracker in
    UIView.animate(withDuration: 0.3) {
        self?.imageView.transform = CGAffineTransform(rotationAngle: -CGFloat(tracker.deviceRotation))
    }
}

Core 数据操作

queue.addCoreDataOperation(persistentContainer) { context in
    try! context.fetch(TestEntity.fetchRequest()).forEach { context.delete($0) }
    try! context.save()
}

NSPersistentContainer 扩展用于异步存储加载,带有伪造进度

progressView.startProgress()
container.loadStoresAsync { [weak self] _, errors in
    self?.progressView.endProgess(errors.isEmpty)
}

调试

Debug.execute { print("log in debug only") }

构建时修改

let queue = OperationQueue().mutate { $0.maxConcurrentOperationCount = 1 }

用于构建 NSPredicate 的算术运算符的 PredicateKey

let predicate1 = PredicateKey("name") == "Sisoje"
let predicate2 = PredicateKey(#keyPath(TestEntity.name)) == "Sisoje"
let predicate3 = \TestEntity.name == "Sisoje"

用于构建复杂预测的 NSPredicate 逻辑运算符

let predicate = !predicate1 || predicate2

带有操作参数的块

queue.addOperationInside { operation in
    while !operation.isCancelled { printf("doing some work") }
}

集合安全索引

let optional = array[safe: 55]

方便构造函数

NSManagedObjectModel(name: "TestModel", in: Bundle.main)
NSFetchedResultsController(performing: request, in: context)
UIColor(colorReference: 0x112233)

通知中心添加和删除

var removeObserver: (() -> Void)?
removeObserver = NotificationCenter.default.addRemovableObserver(.UIApplicationWillEnterForeground) { _ in
    removeObserver?()
}

带有返回块的应用程序设置

application.openApplicationSettings {
    printf("back from settings, something maybe changed")
}

加密检查器

let isEncrypted = RHBEncryptionChecker.isEncrypted(main)

内存诊断

let memoryUsed = RHBDiagnostics.memoryUsed()

示例和代码片段 (Objective-C)

延迟

RHB_DEFER {
    NSLog(@"time to release something");
}];

单例

@implementation MySingleton
    RHB_SINGLETON(sharedInstance)
@end

类型转换

NSArray *array = [NSArray rhb_dynamicCast:self.collection];
if (array) {
    NSLog(@"It is array: %@", array);
}

要求

  • Swift 4.0

  • 平台

      { :ios => "10.0", :watchos => "3.0", :tvos => "10.0", :osx => "10.12" }
    

安装

RHBKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'RHBKit'

作者

Lazar Otasevic, [email protected]

许可协议

RHBKit 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。