KeiSwiftFramework 0.4.9

KeiSwiftFramework 0.4.9

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最后发布日期2016年12月
SwiftSwift版本3.0
SPM支持SPM

KeiTestLibTrunk维护。



  • Keun young Kim

KeiSwiftFramework

使用方法

日期

时间间隔
// 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
日期组件
let now = NSDate()
let tenMinutesBefore = now - 10.minute
let twoHoursAfter = now + 2.hour

let month = now.month
比较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 {
    // ...
}

颜色

解析十六进制颜色字符串 #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设置

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
    }
}

时间分析器

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

文件 & 目录

NSURL扩展
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
防止文件备份到iCloud和iTunes
url.excludedFromBackup = true
// or
url.addSkipBackupAttribute()
// or
NSFileManager.defaultManager().addSkipBackupAttributeToItemAtURL(url)
// or
do {
    try url.addSkipBackupAttributeOrThrows()
    // or
    try NSFileManager.defaultManager().addSkipBackupAttributeToItemAtURLOrThrows(url)
} catch {}

要求

iOS 8或更高版本

安装

KeiSwiftFramework可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中

pod "KeiSwiftFramework"

作者

Keun young Kim, [email protected]

许可证

KeiSwiftFramework可在MIT许可证下获取。有关更多信息,请参阅LICENSE文件。