Skip to content

Commit

Permalink
Changes for the latest version of SDK 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Syerram committed Sep 3, 2015
1 parent ce52608 commit 201a1f3
Show file tree
Hide file tree
Showing 31 changed files with 107 additions and 128 deletions.
6 changes: 3 additions & 3 deletions asphalos/AccountEditController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ class AccountEditController: FormViewController, FormViewControllerDelegate {
category.accountCount = NSNumber(int: category.accountCount.integerValue + 1)
}
///MARK: TODO Perhaps we can use property descriptors and then check validity on the object itself
account!.name = values[Fields.Name] as String
account!.userName = values[Fields.UserName] as String
account!.password = values[Fields.Password] as String
account!.name = values[Fields.Name] as! String
account!.userName = values[Fields.UserName] as! String
account!.password = values[Fields.Password] as! String
account!.category = self.category

//Non required values
Expand Down
4 changes: 2 additions & 2 deletions asphalos/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

lazy var applicationDocumentsDirectory: NSURL = {
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1] as NSURL
return urls[urls.count-1] as! NSURL
}()

lazy var managedObjectModel: NSManagedObjectModel = {
Expand All @@ -79,7 +79,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict as [NSObject : AnyObject])
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
Expand Down
22 changes: 11 additions & 11 deletions asphalos/CategoriesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CategoriesController: UITableViewController, CategoryDelegate, SettingsDel

///MARK: Refresh methods
func loadData(reload:Bool = false) {
self.categories = NSManagedObject.fetchAll("Category", sortKeys: [("name", true)]) as [Category]
self.categories = NSManagedObject.fetchAll("Category", sortKeys: [("name", true)]) as! [Category]
if reload {
self.tableView.reloadData()
}
Expand Down Expand Up @@ -76,7 +76,7 @@ class CategoriesController: UITableViewController, CategoryDelegate, SettingsDel
func settings() {
self.pushControllerOnNavigationStack("SettingsController", callback: { (controller:SettingsController) -> () in
controller.settingsDelegate = self
}, transitionSyle: nil)
})
}

// MARK: - Table view data source
Expand All @@ -101,9 +101,9 @@ class CategoriesController: UITableViewController, CategoryDelegate, SettingsDel
cell.textLabel?.text = accountResults[indexPath.row].name
cell.detailTextLabel?.text = accountResults[indexPath.row].category.name
} else {
cell = tableView.dequeueReusableCellWithIdentifier("CategoryCell", forIndexPath: indexPath) as UITableViewCell
(cell.contentView.viewWithTag(1) as UILabel).text = categories[indexPath.row].name
(cell.contentView.viewWithTag(2) as UILabel).text = "\(categories[indexPath.row].accountCount) accounts"
cell = tableView.dequeueReusableCellWithIdentifier("CategoryCell", forIndexPath: indexPath) as! UITableViewCell
(cell.contentView.viewWithTag(1) as! UILabel).text = categories[indexPath.row].name
(cell.contentView.viewWithTag(2) as! UILabel).text = "\(categories[indexPath.row].accountCount) accounts"
}
return cell
}
Expand All @@ -129,10 +129,10 @@ class CategoriesController: UITableViewController, CategoryDelegate, SettingsDel
var editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Edit") {
(action, indexPath) -> Void in
println("Edit")
self.pushControllerOnNavigationStack("CategoryEditController", callback: { (controller:CategoryEditController) -> () in
self.pushControllerOnNavigationStack("CategoryEditController", transitionSyle: nil, callback: { (controller:CategoryEditController) -> () in
controller.category = self.categories[indexPath.row]
controller.categoryDelegate = self
}, transitionSyle: nil)
})
}
editAction.backgroundColor = UIColor.greenColor()

Expand All @@ -146,12 +146,12 @@ class CategoriesController: UITableViewController, CategoryDelegate, SettingsDel

//MARK: Private
private func filter(q:String) {
self.accountResults = NSManagedObject.fetch("Account", predicates: { () -> NSPredicate in
return NSPredicate(format: "%K CONTAINS[cd] %@", "name", q)!
}, sortKeys: [("name", true)]) as [Account]
self.accountResults = (NSManagedObject.fetch("Account", sortKeys: [("name", true)], predicates: { () -> NSPredicate in
return NSPredicate(format: "%K CONTAINS[cd] %@", argumentArray: ["name", q])
}) as? [Account])!
}

