Skip to content

Commit

Permalink
Merge pull request #27 from davidgatti/swift1.2upgrade
Browse files Browse the repository at this point in the history
Swift1.2upgrade and New Water Consumption View
  • Loading branch information
davidgatti committed Jul 17, 2015
2 parents 0c00c8f + 2c1850c commit a0a2508
Show file tree
Hide file tree
Showing 20 changed files with 544 additions and 222 deletions.
13 changes: 12 additions & 1 deletion GarageOpener.xcodeproj/project.pbxproj
Expand Up @@ -14,6 +14,7 @@
E54E6C101B420851003B3E53 /* ImageResize.swift in Sources */ = {isa = PBXBuildFile; fileRef = E54E6C0F1B420851003B3E53 /* ImageResize.swift */; };
E54E6C121B423565003B3E53 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = E54E6C111B423565003B3E53 /* User.swift */; };
E55C85B81B2CAF090063B75E /* NewAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E55C85B71B2CAF090063B75E /* NewAccountViewController.swift */; };
E57166811B578C0C0091AC42 /* WaterUsageTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E57166801B578C0C0091AC42 /* WaterUsageTableViewController.swift */; };
E597B90B1B37241400D84514 /* ErrorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E597B90A1B37241400D84514 /* ErrorViewController.swift */; };
E59B08C91B22974F009B50D4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E59B08C81B22974F009B50D4 /* AppDelegate.swift */; };
E59B08CC1B22974F009B50D4 /* GarageOpener.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = E59B08CA1B22974F009B50D4 /* GarageOpener.xcdatamodeld */; };
Expand Down Expand Up @@ -67,6 +68,7 @@
E54E6C0F1B420851003B3E53 /* ImageResize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageResize.swift; sourceTree = "<group>"; };
E54E6C111B423565003B3E53 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
E55C85B71B2CAF090063B75E /* NewAccountViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewAccountViewController.swift; sourceTree = "<group>"; };
E57166801B578C0C0091AC42 /* WaterUsageTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WaterUsageTableViewController.swift; sourceTree = "<group>"; };
E597B90A1B37241400D84514 /* ErrorViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorViewController.swift; sourceTree = "<group>"; };
E59B08C31B22974F009B50D4 /* GarageOpener.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GarageOpener.app; sourceTree = BUILT_PRODUCTS_DIR; };
E59B08C71B22974F009B50D4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -274,6 +276,7 @@
E59B08CF1B22974F009B50D4 /* Main.storyboard */,
E5584EF01B446CD000DAB558 /* User */,
E59B08CD1B22974F009B50D4 /* MainViewController.swift */,
E57166801B578C0C0091AC42 /* WaterUsageTableViewController.swift */,
E59B08F91B24E539009B50D4 /* GarageDoorViewController.swift */,
E597B90A1B37241400D84514 /* ErrorViewController.swift */,
E54E6C091B406C12003B3E53 /* GridViewController.swift */,
Expand Down Expand Up @@ -325,7 +328,9 @@
E59B08BB1B22974F009B50D4 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "David Gatti";
TargetAttributes = {
E59B08C21B22974F009B50D4 = {
Expand Down Expand Up @@ -399,6 +404,7 @@
E597B90B1B37241400D84514 /* ErrorViewController.swift in Sources */,
E59B08F61B24B94B009B50D4 /* SwiftJSON.swift in Sources */,
E54E6C121B423565003B3E53 /* User.swift in Sources */,
E57166811B578C0C0091AC42 /* WaterUsageTableViewController.swift in Sources */,
E54E6C101B420851003B3E53 /* ImageResize.swift in Sources */,
E59B08FA1B24E539009B50D4 /* GarageDoorViewController.swift in Sources */,
E54E6C0E1B41F406003B3E53 /* TakePhothoViewController.swift in Sources */,
Expand Down Expand Up @@ -464,6 +470,7 @@
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -540,6 +547,7 @@
INFOPLIST_FILE = GarageOpener/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "pl.gatti.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "GarageOpener/GarageOpener-Bridging-Header.h";
Expand All @@ -561,6 +569,7 @@
INFOPLIST_FILE = GarageOpener/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "pl.gatti.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "GarageOpener/GarageOpener-Bridging-Header.h";
Expand All @@ -581,6 +590,7 @@
);
INFOPLIST_FILE = GarageOpenerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "pl.gatti.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GarageOpener.app/GarageOpener";
};
Expand All @@ -596,6 +606,7 @@
);
INFOPLIST_FILE = GarageOpenerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "pl.gatti.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GarageOpener.app/GarageOpener";
};
Expand Down
26 changes: 18 additions & 8 deletions GarageOpener/AppDelegate.swift
Expand Up @@ -20,7 +20,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

