magicalrecord

How to use Core Data models without saving them?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 10:16:12
I'm writing an application and I am using MagicalRecord as a framework for interacting with Core Data. The application fetches an array of posters from a server and then displays them. Posters can also be created on the app and then uploaded to the server if the user requires it. So posters created by the user are stored in the local db using Core Data, while posters fetched from the server should only be displayed in the app but not saved locally. How can I use the same Poster class (which now is a subclass of NSManagedObject) to handle both these cases? Here is my class: @interface Poster :

NSPredicate not executed

时光毁灭记忆、已成空白 提交于 2019-11-29 09:26:33
问题 This is quite funny. In my application I create thousands of entry in the database (in another thread, I'm using MagicalRecord). Everything seems working fine (from a background/foreground/context point of view). When, in the main thread, I try to fetch the "just inserted" data, I discovered the following behaviour: - (NSArray *) familiesInCompany:(Company *) company { NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"company == %@", company]; NSPredicate *predicate2 = [NSPredicate

Cannot use a predicate that compares dates in Magical Record

荒凉一梦 提交于 2019-11-28 14:34:11
I am making a method that will remove all of my NSManagedObjects that were not updated in the last sync. - (void)removeStaleObjects { // Delete objects that have not been updated in this sync. NSPredicate *stalePredicate = [NSPredicate predicateWithFormat:@"updated < %@", self.syncStart]; NSArray *staleObjects = [Node MR_findAllWithPredicate:stalePredicate]; for (Node *n in staleObjects) { [[NSManagedObjectContext MR_defaultContext] deleteObject:n]; } } The code keeps failing on the MR_findAll... line with [__NSDate objCType]: unrecognized selector sent to instance I have checked my syntax

How to use Core Data models without saving them?

本小妞迷上赌 提交于 2019-11-28 03:48:17
问题 I'm writing an application and I am using MagicalRecord as a framework for interacting with Core Data. The application fetches an array of posters from a server and then displays them. Posters can also be created on the app and then uploaded to the server if the user requires it. So posters created by the user are stored in the local db using Core Data, while posters fetched from the server should only be displayed in the app but not saved locally. How can I use the same Poster class (which

Cannot use a predicate that compares dates in Magical Record

北城以北 提交于 2019-11-27 08:26:41
问题 I am making a method that will remove all of my NSManagedObjects that were not updated in the last sync. - (void)removeStaleObjects { // Delete objects that have not been updated in this sync. NSPredicate *stalePredicate = [NSPredicate predicateWithFormat:@"updated < %@", self.syncStart]; NSArray *staleObjects = [Node MR_findAllWithPredicate:stalePredicate]; for (Node *n in staleObjects) { [[NSManagedObjectContext MR_defaultContext] deleteObject:n]; } } The code keeps failing on the MR

MagicalRecord,一个简化CoreData操作的工具库

左心房为你撑大大i 提交于 2019-11-27 02:20:01
简介 项目主页: https://github.com/magicalpanda/MagicalRecord 实例下载: https://github.com/ios122/MagicalRecord 在软件工程中,活动记录模式是一种用于在关系数据库中存储数据的设计模式.这种设计模式最早由Martin Fowler在他的 Patterns of Enterprise Application Architecture 一书中命名.这样的一个对象的,接口应该包含插入,更新和删除的方法;再加上与底层数据库几乎直接对应的的属性. 活动记录是一种访问数据库中数据的方式.一个数据库的表或者试图被装箱进一个类中;因此,一个对象实例对应表中的一行数据.在创建对象之后,会往表中添加新的一行以保存数据.加载对象时,从数据库中获取信息;当对象更新时,表中对应的行也会被更新.装箱类实现存取方法和分别对应表或视图中每一列的属性. - Wikipedia MagicalRecord 受Ruby on Rails活动记录获取方式的便利性影响.项目目标是: 清理我的Core Data相关代码 支持清晰,简单,一行代码式的查询 当需要优化请求时,仍然可以修改 NSFetchRequest. 使用 CocoaPods 安装 把下面一行添加到 Podfile : pod "MagicalRecord" 在工程目录执行:

Permanent NSManagedObjectID not so permanent?

╄→гoц情女王★ 提交于 2019-11-26 20:15:39
问题 I'm having trouble dealing with object IDs in CoreData. I'm using MagicalRecord for convenience and have 3 contexts: a private queue working context, a main queue context for UI and parent to the working context, and a private queue saving context that is the parent of the main context. My goal is to create an object in the working context, save to the persistent store, save it's objectID URL to NSUserDefaults, and then be able to pull out that MO using the objectID later on. However, what I

How to save Array to CoreData?

孤街浪徒 提交于 2019-11-26 19:27:37
I need to save my array to Core Data. let array = [8, 17.7, 18, 21, 0, 0, 34] The values inside that array, and the number of values are variable. 1. What do I declare inside my NSManagedObject class? class PBOStatistics: NSManagedObject, Equatable { @NSManaged var date: NSDate @NSManaged var average: NSNumber @NSManaged var historicAverage: NSNumber @NSManaged var total: NSNumber @NSManaged var historicTotal: NSNumber @NSManaged var ordersCount: NSNumber @NSManaged var historicOrdersCount: NSNumber @NSManaged var values: [Double] //is it ok? @NSManaged var location: PBOLocation } 2. What do I

What is the replacement method for this MagicalRecord deprecated call?

会有一股神秘感。 提交于 2019-11-26 09:56:43
问题 How do I find the replacement method in MagicalRecord for this (which has been deprecated)? I have looked at Google, SO and the docs; nothing seems to be a replacement, and of course, nothing in the docs tell you what replaced the deprecated method. :-{ [[NSManagedObjectContext MR_contextForCurrentThread] MR_saveErrorHandler:^(NSError *error) 回答1: The deprecated method in question is: [NSManagedObjectContext MR_contextForCurrentThread] I did write a little blog post about this a while ago,

How to save Array to CoreData?

痴心易碎 提交于 2019-11-26 06:16:46
问题 I need to save my array to Core Data. let array = [8, 17.7, 18, 21, 0, 0, 34] The values inside that array, and the number of values are variable. 1. What do I declare inside my NSManagedObject class? class PBOStatistics: NSManagedObject, Equatable { @NSManaged var date: NSDate @NSManaged var average: NSNumber @NSManaged var historicAverage: NSNumber @NSManaged var total: NSNumber @NSManaged var historicTotal: NSNumber @NSManaged var ordersCount: NSNumber @NSManaged var historicOrdersCount: