APSwiftHelpers 0.0.2

APSwiftHelpers 0.0.2

测试已测试
Lang语言 SwiftSwift
许可证 MIT
释放最后发布2016 年 5 月
SPM支持 SPM

Alex Plescan 维护。



  • Alex Plescan

APSwiftHelpers

为在 Swift 中开发 iOS 应用程序而提供的常用工具集合。如果觉得有帮助,请帮忙。

安装

用法

调度

处理 Grand Central Dispatch 队列的工具

// Perform a block on the given queue
performOn(.Main) { self.tableView.reloadData() }
performOn(.LowPriority) { self.clearCache() }

// Delay a block on the given queue - if no queue is provided .Main is assumed
delay(0.5) { self.hideSpinner() }
delay(30, .Background) { self.logActivity() }

// Queue types available:
enum QueueType {
  case Main         // The app's main queue
  case Background   // Background queue (DISPATCH_QUEUE_PRIORITY_BACKGROUND)
  case LowPriority  // Background queue (DISPATCH_QUEUE_PRIORITY_LOW)
  case HighPriority // Background queue (DISPATCH_QUEUE_PRIORITY_HIGH)
}

NSCoding+Helpers

扩展 NSCoding,使其更适合 Swift 使用

// Archive an NSCoding to NSData
let note = Note(title: "secret", content: "I like turtles")
let archivedData = note.archive()

// Unarchive NSData into an NSCoding object
let unarchivedNote = Note.unarchive(archivedData)
unarchivedNote.content // "I like turtles"

CATransaction+Helpers

// Run the given block with CAAnimations disabled
withCAAnimationsDisabled { self.view.resize() }

NSLocale+Helpers

// Fetch region info from NSLocale:
NSLocale.currentLocale().countryCode // String e.g.: "US"
NSLocale.currentLocale().countryName // String e.g.: "United States"

App

// Get info about the currently running app (taken from the
// main bundle's) Info.plist file
App.name
App.version
App.formattedNameAndVersion

// Returns true/false whether the app running within the simulator or not
App.inSimulator

// Returns true/false whether the app is running in DEBUG mode
App.isDebug

DebugLogging

// Print a formatted log message for a CustomDebugStringConvertible

struct Animal: CustomDebugStringConvertible {
  let name: String
  var debugDescription: String { return name }
}

let dog = Animal(name: "Woofy")
debugLog(dog, "is tired") // prints "(Woofy) is tired" to the console