Skip to content

Commit

Permalink
fixes for urlstore folder and Window presenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Knut Inge Grosland committed May 26, 2015
1 parent ca3ed9b commit 589baeb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions AppReviews/ApplicationWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ extension ApplicationWindowController {
searchViewController.delegate = self
searchViewController.state = .Loading
}
window?.beginSheet(window!) {

self.window?.beginSheet(window!) {
(returnCode: NSModalResponse)
in
self.searchWindowController = nil
Expand Down
2 changes: 1 addition & 1 deletion AppReviews/SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SearchViewController: NSViewController {
var delegate: SearchViewControllerDelegate?
var state: SearchViewControllerState = .Idle {
didSet {
switch state {
switch self.state {
case .Idle:
progressIndicator.stopAnimation(nil)
case .Loading:
Expand Down
35 changes: 19 additions & 16 deletions ReviewManager/ReviewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,31 @@ final class ReviewManager {
}

func storeURL() -> NSURL {
let appName = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName") as? String ?? "App Reviews"
var error: NSError? = nil
// ApplicationSupportDirectory

let applicationSupportDirectory = NSFileManager.defaultManager().URLForDirectory(.DesktopDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true, error: &error)
let appDirectory = applicationSupportDirectory?.URLByAppendingPathComponent(appName, isDirectory: true)

let success = NSFileManager.defaultManager().createDirectoryAtPath(appDirectory!.URLString, withIntermediateDirectories: true, attributes: nil, error: &error)
var failureReason = "There was an error creating or loading the application's saved data."

if error != nil {
println("createDirectoryAtPath: \(error?.localizedDescription)")
// Make sure the application files directory is there
let propertiesOpt = self.applicationDocumentsDirectory.resourceValuesForKeys([NSURLIsDirectoryKey], error: &error)
if let properties = propertiesOpt {
if !properties[NSURLIsDirectoryKey]!.boolValue {
failureReason = "Expected a folder to store application data, found a file \(self.applicationDocumentsDirectory.path)."
}
} else if error!.code == NSFileReadNoSuchFileError {
error = nil
NSFileManager.defaultManager().createDirectoryAtPath(self.applicationDocumentsDirectory.path!, withIntermediateDirectories: true, attributes: nil, error: &error)
}

let url = appDirectory?.URLByAppendingPathComponent(kSQLiteFileName)

if error != nil {
println("error storeURL: \(error?.localizedDescription)")
}

return url!
return self.applicationDocumentsDirectory.URLByAppendingPathComponent(kSQLiteFileName)
}

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

let appName = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName") as? String ?? "App Reviews"
return appSupportURL.URLByAppendingPathComponent(appName)
}()

func modelURL() -> NSURL {
return NSBundle.mainBundle().URLForResource("AppReviews", withExtension: "momd")!
}
Expand Down

0 comments on commit 589baeb

Please sign in to comment.