测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年4月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 HFCoreUI 维护。
依赖 | |
TinyLog | >= 0 |
SwiftKeychainWrapper | >= 0 |
要运行示例项目,请克隆仓库,然后首先从 Example 文件夹中运行 pod install
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'HFUtility'
target.build_configurations.each do |config|
if config.name == 'Debug'
config.build_settings['OTHER_SWIFT_FLAGS'] = '-D' 'DEBUG'
else
config.build_settings['OTHER_SWIFT_FLAGS'] = ''
end
end
end
end
end
现在您可以使用 log、logw、loge 任意打印敏感的日志。
if boolean(view?.hidden) {
// do your fantastic job
}
if boolean(view?.hidden, defaultValue: false) {
// do your fantastic job
}
if integer(view?.subviews.count) > 0 {
// do your fantastic job
}
if integer(view?.subviews.count, defaultValue: 0) > 0 {
// do your fantastic job
}
if cgfloat(view?.frame.size.width) <= self.view.width {
// do your fantastic job
}
if cgfloat(view?.frame.size.width, defaultValue: self.view.width) <= self.view.width {
// do your fantastic job
}
HFAsync.invokeAsync(
1, // initial delay interval before start worker closure
worker: {
// do your job async
}, completion: {
// notify or update UI, this closure gonna be called in main thread.
})
HFVersion.systemVersionEqualTo("9.3")
HFVersion.systemVersionGreaterThan("9.3")
HFVersion.systemVersionGreaterThanOrEqualTo("9.3")
HFVersion.systemVersionLessThan("9.3")
HFVersion.systemVersionLessThanOrEqualTo("9.3")
HFVersion.versionEqualTo("9.3", comparedTo: "9.2")
HFVersion.versionGreaterThan("9.3", comparedTo: "9.2")
HFVersion.versionGreaterThanOrEqualTo("9.3", comparedTo: "9.2")
HFVersion.versionLessThan("9.3", comparedTo: "9.2")
HFVersion.versionLessThanOrEqualTo("9.3", comparedTo: "9.2")
要将对象保存到或从本地字典中加载(假设您有一个类似下面的对象)
let storage = HFLocalStorage(fileName: "test.db", directoryType: .LibraryDirectory)
storage.saveObject(["Any", "Kinds", "Of", "NSCoding", "Objects"], "TEST_KEY") // save
let array = storage.loadObject("TEST_KEY") as? [String] // load
要归档遵循 NSCoding 协议的对象
NSKeyedArchiver.archiveObject("path/to/file", object: objectToArchive, key: "OBJECT_KEY")
从文件中解档归档的 NSCoding 遵循对象
let unarchivedObject = NSKeyedArchiver.archiveObject("path/to/file", key: "OBJECT_KEY")
假设您从服务器或其他地方获取 JSON 字符串
let dict = HFJSON.jsonFrom(jsonResponseText)
let jsonString = HFJSON.stringFrom(dict)
假设给定以下包含数据的字典
{
"productList": [{
"productId": 0,
"productName": "Product 0",
"components": [{
"componentId": 100,
"componentName": "Component 100",
"parts": [{
"partId": 1000,
"partName": "Part 1000"
},{
"partId": 2000,
"partName": "Part 2000"
}]
}
}
}
要获取第一产品的第一组件的第二部分的名称,只需调用以下扩展方法即可。
// where jsonDict is an object type of [String: AnyObject]?
let partName = jsonDict?.objectForKeyPath("productList[0].components[0].parts[1].partName") as? String
NSLog("partName: \(partName)") // will get "Part 2000"
此功能已移至另一个仓库,点击以下链接。
https://github.com/DragonCherry/HFSecurity
HFUtility 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "HFUtility"
DragonCherry, [邮箱地址保护]
HFUtility 在 MIT 许可证下可用。更多信息请参阅 LICENSE 文件。