Tag: core data

RESTKIT + COREDATA = FetchResultsController问题

您好,我有NSFetchedResultsController由Web应用程序的数据填充问题。 为了从服务器端映射表,我使用了RestKit框架。 当我更改当前用户时,我的UITableViewController的数据仍然呈现来自之前用户的单元格,但没有从服务器接收到信息 – 只是默认的标签文本值。 但是,单元格的数量与以前的用户相同。 它发生在我身上只有在其他一切UITableViewController工作正常。 你可以看看我的NSFetchedResultsController委托方法,并注销方法,并解释我是什么做错了,或者我应该改变,使其工作? – (void)viewDidLoad { [super viewDidLoad]; _managedObjectContext = [[DateModel sharedDataModel]objectStore].mainQueueManagedObjectContext; [self loadAlerts]; } #pragma mark – TableView Data Source – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [[self.fetchedResultsController sections] count]; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections[section]; return [sectionInfo numberOfObjects]; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { […]

如何检查UICollectionView中插入和删除的项目,看到意外的删除项目

我在这个特定的情况下努力集成UICollectionView和UICollectionView 。 在我的视图控制器中,我获取父实体,但在集合视图中显示其多个子实体。 在这个视图控制器(使用insertNewObjectForEntityForName )中创build一个新的Parent实体并自动创build一个Child实体并将其添加到具有addChildObject的父实体时,我可以通过按下一个button来添加更多的Child实体,并成功保存该对象。 不幸的是,由于某种原因, NSFetchedResultsControllerDelegate方法不被调用,具体来说, controllerDidChangeContent从不被调用,集合视图不会被更新。 当我获取一个已经存在的Parent实体,然后尝试通过添加新的Child对象来更改它时,该应用程序崩溃,出现以下exception: *** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3505.17/UICollectionView.m:4211 最后给出这个错误: CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to controllerDidChangeContent:. Invalid update: invalid number of items in section 0. The number of items contained in an existing section after […]

NSPredicate用于检测属性的类

我有事件,每个事件与NSManagedObject娱乐有一对一的关系,娱乐有多对多的关系,并有NSSet事件 @interface Event : NSManagedObject @property (nonatomic, retain) NSDate *creationDate; @property (nonatomic, retain) NSDate * date; @property (nonatomic, retain) NSString * objectId; @property (nonatomic, retain) NSString * price; @property (nonatomic, retain) Entertainment *entertainment; @property (nonatomic, retain) Place *place; @property (nonatomic, retain) NSString *townName; – (void)fillProperties:(NSDictionary *)JSON; @end @interface Entertainment : NSManagedObject @property (nonatomic, retain) NSString […]

iOS:RESTKit与CoreData同步数据

设置:RESTFull API与MySQL数据库在后端。 我正在使用RESTKit v.20.3来进行API调用。 我即将切换到核心数据。 题: 如果我在远程数据库中有10个对象,并且第一次使用GET进行获取,我将把所有10个对象都取回并存储在Core Data中。 当我做出后续的提取请求时,我该如何告诉RESTkit只下载新的对象,而不是先前下载的对象? 最佳实践方法请!

ManagedObject的子实体的关系给出错误的对象

