Skip to content

Commit

Permalink
Merge pull request #99 from SugarRecord/bug/resultsDependency
Browse files Browse the repository at this point in the history
Splited SugarRecordResults logic
  • Loading branch information
Pedro Piñera Buendía committed Dec 29, 2014
2 parents 315406f + 73a3d83 commit 7d93d6b
Show file tree
Hide file tree
Showing 122 changed files with 4,132 additions and 4,276 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ If you want to stay updated we have a mailing list. We'll send emails with new u

| **Date** | **Done** |
|-------------------------------|------------------------------------------------|
| 29th-December-2014 | Version 1.0.5 released |
| 29th-December-2014 | Separated SugarRecordResults Logic https://github.com/SugarRecord/SugarRecord/issues/98|
| 25th-December-2014 | Version 1.0.4 released |
| 25th-December-2014 | Added Realm example |
| 25th-December-2014 | Added a continuous integration local script |
Expand Down Expand Up @@ -94,8 +96,10 @@ If you want to stay updated we have a mailing list. We'll send emails with new u
- More powerful features to discover!

## Versions
### Version 1.0.5 [WIP]
### Version 1.0.6 [WIP]

### Version 1.0.5
- Fixed a regression introduced with 1.0.4 that caused users having to import Realm/CoreData even if they were using another database technology https://github.com/SugarRecord/SugarRecord/pull/99

### Version 1.0.4
- Updated the project structure and added easy setup steps (without CocoaPods)
Expand Down
4 changes: 2 additions & 2 deletions SugarRecord.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = 'SugarRecord'
s.version = '1.0.4'
s.version = '1.0.5'
s.platform = :ios, '8.0'
s.license = 'MIT'
s.summary = 'CoreData management library implemented with the sugar Swift language'
s.homepage = 'https://github.com/SugarRecord/SugarRecord'
s.author = { 'Pedro Piñera' => 'pepibumur@gmail.com' }
s.social_media_url = "https://twitter.com/pepibumur"
s.source = { :git => 'https://github.com/SugarRecord/SugarRecord.git', :tag => '1.0.4', :submodules => false }
s.source = { :git => 'https://github.com/SugarRecord/SugarRecord.git', :tag => '1.0.5', :submodules => false }
s.description = "Thanks to SugarRecord you'll be able to use a clean syntax to fetch, filter, create, update CoreData objects in an easy way. Inspired by MagicalRecord and opened to new contributions."
s.requires_arc = true
s.documentation_url = "https://github.com/SugarRecord/SugarRecord/wiki"
Expand Down
2 changes: 1 addition & 1 deletion example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ SPEC CHECKSUMS:
SOCKit: d8d0dd3688ae1026c12367570da8fa8e1a6980fb
TransitionKit: 6a6f3ddda38ae758778aa889dcb930e4f8d64edc

