Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vmartinelli committed Feb 16, 2015
2 parents c916786 + 4521826 commit f2092fd
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 44 deletions.
2 changes: 0 additions & 2 deletions Examples/iOS/AlecrimCoreDataExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
let masterNavigationController = splitViewController.viewControllers[0] as UINavigationController
let controller = masterNavigationController.topViewController as MasterViewController

println(localSQLiteStoreURLForBundle(NSBundle.mainBundle()))

return true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14D72i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
Expand All @@ -11,7 +11,7 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2014 Alecrim. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Copyright (c) 2014, 2015 Alecrim. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Vanderlei Martinelli <[email protected]>
Copyright (c) 2014, 2015 Vanderlei Martinelli <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ AlecrimCoreData is a framework to access CoreData objects more easily in Swift.

## Minimum Requirements

- Xcode 6.1
- iOS 8.x (*) / OS X 10.10.x

(*) Not tested on iOS 7.x
- Xcode 6.1.1
- iOS 8.1.3 / OS X 10.10.2

## Installation

Expand Down
41 changes: 21 additions & 20 deletions Source/OS X/AlecrimCoreData.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
objects = {

/* Begin PBXBuildFile section */
140E4EB61A924EF300FA276F /* Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140E4EB31A924EF300FA276F /* Context.swift */; };
140E4EB71A924EF300FA276F /* Stack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140E4EB41A924EF300FA276F /* Stack.swift */; };
140E4EB81A924EF300FA276F /* Table.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140E4EB51A924EF300FA276F /* Table.swift */; };
14CF9DFE1A2C941000B64A45 /* AlecrimCoreData.h in Headers */ = {isa = PBXBuildFile; fileRef = 14CF9DFD1A2C941000B64A45 /* AlecrimCoreData.h */; settings = {ATTRIBUTES = (Public, ); }; };
14D7BB901A2C96C00045897C /* Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D7BB8D1A2C96C00045897C /* Context.swift */; };
14D7BB911A2C96C00045897C /* Stack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D7BB8E1A2C96C00045897C /* Stack.swift */; };
14D7BB921A2C96C00045897C /* Table.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D7BB8F1A2C96C00045897C /* Table.swift */; };
14D7BB941A2C96CD0045897C /* NSManagedObject+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D7BB931A2C96CD0045897C /* NSManagedObject+Extensions.swift */; };
14D7BB961A2C972D0045897C /* Table+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D7BB951A2C972D0045897C /* Table+Extensions.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
140E4EB31A924EF300FA276F /* Context.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = "<group>"; };
140E4EB41A924EF300FA276F /* Stack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stack.swift; sourceTree = "<group>"; };
140E4EB51A924EF300FA276F /* Table.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Table.swift; sourceTree = "<group>"; };
14CF9DF81A2C941000B64A45 /* AlecrimCoreData.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AlecrimCoreData.framework; sourceTree = BUILT_PRODUCTS_DIR; };
14CF9DFC1A2C941000B64A45 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
14CF9DFD1A2C941000B64A45 /* AlecrimCoreData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AlecrimCoreData.h; sourceTree = "<group>"; };
14D7BB8D1A2C96C00045897C /* Context.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Context.swift; path = ../../../Shared/AlecrimCoreData/Classes/Context.swift; sourceTree = "<group>"; };
14D7BB8E1A2C96C00045897C /* Stack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Stack.swift; path = ../../../Shared/AlecrimCoreData/Classes/Stack.swift; sourceTree = "<group>"; };
14D7BB8F1A2C96C00045897C /* Table.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Table.swift; path = ../../../Shared/AlecrimCoreData/Classes/Table.swift; sourceTree = "<group>"; };
14D7BB931A2C96CD0045897C /* NSManagedObject+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSManagedObject+Extensions.swift"; path = "../../../Shared/AlecrimCoreData/Extensions/NSManagedObject+Extensions.swift"; sourceTree = "<group>"; };
14D7BB951A2C972D0045897C /* Table+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Table+Extensions.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -37,6 +37,17 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
140E4EB21A924EF300FA276F /* Classes */ = {
isa = PBXGroup;
children = (
140E4EB31A924EF300FA276F /* Context.swift */,
140E4EB41A924EF300FA276F /* Stack.swift */,
140E4EB51A924EF300FA276F /* Table.swift */,
);
name = Classes;
path = ../../Shared/AlecrimCoreData/Classes;
sourceTree = "<group>";
};
14CF9DEE1A2C941000B64A45 = {
isa = PBXGroup;
children = (
Expand All @@ -57,7 +68,7 @@
isa = PBXGroup;
children = (
14CF9DFD1A2C941000B64A45 /* AlecrimCoreData.h */,
14CF9E141A2C947400B64A45 /* Classes */,
140E4EB21A924EF300FA276F /* Classes */,
14CF9E151A2C947400B64A45 /* Extensions */,
14CF9DFB1A2C941000B64A45 /* Supporting Files */,
);
Expand All @@ -72,16 +83,6 @@
name = "Supporting Files";
sourceTree = "<group>";
};
14CF9E141A2C947400B64A45 /* Classes */ = {
isa = PBXGroup;
children = (
14D7BB8D1A2C96C00045897C /* Context.swift */,
14D7BB8E1A2C96C00045897C /* Stack.swift */,
14D7BB8F1A2C96C00045897C /* Table.swift */,
);
path = Classes;
sourceTree = "<group>";
};
14CF9E151A2C947400B64A45 /* Extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -169,11 +170,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
14D7BB921A2C96C00045897C /* Table.swift in Sources */,
14D7BB911A2C96C00045897C /* Stack.swift in Sources */,
140E4EB71A924EF300FA276F /* Stack.swift in Sources */,
140E4EB81A924EF300FA276F /* Table.swift in Sources */,
140E4EB61A924EF300FA276F /* Context.swift in Sources */,
14D7BB961A2C972D0045897C /* Table+Extensions.swift in Sources */,
14D7BB941A2C96CD0045897C /* NSManagedObject+Extensions.swift in Sources */,
14D7BB901A2C96C00045897C /* Context.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion Source/Shared/AlecrimCoreData/Classes/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import CoreData

public class Context {

public let managedObjectContext: NSManagedObjectContext! // The underlying managed object context
private let stack: Stack!
public let managedObjectContext: NSManagedObjectContext!

public init?(managedObjectModelName: String? = nil, stackType: StackType = StackType.SQLite) {
if let stack = Stack(managedObjectModelName: managedObjectModelName, stackType: stackType) {
Expand Down
35 changes: 22 additions & 13 deletions Source/Shared/AlecrimCoreData/Classes/Stack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal final class Stack {

private class func persistentStoreForSQLiteStoreTypeWithCoordinator(coordinator: NSPersistentStoreCoordinator, managedObjectModelName: String?, bundle: NSBundle) -> NSPersistentStore? {
if let momn = managedObjectModelName {
if let localStoreURL = localSQLiteStoreURLForBundle(bundle) {
if let localStoreURL = Stack.localSQLiteStoreURLForBundle(bundle) {
if let localStorePath = localStoreURL.path {
let fileManager = NSFileManager.defaultManager()
var error: NSError? = nil
Expand All @@ -140,9 +140,17 @@ internal final class Stack {
let storeFilename = momn.stringByAppendingPathExtension("sqlite")!
let localStoreFileURL = localStoreURL.URLByAppendingPathComponent(storeFilename, isDirectory: false)

return coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: localStoreFileURL, options: nil, error: nil)!
var error: NSError? = nil
if let store = coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: localStoreFileURL, options: nil, error: &error) {
return store
}
else {
println(error)
return nil
}
}
}

return nil
}

Expand All @@ -158,6 +166,18 @@ internal final class Stack {
}
}

private class func localSQLiteStoreURLForBundle(bundle: NSBundle) -> NSURL? {
let fileManager = NSFileManager.defaultManager()
let urls = fileManager.URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)
let applicationSupportDirectoryURL = urls.last as NSURL

if let bundleIdentifier = bundle.bundleIdentifier {
return applicationSupportDirectoryURL.URLByAppendingPathComponent(bundleIdentifier, isDirectory: true)
}

return nil
}

}

private class StackBackgroundManagedObjectContext: NSManagedObjectContext {
Expand Down Expand Up @@ -185,14 +205,3 @@ private class StackBackgroundManagedObjectContext: NSManagedObjectContext {

}

public func localSQLiteStoreURLForBundle(bundle: NSBundle) -> NSURL? {
let fileManager = NSFileManager.defaultManager()
let urls = fileManager.URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)
let applicationSupportDirectoryURL = urls.last as NSURL

if let bundleIdentifier = bundle.bundleIdentifier {
return applicationSupportDirectoryURL.URLByAppendingPathComponent(bundleIdentifier, isDirectory: true)
}

return nil
}

0 comments on commit f2092fd

Please sign in to comment.