为了减less冗余数据,我做了User的父实体。 患者和助产士都是用户的子女。 唯一的附加数据是,助产士有一套病人,病人可以有一套助产士。 当我将pipe理对象填充到核心数据时,它会显示它们与正确对象的关系。 问题是,当我尝试使用User类检索对象时,ManagedObject的关系指向错误的对象(它实际上指向同一个ManagedObject)。 我使用谓词查询核心数据NSString *predicateString = [NSString stringWithFormat:@"username == '%@' AND password == '%@'", username, password]; 当我尝试使用我的帮助器方法login时,我检查是否该对象是一个助产士或患者,所以我知道要调用什么关系。 但是这种关系指向了错误的对象。 [User userWithUsername:username password:password success:^(id user) { if([user isKindOfClass:[Midwife class]]) { NSLog(@"Midwife : %@", [user fullName]); dispatch_sync(dispatch_get_main_queue(), ^{ [self performSegueWithIdentifier:@"midwifeDashboard" sender:self]; }); } else if([user isKindOfClass:[Patient class]]) { NSLog(@"Patient : %@", [user fullName]); dispatch_sync(dispatch_get_main_queue(), ^{ [self […]

CoreData TableView里面的UIViewController

我想重新写一个我在我的应用程序中改进布局的视图。 最初我实现了一个使用CoreData作为源的TableViewController。 这个视图对我来说工作得很好,直到我需要在TableViewController中添加更多的独立于表格的视图,并且不会因为添加更多的行而滚出屏幕。 最初的实现如下,基于NSFetchedResultsController的苹果指南: CoreDataTableViewController.h: @interface CoreDataTableViewController : UITableViewController <NSFetchedResultsControllerDelegate> @property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController; – (void)performFetch; @property (nonatomic) BOOL suspendAutomaticTrackingOfChangesInManagedObjectContext; @property BOOL debug; @end CoreDataTableViewController.m: @interface CoreDataTableViewController() @property (nonatomic) BOOL beganUpdates; @end @implementation CoreDataTableViewController #pragma mark – Properties @synthesize fetchedResultsController = _fetchedResultsController; @synthesize suspendAutomaticTrackingOfChangesInManagedObjectContext = _suspendAutomaticTrackingOfChangesInManagedObjectContext; @synthesize debug = _debug; @synthesize beganUpdates = _beganUpdates; […]

如何在Core Data中使用Swift 4 Codable?

Codable似乎是一个非常令人兴奋的function。 但是我想知道我们如何在Core Data中使用它? 特别是,是否有可能直接编码/解码从/到NSManagedObject JSON? 我尝试了一个非常简单的例子: 并自己定义了Foo : import CoreData @objc(Foo) public class Foo: NSManagedObject, Codable {} 但是像这样使用它: let json = """ { "name": "foo", "bars": [{ "name": "bar1", }], [{ "name": "bar2" }] } """.data(using: .utf8)! let decoder = JSONDecoder() let foo = try! decoder.decode(Foo.self, from: json) print(foo) 编译器因此错误而失败: super.init isn't called on all […]

从实体中提取所有数据并仅打印显示最后一条logging

我试图从一个特定的核心数据实体获取所有的数据,并将每个logging放入一个string。 但是下面的代码只打印它访问的最后一个logging。 我究竟做错了什么? NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Order" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; NSLog(@"============================================="); NSLog(@"Generating Data To Be Sent"); for (NSManagedObjectContext * info in fetchedObjects) { NSLog(@"Client Name: %@", [info valueForKey:@"clientName"]); NSLog(@"Client Account Number: %@", [info valueForKey:@"clientAccountNumber"]); NSLog(@"Product Code: %@", [info valueForKey:@"productCode"]); NSLog(@"Product Price: %@", […]

应用程序拒绝在persistenstore创build崩溃

我的应用程序在启动时因为崩溃而被拒绝,在象征崩溃日志之后,我得到了以下结果: Incident Identifier: — CrashReporter Key: — Hardware Model: xxx Process: BUDGT [1029] Path: /private/var/mobile/Containers/Bundle/Application/F5D98A63-AF73-4A76-A80C-EA57B4E41082/BUDGT.app/BUDGT Identifier: –.BUDGT Version: 1 (4) Code Type: ARM-64 (Native) Parent Process: launchd [1] Date/Time: 2015-05-08 18:09:23.379 -0700 Launch Time: 2015-05-08 18:09:23.142 -0700 OS Version: iOS 8.3 (12F70) Report Version: 105 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Triggered by […]

在表视图之间传递数据

我有一个问题,我创build了一个使用CoreData的UITableView在视图之间传递数据( UITableView到一个row DetailView )我用这个方法: – (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"UpdateData"]) { NSManagedObject *selectedDevice = [self.datas objectAtIndex: [[self.tableView indexPathForSelectedRow] row]]; DetailViewController *destViewController = segue.destinationViewController; destViewController.datas = selectedDevice; } } 一切正常。 但后来我添加了一个UISearchBar不能与NSManagedObject工作,所以我创build了另一个NSMutableArray ,我保存了所有构成cell.textLabel.text的NSStrings ,并且工作正常。 但是现在我需要修改prepareForSegue为了执行一个segue每当我从SearchBar tableView中select一行。 问题是,执行这种segue与CoreData连接我需要使用NSManagedObject ,所以我的问题是:我怎么能从我的UITableView UISearchBar的indexPath.row ,并使其对应的正确indexPath.row我的self.data (这是我用来在UITableView执行正常的segue的数组,请参阅代码)? 我想我可以比较单元格(cell.textLabel.text)的string,但是 不知道该怎么办。 如果有两行同名的话我可能会遇到问题。 有什么build议? 编辑:我添加了故事板的UISearchBar,这是我用来过滤主表视图的代码: – (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { [_searchDati removeAllObjects]; NSPredicate *resultPredicate […]