modo-studio / sugarrecord Goto Github PK
View Code? Open in Web Editor NEWCoreData/Realm sweet wrapper written in Swift
License: MIT License
CoreData/Realm sweet wrapper written in Swift
License: MIT License
I was using an older version of SugarRecord, but I just updated to the latest revision of the code, and I'm getting these compiler errors.
/SugarRecord/library/CoreData/Base/NSManagedObject+SugarRecord.swift:178:27: Missing argument for parameter 'inContext' in call
/SugarRecord/library/CoreData/Base/NSManagedObject+SugarRecord.swift:275:24: Could not find member 'beginWriting'
/SugarRecord/library/CoreData/Base/NSManagedObject+SugarRecord.swift:286:24: Could not find member 'endWriting'
/SugarRecord/library/CoreData/Base/NSManagedObject+SugarRecord.swift:295:24: Could not find member 'cancelWriting'
Not sure if there was anything I missed.
Hi there, any plans to update the Realm submodule? It's got some new features that i'd like to use e.g. Optional properties and not having to make model object a direct subclass of RLMObject
I pulled sugarrecord submodule HEAD and changed the setup (added core and Realm folders directly to project) and now I get two new errors:
for this code:
var dbCards: [Card]? = Card.by("cloudUUID", equalTo: ""(cardUUID!)"").find() as [Card]?
I get "extra argument equalTo: in call"
and then for
card.beginWriting()
I get "Ambiguous use of beginWriting"
Card of course is a RLMObject
I don't seem to have any other Realm or SugarRecord errors
Offer a protocol and implementations to let a consumer implement its own custom stack.
It is always fun to have documentation with examples in a playground.
Dependent of 1.0 stack refactor
We can build it using this tool: https://github.com/jas/swift-playground-builder which allow us to explain and write examples.
Awesome work guys! Thank you for this. Any specific reason why you didn't include a CocoaTouch Framework project or a target for this? Similar libraries (Alamofire i.e.) are including CocoaTouch Framework projects so one could just include that project and add link+copy the framework. I think that's a little bit nicer than including the sources directly. I've done something similar here, but I'm not submitting a PR because I think this should be done by someone of the core team, you know just to get the organization information right.
Hello guys,
I'd liked to write on Stackoverflow but I don't have enough reputations to use SugarRecord :/.
I really like SugarRecord! I use it on my personal project with success except for find records correctly of my table "Setting". In fact I write this code:
let settings = Setting.find(.all, inContext: nil, filteredBy: nil, sortedBy: nil)
And it retrieve correctly my 5 records. But if I add subsequently a record and redo "Setting.find(.all..." it retrieve 11 record instead of 6. Why? :(
Create any extension of NSManagedObject to generate automatically a fetchedResultsController with the passed filtering, and sorting data.
Hello,
in iOS 8 SugarRecord works perfectly but when I run my app on iOS 7 Simulator it crash with:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObjectContext setName:]: unrecognized selector sent to instance 0x7ff03951d310'
In applicationDidFinishLaunchingWithOptions I have this code:
let stack: DefaultCDStack = DefaultCDStack(databaseName: "Database.sqlite", automigrating: true)
SugarRecord.addStack(stack)
SugarRecordLogger.currentLevel = SugarRecordLogger.logLevelVerbose
Because that's gonna avoid the casting on the database fetches. Generic methods are going to know which objects have to be returned and they are not going to return something like [AnyObject] like they did until now.
Hi Pedro,
I have a few questions and suggestions to contribute:
xcodebuild test -project SugarRecordDemo/SugarRecord.xcodeproj -scheme SugarRecord -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
but I couldn't with xctool
, it seems not supported for xcode6-betasCheers
Is there any way to control the tests order?
I have a class that has an static property, and in each suite of tests what I do is to set that static property to be tested in the suite tests. However before one of the suites has finished, the other is started and it changes that static property and the pending tests start failing. Is there any way to control that?
Thanks
Add the option to autosave changes applied to the MainContext in the database.
Note: Currently main context changes are only persisted when the app goes to the background
Because mergeChangesInMainThread(fromNotification:)
is exported to ObjC runtime as mergeChangesInMainThreadFromNotification:
, calling the method from NSNotificationCenter
is failing.
if mainThread {
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("mergeChangesInMainThreadFromNotification:"), name: NSManagedObjectContextDidSaveNotification, object: context)
}
or
@objc(mergeChangesInMainThread:)
func mergeChangesInMainThread(fromNotification notification: NSNotification)
or
func mergeChangesInMainThread(notification: NSNotification)
fixes the issue.
func mergeChanges(fromNotification notification: NSNotification)
would be the same.
I have a Realm model like this:
import Realm
// IdentityProxy model
class IdentityProxy: RLMObject {
dynamic var name = ""
dynamic var title = ""
dynamic var imageUrl = ""
dynamic var cloudUUID = ""
dynamic var changeDate = NSDate(timeIntervalSince1970: 1)
}
but I can't get the RLMObject SugarRecord operations to work, e.g.:
let idents: [IdentityProxy]? = IdentityProxy("cloudUUID", equalTo: "someuuid").find() as [IdentityProxy]?
gives the error "Extra argument in call"
none of the other SugarRecord code gives any errors, e.g. SugarRecord.addStack...
I'm successful with pure Realm, like so:
var idents = IdentityProxy.objectsWhere("cloudUUID = '\(identUUID!)'")
but I can't use that inside SugarRecord.operation without it crashing Realm by being on the wrong thread.
I had add SugarRecord in my project, and import xxx-Swift.h in Objective-C file.
But Xcode cannot find SugarRecord class. In Swift file it's ok.
Think about how to bring migrations to the Library supporting both Realm and CoreData with the SugarRecordAbstraction
Hi! @pepibumur
Thank you for your open source.
If i need to update a model few fields, then how to do?
The RSS App, now update some articles to read.
So the question comes, we have one million data needs to be mark read, that do?
Jack
Why won't this compile:
if let extId:NSNumber = subJson["id"].number{
==> error here: let category: Categorization? = Categorization.by("extID", equalTo: extId).find()?.first as Categorization?
Once refactored the library with the stacks support it would be great to have the following stack structures, each of them with its own tests:
Installation steps are a bit messy currently. Take a look how Realm is doing and try to do something similar http://realm.io/docs/cocoa/0.89.1/
We can use Cocoapods, Carthage even Dynamic libraries.
I am doing a sync of my database.
func syncCategories(){
var fullStringURL = self.baseStringURL + "/Category.json"
let URL = NSURL(string:fullStringURL)!
defaults.objectForKey("lastCategoryUpdate")
let dateString = defaults.objectForKey("lastCategoryUpdate")! as String
let parameters:[String:AnyObject] = ["lastmoddate":dateString]
Alamofire.request(.GET, URL, parameters: parameters)
.responseJSON { (req, res, json, error) in
if(error != nil) {
NSLog("Error: \(error)")
println(req)
println(res)
}
else {
var json = JSON(json!)
SugarRecord.operation(inBackground: true, stackType: SugarRecordStackType.SugarRecordStackTypeCoreData, closure: { (context) -> () in
context.beginWriting()
for (index: String, subJson: JSON) in json {
if let extId:NSNumber = subJson["id"].number{
var category: Categorization? = Categorization.by("extID", equalTo: "\(extId)").find()?.first as Categorization?
if(category == nil){
category = Categorization.create(inContext: context) as? Categorization
context.insertObject(category!)
}
category!.extID = extId
if let userName = subJson["name"].string{
category!.name = userName
}
if let mainImage = subJson["mainImage"].string{
category!.mainImageURL = mainImage
}
if let thumbnailImage = subJson["thumbnailImage"].string{
category!.thumbnailURL = thumbnailImage
}
}else{
//skip
}
}
context.endWriting()
})
}
}
}
Hi!
I am trying to use SugarRecord and got some assertions. I've checked the reason and I think the following function is missing a line:
class func initializeContextsStack(persistentStoreCoordinator: NSPersistentStoreCoordinator) {
SugarRecordLogger.logLevelInfo.log("Creating contexts stack")
var rootContext: NSManagedObjectContext = NSManagedObjectContext.newContext(nil, persistentStoreCoordinator: persistentStoreCoordinator)
NSManagedObjectContext.setRootSavingContext(rootContext)
var defaultContext: NSManagedObjectContext = NSManagedObjectContext.newContext(rootContext, persistentStoreCoordinator: nil)
}
Isn't there a line
NSManagedObjectContext.setDefaultContext(defaultContext)
missing?
Current build: https://travis-ci.org/SugarRecord/SugarRecord/builds/38907195
The command is exiting 0 because you're piping to xcpretty and not accounting for exit codes. See: https://github.com/supermarin/xcpretty#usage
We're using closures in Swift but we have to be careful with them because we could have the same retaining cycles that we had in case of blocks in Objective-C. Review where we are using them and if we are passing the variables from outside with the proper referencing type.
Depends on this issue (to avoid possible conflicts in naming): #11
When Cocoapods is compatible with Swift projects it would be great to have documentation there to be easily checked out by our library users.
Dependent of 1.0 stack refactor
http://cocoadocs.org/
Pod::Spec.new do |s|
s.name = "Quick"
s.version = "0.2.0"
s.summary = "The Swift (and Objective-C) testing framework."
s.description = <<-DESC
Quick is a behavior-driven development framework for Swift and Objective-C. Inspired by RSpec, Specta, and Ginkgo.
DESC
s.homepage = "https://github.com/Quick/Quick"
s.license = { :type => "Apache 2.0", :file => "LICENSE" }
s.author = "Quick Contributors"
s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.10"
s.source = { :git => "https://github.com/Quick/Quick.git", :tag => "v0.2.0" }
s.source_files = "Quick", "Quick/**/*.{swift,h,m}"
s.framework = "XCTest"
end
If you would like to use Quick with CocoaPods today, you will need to use
rubygem's Bundler to use the swift branch of CocoaPods. This
can be done by including a Gemfile that looks like this:
source 'https://rubygems.org'
gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :branch => 'swift'
gem 'cocoapods-core', :git => 'https://github.com/CocoaPods/Core.git', :branch => 'swift'
gem 'xcodeproj', :git => "https://github.com/CocoaPods/Xcodeproj.git", :branch => 'ext_build_settings'
Then run bundle install
to start using Swift CocoaPods for just this project.
Then in your Podfile, add the following to your test target.
pod 'Quick', :git => "https://github.com/Quick/Quick", :head
Finally, run bundle exec pod install
. The bundle exec
ensures you're using
the Swift CocoaPods version from your Gemfile.
It seems that Jazzy has been updated to support the last version of XCode
Use it to generate documentation for SugarRecord and upload the generated doc to
http://sugarrecord.com/docs
In swift we don't have blocks anymore, we could give a more appropriate name for this
I can pass compile at xcode 6.1.1(6A2006)
at last of iCloudCDStack.swift line 267, lastPathComponent is a Optional Value, should add "!" ?
self!.databasePath = NSURL(fileURLWithPath: iCloudRootPath!.path!.stringByAppendingPathComponent(self!.icloudData!.iCloudDataDirectoryName).stringByAppendingPathComponent(self!.databasePath!.lastPathComponent))
In addition of saving and creating methods, add import methods for the use cases which we have a huge collection of data to import into Core Data.
Fill the Wiki explaining how to use different components of the library:
https://github.com/magicalpanda/MagicalRecord/wiki
Hi there!
First, thanks for this project, it looks awesome! I'm just starting to use it but the potential is very great :)
Ok, I started using it on a new project so I created my first NSManagedObject
subclass as a Swift file.
I encountered an issue with this line of code in NSManagedObject+Stack.swift
inside class func entityDescription(inContext context: NSManagedObjectContext?) -> (NSEntityDescription)
method:
return NSEntityDescription.entityForName(entityName, inManagedObjectContext: context!)!
This returns EXC_BAD_INSTRUCTION and the debugger logs:
fatal error: unexpectedly found nil while unwrapping an Optional value
.
To fix this I thought about removing the NSManagedObject
Swift file and rebuild it in Objective-C (and add it to the "APP-Bridging-Header.h"). Then it all works like a charm.
For me is not a big deal because if I want to extend it in Swift I use and it works:
extension managedClassName {
}
...I will never overwrite a subclass like this anyway
I say this because I haven't found anything about this on the README file and it may help other people that are stuck on the same issue. This fixes the issue, but a lot of people may be creating Swift subclasses (All in in Swift!!!) and hitting this wall.
Thanks again for this fantastic project ๐
Regarding the last update notes, http://realm.io/news/realm-cocoa-0.86.0/:
Each subclass is treated as an entirely distinct type containing all of the properties defined on it and all of its parent classes. This means that you can do things like [company.employees objectsWhere:@"name > 25"](querying an object based on a property defined in a parent class), but you cannot use an object of a subclass in a relationship where the parent is expected. That is, the following does not work:
Thanks for the hard work - great library!!!
Just running into an issue with a query - in the example
users: [User]? = User("age", equalTo: "10").sorted(by:"name", ascending: true).find()?
We get an error of "Extra Argument in Call" for the initial method call...
User("age", equalTo: "10")
Should we be extending our objects from something else besides NSManagedObject
thanks for your help
by()
method into:by(name: String, stringValue: String)
by(name: String, intValue: String)
I would love to be able to integrate with Restkit.
there's already a few examples of how to integrate MagicalRecord with RestKit
see:
https://github.com/m1entus/MZFlickrMania/blob/master/FlickrMania/MZAppDelegate.m#L40-L57
https://github.com/RestKit/RKGist/blob/master/TUTORIAL.md#configuring-restkit--core-data
https://github.com/magicalpanda/MagicalRecord/blob/develop/Docs/GettingStarted.md
also, do you guys think they will work well together?
ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later (@rpath/SugarRecord.framework/SugarRecord) for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
you have a method entityName() in your NSManagedObject extension. MOGenerator adds its own.
I would suggest you rename yours so they will work easily together and MOGenerator has been around for years.
Realm has a feature to cancel a write operation. We should support it too in SugarRecord. This way if the user inserted the object in the SugarRecordContext
and he/she ends up cancelling it, there's no need to commit and then delete. Just cancel the operation
Which iOS version for iCloud is supported iOS 7, iOS 8 or both. And is there some specific steps to add iCloud support different from just change the CoreDataStack and enable iCloud?
I'm trying to setup my project to use sugarrecord as a submodule but i am unable to get the application to compile.
I want to use CoreData and RestKit, and I followed your instructions on the wiki, but it keeps saying builds fails (no error) i'm not sure what i'm doing wrong.
do you have example application that has sugarrecord imported as a submodule?
@pepibumur
Hello,
Thanks for the great source, it works like a charm.
but it not Objective - C language.
Jack
One of the most remarkable features of Swift is its sugar syntax and it's time to bring it to SugarRecord too. This issue is opened as a brainStorming to talk about the syntax and how we could refactor our methods.
// Operations with contexts
person.save()
person.save(asynchronously)
person.inContext(context).save()
person.inContext(context).save(asynchronously)
// Main examples
Person.by("name", "Pedro").sorting("age", ascending: true).fist() // -> NSFetchRequest
Person.by("name", "Pedro").sorting("age", ascending: true).first(20).find() // -> [NSManagedObject]?
Person.by("name", "Pedro").sorting("age", ascending: true).last().find(context) // -> [NSManagedObject]?
Person.by("name", "Pedro").sorting("age", ascending: true).all().find(context, asynchronously: true) // -> [NSManagedObject]?
// Alternatives around previous idea
Person.by("name", "Pedro").all // -> NSFetchRequest
Person.by("name", "Pedro").first(20) // -> NSFetchRequest
Person.by("name", "Pedro").last(20) // -> NSFetchRequest
Person.by("name", "Pedro").all // -> NSFetchRequest
Person.by("name", "Pedro").first // -> NSFetchRequest
// FetchedResultsController
Person.by("name","Pedro").fetchedResultsController() // -> NSFetchedResultsController
I found that when i call model.save() or model.endWriting(), they are not save to database.
Sometimes , I want to manually call the save method to save data immediately in database.
like:
[MagicalRecord saveUsingCurrentThreadContextWithBlockAndWait:nil];
Instead of having a method like this one:
public class func by(key: String, equalTo value: String) -> SugarRecordFinder
We could have a method like this one
public class func by(key: String, equalTo value: StringLiteralConvertible) -> SugarRecordFinder
Allowing the users to use other types besides Strings. Check if we can apply that in some other places around the app.
I'm using SugarRecord but have an issue: i can't execute page request.
fetchRequest.fetchOffset = page * size;
fetchRequest.fetchLimit = size;
I know SugarRecordFinder have an firsts() function, but can't set offset.
And, SugarRecord.operations give me a SugarRecordContext, so i can't use NSManagedObjectContext direct.
For any reason Travis is failing. Try to fix it and leave it passing for future PR proposals
But i dont use it, how to be compatible.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.