COCOAPODS: 0.35.0
COCOAPODS: 0.36.0.beta.1
12 changes: 12 additions & 0 deletions example/SugarRecordExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/* Begin PBXBuildFile section */
17789BF20854A2251ACB4763 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 93387547534B0073B3B4B328 /* libPods.a */; };
3D0B0D211A50D360008340CB /* CDArray+SugarRecordResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D0B0D201A50D360008340CB /* CDArray+SugarRecordResults.swift */; };
3D0B0D231A50D36F008340CB /* RLMResults+SugarRecordResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D0B0D221A50D36F008340CB /* RLMResults+SugarRecordResults.swift */; };
3D0B0D251A50D38A008340CB /* SugarRecordResultsProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D0B0D241A50D38A008340CB /* SugarRecordResultsProtocol.swift */; };
3D47547F1A4C460100479D16 /* SugarRecordFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D47547E1A4C460100479D16 /* SugarRecordFinder.swift */; };
3D4754811A4C461B00479D16 /* SugarRecordResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D4754801A4C461B00479D16 /* SugarRecordResults.swift */; };
3D4754DF1A4C7C5200479D16 /* RealmTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D4754DE1A4C7C5200479D16 /* RealmTableViewController.swift */; };
Expand Down Expand Up @@ -71,6 +74,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
3D0B0D201A50D360008340CB /* CDArray+SugarRecordResults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CDArray+SugarRecordResults.swift"; sourceTree = "<group>"; };
3D0B0D221A50D36F008340CB /* RLMResults+SugarRecordResults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RLMResults+SugarRecordResults.swift"; sourceTree = "<group>"; };
3D0B0D241A50D38A008340CB /* SugarRecordResultsProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SugarRecordResultsProtocol.swift; sourceTree = "<group>"; };
3D47547E1A4C460100479D16 /* SugarRecordFinder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SugarRecordFinder.swift; sourceTree = "<group>"; };
3D4754801A4C461B00479D16 /* SugarRecordResults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SugarRecordResults.swift; sourceTree = "<group>"; };
3D4754DE1A4C7C5200479D16 /* RealmTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmTableViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -211,6 +217,7 @@
3DF36C891A39056B00A73311 /* Realm */ = {
isa = PBXGroup;
children = (
3D0B0D221A50D36F008340CB /* RLMResults+SugarRecordResults.swift */,
3DF36C8A1A39056B00A73311 /* DefaultREALMStack.swift */,
3DF36C8B1A39056B00A73311 /* RLMObject+SugarRecord.swift */,
3DF36C8C1A39056B00A73311 /* RLMObjectMigration.swift */,
Expand Down Expand Up @@ -295,6 +302,7 @@
E1526DDF1A38A05C00BC6E1E /* Protocols */ = {
isa = PBXGroup;
children = (
3D0B0D241A50D38A008340CB /* SugarRecordResultsProtocol.swift */,
E1526DE01A38A05C00BC6E1E /* SugarRecordContextProtocol.swift */,
E1526DE21A38A05C00BC6E1E /* SugarRecordStackProtocol.swift */,
);
Expand All @@ -314,6 +322,7 @@
E1526DE71A38A05C00BC6E1E /* Base */ = {
isa = PBXGroup;
children = (
3D0B0D201A50D360008340CB /* CDArray+SugarRecordResults.swift */,
E1526DE81A38A05C00BC6E1E /* DefaultCDStack.swift */,
E1526DE91A38A05C00BC6E1E /* iCloudCDStack.swift */,
E1526DEA1A38A05C00BC6E1E /* NSManagedObject+SugarRecord.swift */,
Expand Down Expand Up @@ -443,9 +452,12 @@
3D4754EC1A4C7F5300479D16 /* RLMObjectMigration.swift in Sources */,
E197C9CD1A3F97AA000533A4 /* RestKitModel.swift in Sources */,
3D4754EB1A4C7F5000479D16 /* RLMObject+SugarRecord.swift in Sources */,
3D0B0D231A50D36F008340CB /* RLMResults+SugarRecordResults.swift in Sources */,
3DF36C831A38F5A800A73311 /* AppDelegate.swift in Sources */,
3D0B0D211A50D360008340CB /* CDArray+SugarRecordResults.swift in Sources */,
3DF36C861A38F5A800A73311 /* StackTableViewController.swift in Sources */,
3D4754E11A4C7CD000479D16 /* RealmModel.swift in Sources */,
3D0B0D251A50D38A008340CB /* SugarRecordResultsProtocol.swift in Sources */,
3DF36C871A38F5A800A73311 /* CoreDataModel.swift in Sources */,
E1526DF21A38A05C00BC6E1E /* SugarRecord.swift in Sources */,
E1526DF61A38A05C00BC6E1E /* iCloudCDStack.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CoreDataTableViewController: StackTableViewController {

//MARK: - Attributes

var data: SugarRecordResults<NSManagedObject>?
var data: SugarRecordResults?
internal let model: NSManagedObjectModel = {
let modelPath: NSString = NSBundle.mainBundle().pathForResource("Models", ofType: "momd")!
let model: NSManagedObjectModel = NSManagedObjectModel(contentsOfURL: NSURL(fileURLWithPath: modelPath)!)!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RealmTableViewController: StackTableViewController
{
//MARK: - Attributes

var data: SugarRecordResults<RLMObject>?
var data: SugarRecordResults?


//MARK: - Viewcontroller Lifecycle
Expand Down
4 changes: 2 additions & 2 deletions library/Core/Protocols/SugarRecordContextProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public protocol SugarRecordContext
/**
* Deletes the objects in the array from the context
*/
func deleteObjects<T>(objects: SugarRecordResults<T>) -> ()
func deleteObjects(objects: SugarRecordResults) -> ()

/**
* Executes the finder query to return filtered values
*/
func find<T>(finder: SugarRecordFinder<T>) -> SugarRecordResults<T>
func find(finder: SugarRecordFinder) -> SugarRecordResults
}
49 changes: 49 additions & 0 deletions library/Core/Protocols/SugarRecordResultsProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SugarRecordResultsProtocol.swift
// project
//
// Created by Pedro Piñera Buendía on 29/12/14.
// Copyright (c) 2014 SugarRecord. All rights reserved.
//

import Foundation

internal protocol SugarRecordResultsProtocol
{
/**
Returns the count of elements in Results
:param: finder Finder restrict the query results (lasts, first, firsts, ...) which is not possible directly on Realm
:returns: Count of elements
*/
func count(#finder: SugarRecordFinder) -> Int

/**
Returns the object at a given index
:param: index Index of the object
:param: finder Finder restrict the query results (lasts, first, firsts, ...) which is not possible directly on Realm
:returns: Object at that index (if exists)
*/
func objectAtIndex(index: UInt, finder: SugarRecordFinder) -> AnyObject!

/**
Returns the first object of the results
:param: finder Finder restrict the query results (lasts, first, firsts, ...) which is not possible directly on Realm
:returns: First object (if exists)
*/
func firstObject(#finder: SugarRecordFinder) -> AnyObject!

/**
Returns the last object of the results
:param: finder Finder restrict the query results (lasts, first, firsts, ...) which is not possible directly on Realm
:returns: Last object (if exists)
*/
func lastObject(#finder: SugarRecordFinder) -> AnyObject!
}
10 changes: 5 additions & 5 deletions library/Core/SugarRecordFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum SugarRecordFinderElements
case lasts(Int)
}

public class SugarRecordFinder<T>
public class SugarRecordFinder
{
//MARK: - Attributes

Expand Down Expand Up @@ -338,16 +338,16 @@ public class SugarRecordFinder<T>
:returns: Fetch result
*/
public func find() -> SugarRecordResults<T>
public func find() -> SugarRecordResults
{
var objects: SugarRecordResults<T>!
var objects: SugarRecordResults!
SugarRecord.operation(stackType!, closure: { (context) -> () in
objects = context.find(self)
})
return objects
}

public func find(inContext context:SugarRecordContext) -> SugarRecordResults<T>
public func find(inContext context:SugarRecordContext) -> SugarRecordResults
{
return context.find(self)
}
Expand All @@ -373,7 +373,7 @@ public class SugarRecordFinder<T>
public func delete (asynchronously: Bool, completion: () -> ())
{
SugarRecord.operation(inBackground: asynchronously, stackType: stackType!) { (context) -> () in
let objects: SugarRecordResults<T>! = context.find(self)
let objects: SugarRecordResults! = context.find(self)
if objects == nil {
SugarRecordLogger.logLevelInfo.log("No objects have been deleted")
return
Expand Down

0 comments on commit 7d93d6b

Please sign in to comment.