func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -> Bool {
func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String!) -> Bool {
self.filter(searchString)
return true
}
Expand Down
10 changes: 5 additions & 5 deletions asphalos/CategoryController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class CategoryController: UITableViewController, AccountDelegate {

///MARK: Refresh methods
func loadData(reload:Bool = false) {
self.accounts = NSManagedObject.fetch("Account", predicates: { () -> NSPredicate in
return NSPredicate(format: "category = %@", self.category)!
}, sortKeys: [("name", true)]) as [Account]
self.accounts = NSManagedObject.fetch("Account", sortKeys: [("name", true)], predicates: { () -> NSPredicate in
return NSPredicate(format: "category = %@", argumentArray: [self.category])
}) as! [Account]
if reload {
self.tableView.reloadData()
}
Expand Down Expand Up @@ -90,8 +90,8 @@ class CategoryController: UITableViewController, AccountDelegate {


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("AccountCell", forIndexPath: indexPath) as UITableViewCell
(cell.contentView.viewWithTag(1) as UILabel).text = accounts[indexPath.row].name
let cell = tableView.dequeueReusableCellWithIdentifier("AccountCell", forIndexPath: indexPath) as! UITableViewCell
(cell.contentView.viewWithTag(1) as! UILabel).text = accounts[indexPath.row].name
return cell
}

Expand Down
2 changes: 1 addition & 1 deletion asphalos/CategoryEditController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CategoryEditController: FormViewController, FormViewControllerDelegate {
if isNew {
category = NSManagedObject.newEntity("Category") as Category
}
category!.name = (values[Fields.Name] as String).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
category!.name = (values[Fields.Name] as! String).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
Category.save()
self.proxy(categoryDelegate, callback: { (object:CategoryDelegate) -> () in
object.categoryUpdated(self.category!, isNew: isNew)
Expand Down
2 changes: 1 addition & 1 deletion asphalos/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ extension String {
//2 digits of zero-padded hex
output.appendFormat("%02x", byte)
}
return output
return output as String
}
}
8 changes: 4 additions & 4 deletions asphalos/DataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ extension NSManagedObject {

///Save all of the changes
class func save() {
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.saveContext()
}

class func managedObjectContext() -> NSManagedObjectContext? {
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
if let managedObjContext = appDelegate.managedObjectContext {
return managedObjContext
} else {
Expand Down Expand Up @@ -57,7 +57,7 @@ extension NSManagedObject {

///New entity
class func newEntity<T>(entityName:String) -> T {
return NSEntityDescription.insertNewObjectForEntityForName(entityName, inManagedObjectContext: self.managedObjectContext()!) as T
return NSEntityDescription.insertNewObjectForEntityForName(entityName, inManagedObjectContext: self.managedObjectContext()!) as! T
}

///Prepare sort descriptors for list of tuples with key, ascending order
Expand All @@ -83,7 +83,7 @@ extension NSManagedObject {
}

///Return specific objects for the given predicate
class func fetch(entityName:String, predicates:() -> NSPredicate, sortKeys:[(String, Bool)]? = nil) -> [NSManagedObject] {
class func fetch(entityName:String, sortKeys:[(String, Bool)]? = nil, predicates:() -> NSPredicate) -> [NSManagedObject] {
let fetchRequest = NSFetchRequest(entityName: entityName)
fetchRequest.predicate = predicates()
if let _sortKeys = sortKeys {
Expand Down
22 changes: 11 additions & 11 deletions asphalos/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
extension UIWindow {
///Navigate to root controller for the given nib
func navigateToRootController(nibName: String) {
var rootController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier(nibName) as UIViewController
var rootController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier(nibName) as! UIViewController
UIView.transitionWithView(self, duration: 0.5, options: UIViewAnimationOptions.TransitionCurlDown, animations: {
self.rootViewController = rootController
}, completion: nil)
Expand Down Expand Up @@ -226,19 +226,19 @@ extension UIViewController {
///Callers have the opportunity to work with the controller once its created by passing code block to callback
///@param: nibName: Pass the storyboard name for the controller
///@param: callback: Pass the code block. Ensure to provide the actual type of your controller
func pushControllerOnNavigationStack<T>(nibName:String, callback:(controller:T) -> (), transitionSyle:UIViewAnimationTransition? = nil) -> T {
func pushControllerOnNavigationStack<T>(nibName:String, transitionSyle:UIViewAnimationTransition? = nil, callback:(controller:T) -> ()) -> T {
self.navigationItem.title = ""
var controller:T = self.storyboard?.instantiateViewControllerWithIdentifier(nibName)! as T
var controller:T = self.storyboard?.instantiateViewControllerWithIdentifier(nibName) as! T
callback(controller: controller)
var currentView = self.navigationController!.view
if transitionSyle != nil {
UIView.animateWithDuration(0.75, animations: { () -> Void in
UIView.setAnimationCurve(UIViewAnimationCurve.EaseIn)
self.navigationController?.pushViewController(controller as UIViewController, animated: false)
self.navigationController?.pushViewController(controller as! UIViewController, animated: false)
UIView.setAnimationTransition(transitionSyle!, forView: currentView, cache: false)
}, completion: nil)
} else {
self.navigationController?.pushViewController(controller as UIViewController, animated: true)
self.navigationController?.pushViewController(controller as! UIViewController, animated: true)
}
return controller
}
Expand All @@ -250,18 +250,18 @@ extension UIViewController {
if transitionSyle != nil {
UIView.animateWithDuration(0.75, animations: { () -> Void in
UIView.setAnimationCurve(UIViewAnimationCurve.EaseIn)
self.navigationController?.pushViewController(controller as UIViewController, animated: false)
self.navigationController?.pushViewController(controller as! UIViewController, animated: false)
UIView.setAnimationTransition(transitionSyle!, forView: currentView, cache: false)
}, completion: nil)
} else {
self.navigationController?.pushViewController(controller as UIViewController, animated: true)
self.navigationController?.pushViewController(controller as! UIViewController, animated: true)
}
}

///Present the controller as a root controller
func presentAsRootController(nibName:String, transitionStyle:UIViewAnimationOptions) {
var controller = self.storyboard!.instantiateViewControllerWithIdentifier(nibName) as UIViewController
var appDelegate:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var controller = self.storyboard!.instantiateViewControllerWithIdentifier(nibName) as! UIViewController
var appDelegate:AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
UIView.transitionWithView(appDelegate.window!, duration: 0.5, options: transitionStyle, animations: { () -> Void in
appDelegate.window!.rootViewController = controller
}, completion: nil)
Expand All @@ -270,9 +270,9 @@ extension UIViewController {

///Present as Model
func presentAsModalController<T>(nibName:String, callback:(controller:T) -> ()) {
var controller:T = self.storyboard?.instantiateViewControllerWithIdentifier(nibName)! as T
var controller:T = self.storyboard?.instantiateViewControllerWithIdentifier(nibName)! as! T
callback(controller: controller)
var presentingController = controller as UIViewController
var presentingController = controller as! UIViewController
presentingController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
self.presentViewController(presentingController, animated: true, completion: nil)
}
Expand Down
2 changes: 1 addition & 1 deletion asphalos/FormBaseCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class FormBaseCell: UITableViewCell {
}

for visualConstraint in visualConstraints {
let constraints = NSLayoutConstraint.constraintsWithVisualFormat(visualConstraint as String, options: NSLayoutFormatOptions(0), metrics: nil, views: views)
let constraints = NSLayoutConstraint.constraintsWithVisualFormat(visualConstraint as! String, options: NSLayoutFormatOptions(0), metrics: nil, views: views)
for constraint in constraints {
customConstraints.append(constraint)
}
Expand Down
6 changes: 3 additions & 3 deletions asphalos/FormCheckCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FormCheckCell: FormTitleCell {
rowDescriptor.value = false
}

accessoryType = (rowDescriptor.value as Bool) ? .Checkmark : .None
accessoryType = (rowDescriptor.value as! Bool) ? .Checkmark : .None
}

override class func formViewController(formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) {
Expand All @@ -41,11 +41,11 @@ class FormCheckCell: FormTitleCell {

private func check() {
if rowDescriptor.value != nil {
rowDescriptor.value = !(rowDescriptor.value as Bool)
rowDescriptor.value = !(rowDescriptor.value as! Bool)
}
else {
rowDescriptor.value = true
}
accessoryType = (rowDescriptor.value as Bool) ? .Checkmark : .None
accessoryType = (rowDescriptor.value as! Bool) ? .Checkmark : .None
}
}
2 changes: 1 addition & 1 deletion asphalos/FormDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FormDescriptor: NSObject {
}
}
}
return formValues.copy() as NSDictionary
return formValues.copy() as! NSDictionary
}

func validateForm() -> FormRowDescriptor! {
Expand Down
9 changes: 2 additions & 7 deletions asphalos/FormOptionsSelectorController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class FormOptionsSelectorController: UITableViewController, FormSelector {
var formCell: FormBaseCell!

/// MARK: Init

override init() {
super.init(style: .Grouped)
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
Expand Down Expand Up @@ -59,7 +54,7 @@ class FormOptionsSelectorController: UITableViewController, FormSelector {
cell = UITableViewCell(style: .Default, reuseIdentifier: reuseIdentifier)
}

let optionValue = formCell.rowDescriptor.options[indexPath.row] as NSObject
let optionValue = formCell.rowDescriptor.options[indexPath.row] as! NSObject
var uiLabel = cell!.textLabel! as UILabel

uiLabel.text = formCell.rowDescriptor.titleForOptionValue(optionValue)
Expand Down Expand Up @@ -95,7 +90,7 @@ class FormOptionsSelectorController: UITableViewController, FormSelector {
let cell = tableView.cellForRowAtIndexPath(indexPath)

let allowsMultipleSelection = formCell.rowDescriptor.allowsMultipleSelection
let optionValue = formCell.rowDescriptor.options[indexPath.row] as NSObject
let optionValue = formCell.rowDescriptor.options[indexPath.row] as! NSObject

if allowsMultipleSelection {

Expand Down
4 changes: 2 additions & 2 deletions asphalos/FormReadTextFieldCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class FormReadTextFieldCell: FormBaseCell {
override func defaultVisualConstraints() -> [String] {
let _imageView = self.imageView! as UIImageView
if _imageView.image != nil {
if titleLabel.text != nil && countElements(titleLabel.text!) > 0 {
if titleLabel.text != nil && count(titleLabel.text!) > 0 {
return ["H:[imageView]-[titleLabel]-[valueLabel]-16-|"]
}
else {
return ["H:[imageView]-[valueLabel]-16-|"]
}
}
else {
if titleLabel.text != nil && countElements(titleLabel.text!) > 0 {
if titleLabel.text != nil && count(titleLabel.text!) > 0 {
return ["H:|-16-[titleLabel]-[valueLabel]-16-|"]
}
else {
Expand Down
4 changes: 2 additions & 2 deletions asphalos/FormRowDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ class FormRowDescriptor: NSObject {
/// MARK: Public interface

func titleForOptionAtIndex(index: Int) -> String! {
return titleForOptionValue(options[index] as NSObject)
return titleForOptionValue(options[index] as! NSObject)
}

func titleForOptionValue(optionValue: NSObject) -> String! {
if titleFormatter != nil {
return titleFormatter(optionValue)
}
else if optionValue is String {
return optionValue as String
return optionValue as! String
}
return "\(optionValue)"
}
Expand Down
6 changes: 3 additions & 3 deletions asphalos/FormSegmentedControlCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FormSegmentedControlCell: FormBaseCell {
var idx = 0
if rowDescriptor.value != nil {
for optionValue in rowDescriptor.options {
if optionValue as NSObject == rowDescriptor.value {
if optionValue as! NSObject == rowDescriptor.value {
segmentedControl.selectedSegmentIndex = idx
break
}
Expand All @@ -67,7 +67,7 @@ class FormSegmentedControlCell: FormBaseCell {

override func defaultVisualConstraints() -> [String] {

if titleLabel.text != nil && countElements(titleLabel.text!) > 0 {
if titleLabel.text != nil && count(titleLabel.text!) > 0 {
return ["H:|-16-[titleLabel]-16-[segmentedControl]-16-|"]
}
else {
Expand All @@ -88,7 +88,7 @@ class FormSegmentedControlCell: FormBaseCell {
segmentedControl.removeAllSegments()
var idx = 0
for optionValue in rowDescriptor.options {
segmentedControl.insertSegmentWithTitle(rowDescriptor.titleForOptionValue(optionValue as NSObject), atIndex: idx, animated: false)
segmentedControl.insertSegmentWithTitle(rowDescriptor.titleForOptionValue(optionValue as! NSObject), atIndex: idx, animated: false)
++idx
}
}
Expand Down
Loading

0 comments on commit 201a1f3

Please sign in to comment.