This is supposed to be a Swift Library for simplified access to common iOS/MacOS/tvOS libraries, such as Security (Keychain access) or Core Data (database management). The purpose is to write wrappers around common problems in developing iOS/MacOS/tvOS applications and make them accessible to the public.
Why program the same routines over and over again? Why write so many lines of code just to set up a Core Data database with proper error handling? Why use the low level functions of Security with a 'not-so-pretty' C-style API? This frameworks builds upon these commonly used APIs, providing some functionality that you, as a developer, would have implemented yourself anyways.
Example:
guard let
modelPath = NSBundle.mainBundle().pathForResource(managedObjectModelName, ofType: "momd")?.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()),
modelURL = NSURL(string: modelPath),
model = NSManagedObjectModel(contentsOfURL: modelURL) else {
print("Warning: database was not created due to invalid file path.")
return nil
}
self.storeCoordinator = NSPersistentStoreCoordinator(managedObjectModel: model)
self.mainContext.persistentStoreCoordinator = self.storeCoordinator
do {
let userDirectory = try NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true).URLByAppendingPathComponent("\(storeName).sqlite")
try self.storeCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: userDirectory, options: nil)
} catch let error as NSError {
print("Error while creating a Core Data persistent store on disk.")
print(error.localizedDescription)
return nil
}
becomes:
STDatabase(managedObjectModelName: managedObjectModelName, persistentStoreName: storeName)
Starting with Core Data and Security, a simple base layer is set for secure applications that lets a developer store passwords, certificates or other credentials in a secure manner in the keychain while using the Core Data API to build a model for their Model-View-Controller structure. The future will bring network access to setup server connections and hopefully manage synchronization between the Core Data layer and server data. Further, there is also some potential for new User Interface elements, such as an improved default camera (ever used UIImagePickerController? Easy to use, but not too awesome ...).
"import SwifTrix" in your project, add the library to your app's dependencies and you're ready to go. All classes inside SwifTrix are prefixed with an "ST", which gives you classes like STDatabase or STKeychainItem. All classes and methods are documented as good as possible, but some knowledge about CoreData or the concept of attributes in the keychain is still required.
With iOS 8.0 frameworks became available for apps. So since this project is a framework, the minimum system version is iOS 8.0 (although you might be able to compile it as a static library or just C&P the source code). Swift on the other hand is only available on Mac OS 10.9+, so sorry to all 32-bit Mac Users: You'll have to rewrite it in Obj-C.
Go ahead!