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

KeiSwiftFramework 0.4.9

KeiSwiftFramework 0.4.9

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by KeiTestLibTrunk.



  • By
  • Keun young Kim

KeiSwiftFramework

Usage

Date

Time Interval
// 1 hour 30 min
let interval = 1.hour + 30.minute       // 5400.0
let min = interval.minuteInterval       // 90.0
let hour = interval.hourInterval        // 1.5

let yesterday = Yesterday.startDate
let now = Today.now
let minInterval = (now - yesterday).minuteInterval
let hourInterval = (now - yesterday).hourInterval
Date Components
let now = NSDate()
let tenMinutesBefore = now - 10.minute
let twoHoursAfter = now + 2.hour

let month = now.month
Compare NSDate
let date1 = NSDate(timeIntervalSince1970: 0)
let date2 = NSDate()

if date1 < date2 {
    print("asc")
} else if date1 > date2 {
    print("desc")
} else {
    print("same")
}
// Supported Operators : ==, !=, <, <=, >, >=


let now = Today.now
if now == KWeekday.Sunday {
    // ...
}

if now == KMonth.March {
    // ...
}

Color

Parse Hex Color String #RGB, #ARGB, #RRGGBB, #AARRGGBB
let hexString = "#03a9f4"
let color = UIColor(hexString: hexString)
let color2 = hexString.UIColorValue

if hexString.isHexColorString {
    // ...
}

if let color = hexString.parseHexColorString() {
    // ...
}

CoreData Setup

class AppDelegate: KApp {
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        setupCoreData(modelName: "Model Name")
        // or
        setupCoreData(modelName: "Model Name", storeType: NSSQLiteStoreType, useLightweightMigration: true)

        return true
    }
}

Time Profiler

KTimeProfiler.start()                       // Required
// ...
KTimeProfiler.checkpoint()
// ...
KTimeProfiler.checkpoint("Create File")
// ...
KTimeProfiler.checkpoint("Save to DB")
// ...
KTimeProfiler.report(verbose: true)

// Verbose Report
// KTimeProfiler: application(_:didFinishLaunchingWithOptions:) in 0.801861s
// ==================================================
// Start            0
// Checkpoint 1    +0.100269
// Create File     +0.301065
// Save to DB      +0.200434
// End             +0.200093
// ==================================================
// total            0.801861
// ==================================================

File & Directory

NSURL Extension
let url = NSURL(fileURLWithPath: ...)

// read only
url.name
url.exist
url.isDirectory
url.fileSize
url.creationDate
url.lastAccessDate
url.modificationDate

// read/write
url.hidden
url.excludedFromBackup
Prevent files from being backed up to iCloud and iTunes
url.excludedFromBackup = true
// or
url.addSkipBackupAttribute()
// or
NSFileManager.defaultManager().addSkipBackupAttributeToItemAtURL(url)
// or
do {
    try url.addSkipBackupAttributeOrThrows()
    // or
    try NSFileManager.defaultManager().addSkipBackupAttributeToItemAtURLOrThrows(url)
} catch {}

Requirements

iOS 8 or higher

Installation

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

pod "KeiSwiftFramework"

Author

Keun young Kim, [email protected]

License

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