CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.

HFUtility 2.0.13

HFUtility 2.0.13

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Apr 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by HFCoreUI.



 
Depends on:
TinyLog>= 0
SwiftKeychainWrapper>= 0
 

HFUtility 2.0.13

  • By
  • .

HFUtility

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Common

  • To print log only while you have DEBUG flag at OTHER_SWIFT_FLAG in Debug mode, just append following script at your Podfile.

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

Now you can freely print sensitive logs using log, logw, loge.

  • Sometimes you need to have to cast nilable object into number(CGFloat, Float, Int, Bool), then just call as shown below.

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
}

Utilities

  • HFAsync provides simple way to run asynchronous task and callback notification.

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 provides simple way to compare version string

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")

Local Data Management

  • HFLocalStorage provides simple way to save and load object

To save into or load from local dictionary(suppose that you have an object somewhere like below)


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

  • extensions of NSKeyedArchiver and NSKeyedUnarchiver provides simple way to archive and unarchive object

To archive object that conforms to protocol NSCoding,


NSKeyedArchiver.archiveObject("path/to/file", object: objectToArchive, key: "OBJECT_KEY")

To unarchive archived NSCoding-conformed object from file,


let unarchivedObject = NSKeyedArchiver.archiveObject("path/to/file", key: "OBJECT_KEY")

Data Handling

  • HFJSON provides simple way to get JSON object from String, and vice versa.

Suppose that you have JSON string from server or somewhere,


let dict = HFJSON.jsonFrom(jsonResponseText)

let jsonString = HFJSON.stringFrom(dict)

  • Dictionary+HF provides simple way to pick an object from complicated dictionary

Suppose that a dictionary with data is given below,


{

    "productList": [{

        "productId": 0,

        "productName": "Product 0",

        "components": [{

            "componentId": 100,

            "componentName": "Component 100",

            "parts": [{

                "partId": 1000,

                "partName": "Part 1000"

            },{

                "partId": 2000,

                "partName": "Part 2000"

            }]

        }

    }
}

To get second part name of first component of first product, just call extension method below.


// 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"

Cryptors

This feature moved to another repository, click link below.

https://github.com/DragonCherry/HFSecurity

Requirements

Installation

HFUtility is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "HFUtility"

Author

DragonCherry, [email protected]

License

HFUtility is available under the MIT license. See the LICENSE file for more info.