var secrets = Secrets.sharedInstance
let secrets = Secrets.sharedInstance

// [Optional] Power your app with Local Datastore. For more info, go to
// https://parse.com/docs/ios_guide#localdatastore/iOS
Expand Down Expand Up @@ -64,7 +64,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var applicationDocumentsDirectory: NSURL = {
// The directory the application uses to store the Core Data store file. This code uses a directory named "pl.gatti.GarageOpener" in the application's documents Application Support directory.
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 @@ -80,7 +80,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("GarageOpener.sqlite")
var error: NSError? = nil
var failureReason = "There was an error creating or loading the application's saved data."
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
do {
try coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
} catch var error1 as NSError {
error = error1
coordinator = nil
// Report any error we got.
var dict = [String: AnyObject]()
Expand All @@ -92,6 +95,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// 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)")
abort()
} catch {
fatalError()
}

return coordinator
Expand All @@ -113,11 +118,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func saveContext () {
if let moc = self.managedObjectContext {
var error: NSError? = nil
if moc.hasChanges && !moc.save(&error) {
// Replace this implementation 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)")
abort()
if moc.hasChanges {
do {
try moc.save()
} catch let error1 as NSError {
error = error1
// Replace this implementation 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)")
abort()
}
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions GarageOpener/AvatarViewController.swift
Expand Up @@ -39,7 +39,7 @@ class AvatarViewController: UIViewController, UIImagePickerControllerDelegate, U

UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale)
image.drawInRect(CGRectMake(0, 0, image.size.width, image.size.height))
var normalizedImage:UIImage = UIGraphicsGetImageFromCurrentImageContext();
let normalizedImage:UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return normalizedImage;
Expand All @@ -54,17 +54,17 @@ class AvatarViewController: UIViewController, UIImagePickerControllerDelegate, U
btnTakePhotho.enabled = false

// New size for the image
var size: CGSize = CGSize(width: 100, height: 100)
let size: CGSize = CGSize(width: 100, height: 100)

// Resizign the image

var smallImage = self.imgObject.resizeImage(imageView.image!, newSize: size)
let smallImage = self.imgObject.resizeImage(imageView.image!, newSize: size)

// Converting the image in to a JPG
let imageData = UIImageJPEGRepresentation(self.correctlyOrientedImage(smallImage), 1.0)

// Converting the image in to a Pars file
let imageFile = PFFile(name: "avatar.jpg", data: imageData)
let imageFile = PFFile(name: "avatar.jpg", data: imageData!)
imageFile.save()

// Making a Parse query
Expand All @@ -77,9 +77,9 @@ class AvatarViewController: UIViewController, UIImagePickerControllerDelegate, U
user.signUpInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in

if let error = error {
let errorString = error.userInfo?["error"] as? NSString
let errorString = error.userInfo["error"] as? NSString

println(errorString)
print(errorString)

} else {

Expand All @@ -88,7 +88,7 @@ class AvatarViewController: UIViewController, UIImagePickerControllerDelegate, U
defaults.setValue(user.objectId!, forKey: "userID")

let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let vc : UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("mainView") as! UIViewController
let vc : UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("mainView") as UIViewController
self.presentViewController(vc, animated: true, completion: nil)
}
}
Expand Down

0 comments on commit a0a2508

Please sign in to comment.