CoreData使用

浅谈SwiftUI 3.0新加入的CoreData动态FetchRequest过滤与排序特性 本篇博文您将学到:SwiftUI 3.0之前SwiftUI如何支持动态过滤与排序;SwiftUI 3.0中FetchRequest对象对上面功能的原生支持。 阅读详情
CoreData相当于一个综合的数据库管理库,它支持sqlite,二进制存储文件两种形式的数据存储。而CoreData提供了存储管理,包括查询、插入、

删除、更新、回滚、会话管理、锁管理等一系列数据库操作。另外,开发者还可以在xcode中使用 .xcdatamodel 扩展名的文件,以图形化的形式编辑数据模型,这里包括了

Entities、Properties、Attributes、Relationships四个概念,这里跟关系型数据库有很大的相似点。

                  下面来看一下CoreData的框架。

                一次来了解一下 PersistentStore、DataModel、PersistentStoreCoordinator、ManagedObjects、ManagedObjectsContext、FetchRequest 这些概念。

                PersistentStore

                            这个是数据真正存储的地方,CodeData提供了两种存储的选择,分别是sqlite和二进制文件。PersistentStore本身并不是objc类,仅仅是数据存储。

               DataModel

                              对应的objc类为 NSManagedObjectModel,一个典型的应用如:

 

[cpp]  view plain copy
  1. /** 
  2. Returns the managed object model for the application. 
  3. If the model doesn't already exist, it is created by merging all of the models 
  4. found in the application bundle. 
  5. */  
  6. - (NSManagedObjectModel *)managedObjectModel {  
  7. if (managedObjectModel != nil) {  
  8. return managedObjectModel;  
  9. }  
  10. managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];  
  11. return managedObjectModel;  
  12. }  
这里用了iPhone开发中典型的laze loading,而
[cpp]  view plain copy
  1. managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];  

中的nil表示连接项目中所有的 .xcodemodel 文件为一个datamodel,这是一个非常好的方法,把多个entity放在各自的xcodemodel文件中分开管理,然后用这个函数连接起来生成一个datamodel,这样就可以对应一个persistentStore。

PersistentStoreCoordinator

     对应的objc类为NSPersistentStoreCoordinator,这个类用来控制对PersistentStore的访问。PersistentStoreCoordinator提供了一些列的高级调用供其他类来使用,对PersistentStore进行读和写。下面看一段典型的代码:

 

[cpp]  view plain copy
  1. /** 
  2. Returns the persistent store coordinator for the application. 
  3. If the coordinator doesn't already exist, it is created and the application's store 
  4. added to it. 
  5. */  
  6. - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {  
  7.     if (persistentStoreCoordinator != nil) {  
  8.         return persistentStoreCoordinator;  
  9.     }  
  10.     NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory]  
  11.     stringByAppendingPathComponent: @"CoreData.sqlite"]];  
  12.     NSError *error;  
  13.     persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]  
  14.     initWithManagedObjectModel: [self managedObjectModel]];  
  15.     if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType  
  16.     configuration:nil URL:storeUrl options:nil error:&error]) {  
  17.     // Handle error  
  18.     }  
  19.     return persistentStoreCoordinator;  
  20. }  
这里默认存储形式为sqlite,并且存储文件为CoreData.sqlite,这段代码比较简单,创建了persistentStoreCoordinator实例。

 

ManagedObjects

    对应的类为NSManagedObject。上面的CoreData框架图中有Entities,Entity定义了数据的结构,但他并不是数据,真正的数据实例是NSManagedObject类或他的子类。

    NSManagedObject类支持Key-Value 编码(KVC),像NSDictionary差不多。NSManagedObject提供了valueForKey:和setValue:forKey:用来设置和查询的方法。另外他也提供了对关系操作的方法。

   下面是几个典型的代码案例:

 

[cpp]  view plain copy
  1. NSDate *timeStamp = [managedObject valueForKey:@"timeStamp"];  

[cpp]  view plain copy
  1. [managedObject setValue:[NSDate date] forKey:@"timeStamp"];  

另外KVC也支持keypath,如有两个数据entity,一个是Employee,一个事Employer,Employee中有个属性石whereIWork,而这个属性用relationship连接到了对应的Employer,Employer中有个属性石name,这样要查询一个Employer的name,可以用keypath的形式, whereIWork.name。

 

 

[cpp]  view plain copy
  1. NSString *employerName = [managedObject valueForKeyPath:@"whereIWork.name"];  

 

ManagedObjectsContext

    对应的类为NSManagedObjectsContext。 这个类是一个用户对persistentStore操作的网关,他维护了用户创建或者加载的managed objects。他记录了用户对managed objects的所有改变,以便用来undo或redo,另外当用户要存储现在的managed objects到persistentstore时,只需调用managedObjectsContext的save方法就行了。

    每个应用至少需要一个context,当然可以同时存在多个context,比如多线程时,如NSOperationQueue。context并不是线程安全的,因此在这种情况中用户要自己做好安全工作。

    下面是一个简单应用实例。

[cpp]  view plain copy
  1. /** 
  2. Returns the managed object context for the application. 
  3. If the context doesn't already exist, it is created and bound to the persistent 
  4. store coordinator for the application. 
  5. */  
  6. - (NSManagedObjectContext *) managedObjectContext {  
  7.     if (managedObjectContext != nil) {  
  8.         return managedObjectContext;  
  9.     }  
  10.     NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];  
  11.     if (coordinator != nil) {  
  12.         managedObjectContext = [[NSManagedObjectContext alloc] init];  
  13.         [managedObjectContext setPersistentStoreCoordinator: coordinator];  
  14.     }  
  15.     return managedObjectContext;  
  16. }  

这个代码也比较简单,不做解释了。

 

FetchRequest(FetchRequestController)

 

这里重点讲FetchRequestController,其实用户打交道最多的就是这个控制器了。要讲的东西很多,放到下面一篇吧。

这篇文章重点讲讲CoreData的Fetched Results Controller。

             对应的objc类为NSFetchedResultsController。这个类是用来管理CoreData Fetch request返回的对象的。

             在创建这个控制器之前,必须先创建fetch request。 fetch request描述了详细的查询规则,还可以添加查询结果的排序描述(sort descriptor)。fetchResultsController根据已经创建完的fetch request来创建, 它是NSFetchedResultsController的实例,这个实例的主要任务就是使用fetch request来保证它所关联的数据的新鲜性。创建了fetchResultsController实例后要做一下初始化,一般初始化是向这个控制器发送PerformFetch消息,下面是这一过程的代码。

[cpp]  view plain copy
  1. - (NSFetchedResultsController *)fetchedResultsController {    
  2.     if (fetchedResultsController != nil) {    
  3.         return fetchedResultsController;    
  4.     }    
  5.     /*  
  6.     Set up the fetched results controller.  
  7.     */    
  8.     // Create the fetch request for the entity.    
  9.     NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];    
  10.     // Edit the entity name as appropriate.    
  11.     NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event"    
  12.     inManagedObjectContext:managedObjectContext];    
  13.     [fetchRequest setEntity:entity];    
  14.     // Set the batch size to a suitable number.    
  15.     [fetchRequest setFetchBatchSize:20];    
  16.     // Edit the sort key as appropriate.    
  17.     NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]    
  18.     initWithKey:@"timeStamp" ascending:NO];    
  19.     NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor,nil];    
  20.     [fetchRequest setSortDescriptors:sortDescriptors];    
  21.     // Edit the section name key path and cache name if appropriate.    
  22.     // nil for section name key path means "no sections".    
  23.     NSFetchedResultsController *aFetchedResultsController =    
  24.     [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest    
  25.     managedObjectContext:managedObjectContext sectionNameKeyPath:nil    
  26.     cacheName:@"Root"];    
  27.     aFetchedResultsController.delegate = self;    
  28.     self.fetchedResultsController = aFetchedResultsController;    
  29.     [aFetchedResultsController release];    
  30.     [fetchRequest release];    
  31.     [sortDescriptor release];    
  32.     [sortDescriptors release];    
  33.     return fetchedResultsController;    
  34. }    

            `这个函数用来创建FetchedResultsController,过程还是比较简单的,下面是初始化这个控制器代码。

[cpp]  view plain copy
  1. NSError *error = nil;    
  2. if(![[self  fetchedResultsController]performFetch: &error]){    
  3.     //handle the error appropriately    
  4.     NSLog(@"Unresolved error %@, %@", error, [error userInfo]);    
  5.     exit(-1);    
  6. }    

          这段代码一般会放在viewDidLoad函数中,初始化之后,fetchedResultsController就与数据相连接了,之后要取数据都能直接从这个控制器提供的方法中去取。

            实现这个控制器,最关键的还要实现Fetched Results Controller Delegate Methods。控制器与数据源连接后,控制器监视器会时刻监视着数据源,当数据源发生

改变后,监视器会调用对应的协议方法,改协议总共要实现四个方法,分别为:

[cpp]  view plain copy
  1. - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller;    
  2. - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller;    
  3. - (void)controller:(NSFetchedResultsController *)controller    
  4.    didChangeObject:(id)anObject    
  5.        atIndexPath:(NSIndexPath *)indexPath    
  6.      forChangeType:(NSFetchedResultsChangeType)type    
  7.       newIndexPath:(NSIndexPath *)newIndexPath;    
  8. - (void)controller:(NSFetchedResultsController *)controller    
  9.   didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo    
  10.            atIndex:(NSUInteger)sectionIndex    
  11.      forChangeType:(NSFetchedResultsChangeType)type;    

 

              下面依次来解释这四个协议方法。

              1.  - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller

            当控制器监控的数据发生改变时,如对象被删除,有插入,更新等,监视器会在数据发生改变前意识到这个情况,此时就会调用这个函数。往往我们用列表的形式

表现数据,此时意味着屏幕上的数据即将过时,因为数据马上要改变了,这是这个协议方法的工作就是通知列表数据马上要更新的消息,往往代码是这样实现的。 
[cpp]  view plain copy
  1. - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {    
  2.     [self.tableView beginUpdates];    
  3. }   

 

           2. - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller

            当fetchedResultsController完成对数据的改变时,监视器会调用这个协议方法。在上面提到的情况,这个方法要通知列表数据已经完成,可以更新显示的数据这个

消息,因此通常的实现是这样的。

 

[cpp]  view plain copy
  1. - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {    
  2.     [self.tableView endUpdates];    
  3. }    
  3. - (void)controller:(NSFetchedResultsController *)controller

 

 

              didChangeObject:(id)anObject 

                        atIndexPath:(NSIndexPath *)indexPath 

                  forChangeType:(NSFetchedResultsChangeType)type 

                    newIndexPath:(NSIndexPath *)newIndexPath

               当fetchedResultsController发现指定的对象有改变时,监视器会调用这个协议方法。这里改变的类型从列表中体现有 更新、插入、删除或者行的移动。因此这个

方法要实现所有的这些方法,以应对任何一种改变。下面是这个方法的标准实现。

[cpp]  view plain copy
  1. - (void)controller:(NSFetchedResultsController *)controller    
  2.    didChangeObject:(id)anObject    
  3.        atIndexPath:(NSIndexPath *)indexPath    
  4.      forChangeType:(NSFetchedResultsChangeType)type    
  5.       newIndexPath:(NSIndexPath *)newIndexPath {    
  6.     switch(type) {    
  7.         case NSFetchedResultsChangeInsert:    
  8.             [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]     
  9.                             withRowAnimation:UITableViewRowAnimationFade];    
  10.             break;    
  11.         case NSFetchedResultsChangeDelete:    
  12.             [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]    
  13.                             withRowAnimation:UITableViewRowAnimationFade];    
  14.             break;    
  15.         case NSFetchedResultsChangeUpdate: {    
  16.             NSString *sectionKeyPath = [controller sectionNameKeyPath];    
  17.             if (sectionKeyPath == nil)    
  18.                 break;    
  19.             NSManagedObject *changedObject = [controller objectAtIndexPath:indexPath];    
  20.             NSArray *keyParts = [sectionKeyPath componentsSeparatedByString:@"."];    
  21.             id currentKeyValue = [changedObject valueForKeyPath:sectionKeyPath];    
  22.             for (int i = 0; i < [keyParts count] - 1; i++) {    
  23.                 NSString *onePart = [keyParts objectAtIndex:i];    
  24.                 changedObject = [changedObject valueForKey:onePart];    
  25.             }    
  26.             sectionKeyPath = [keyParts lastObject];    
  27.             NSDictionary *committedValues = [changedObject committedValuesForKeys:nil];    
  28.             if ([[committedValues valueForKeyPath:sectionKeyPath]isEqual:currentKeyValue])    
  29.                 break;    
  30.             NSUInteger tableSectionCount = [self.tableView numberOfSections];    
  31.             NSUInteger frcSectionCount = [[controller sections] count];    
  32.             if (tableSectionCount != frcSectionCount) {    
  33.                 // Need to insert a section    
  34.                 NSArray *sections = controller.sections;    
  35.                 NSInteger newSectionLocation = -1;    
  36.                 for (id oneSection in sections) {    
  37.                     NSString *sectionName = [oneSection name];    
  38.                     if ([currentKeyValue isEqual:sectionName]) {    
  39.                         newSectionLocation = [sections indexOfObject:oneSection];    
  40.                         break;    
  41.                     }    
  42.                 }    
  43.                 if (newSectionLocation == -1)    
  44.                     return; // uh oh    
  45.                 if (!((newSectionLocation == 0) && (tableSectionCount == 1)    
  46.                        && ([self.tableView numberOfRowsInSection:0] == 0)))    
  47.                     [self.tableView insertSections:[NSIndexSet indexSetWithIndex:newSectionLocation]    
  48.                                   withRowAnimation:UITableViewRowAnimationFade];    
  49.                 NSUInteger indices[2] = {newSectionLocation, 0};    
  50.                 newIndexPath = [[[NSIndexPath alloc] initWithIndexes:indiceslength:2] autorelease];    
  51.             }    
  52.         }    
  53.         case NSFetchedResultsChangeMove    
  54.             if (newIndexPath != nil) {    
  55.                 [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]    
  56.                                       withRowAnimation:UITableViewRowAnimationFade];    
  57.                 [self.tableView insertRowsAtIndexPaths: [NSArray arrayWithObject:newIndexPath]    
  58.                                       withRowAnimation: UITableViewRowAnimationRight];    
  59.             }    
  60.             else {    
  61.                 [self.tableView reloadSections:[NSIndexSet    
  62.                 indexSetWithIndex:[indexPath section]]withRowAnimation:UITableViewRowAnimationFade];    
  63.             }    
  64.             break;    
  65.         default:    
  66.             break;    
  67.     }    
  68. }    

 

 

          从上面的代码可以看出,插入,删除,移动是比较简单的,最复杂的是更新。这个代码是xcode的模板代码,基本能适用我们遇到的情况,对更新里面的代码我还不是非常确定,所以这里留着等过几天完全吃透了再补上。

 

 

           4. - (void)controller:(NSFetchedResultsController *)controller

            didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo

                                atIndex:(NSUInteger)sectionIndex 

                 forChangeType:(NSFetchedResultsChangeType)type

              当改变控制器管理的对象后引起了列表section的变化,此时监视器就会调用这个协议函数。

            下面是标准实现。 

[cpp]  view plain copy
  1. - (void)controller:(NSFetchedResultsController *)controller    
  2.   didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo    
  3.            atIndex:(NSUInteger)sectionIndex    
  4.      forChangeType:(NSFetchedResultsChangeType)type {    
  5.     switch(type) {    
  6.         case NSFetchedResultsChangeInsert:    
  7.             if (!((sectionIndex == 0) && ([self.tableView numberOfSections] == 1)    
  8.                              && ([self.tableView numberOfRowsInSection:0] == 0)))    
  9.                 [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]    
  10.                               withRowAnimation:UITableViewRowAnimationFade];    
  11.             break;    
  12.         case NSFetchedResultsChangeDelete:    
  13.             if (!((sectionIndex == 0) && ([self.tableView numberOfSections] == 1)    
  14.                              && ([self.tableView numberOfRowsInSection:0] == 0)))    
  15.                 [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]    
  16.                               withRowAnimation:UITableViewRowAnimationFade];    
  17.             break;    
  18.         case NSFetchedResultsChangeMove:    
  19.         case NSFetchedResultsChangeUpdate:    
  20.         default:    
  21.             break;    
  22.     }    
  23. } 
【Aseprite】制作Unity2D瓦片地图素材(平台游戏) 本文章用于记录用Aseprite软件制作2D平台游戏的瓦片地图的方法。 阅读详情

相关推荐

python设计俄罗斯方块(附源码)

【代码】python设计俄罗斯方块(附源码)

牧魂的博客 2066

SwiftUI入门 - Core Data包装器@FetchRequest的排序、筛选和分页

在上一篇文章《SwiftUI入门 - Core Data初探与实践》中,我们已知晓Core Data模型、实体和实体属性的创建,并通过编写CRUD函数完成了实体数据的增删改查操作。在实现查询数据的过程中对属性包装器的使用则是一笔带过,并未对其进行详细的了解。本文中将对Core Data的排序、筛选和分页的使用方法进行学习和探究。我们通过的形参与结构体来对查询数据进行排序使用predicate进行数据筛选过滤,了解到中的format其实就是SQL中的where语句。

ttheitao的博客 505

海思MIPI屏调试实战:从参数计算到点亮屏幕的完整指南

本文提供了一份海思平台MIPI屏幕调试的完整实战指南。文章以Hi3516DV300调试800x1280分辨率屏幕为例,详细讲解了从参数计算、配置文件修改到最终点亮屏幕的全流程,并分享了常见问题排查与进阶优化技巧,旨在帮助嵌入式开发者高效解决MIPI屏调试难题。

weixin_29190573的博客 743

iOS CoreData

我目前的理解,CoreData相当于一个综合的数据库管理库,它支持sqlite,二进制存储文件两种形式的数据存储。而CoreData提供了存储管理,包括查询、插入、 删除、更新、回滚、会话管理、锁管理等一系列数据库操作。另外,开发者还可以在xcode中使用 .xcdatamodel 扩展名的文件,以图形化的形式编辑数据模型,这里包括了 Entities、Properties、At...

aihuangfu1459的博客 258

GX WORKS2通过交换机连接PLC的方法

三菱PLC连接方法的分享

weixin_64927621的博客 3632

西门子WinCC VBS脚本实战:5分钟搞定变量记录导出到Excel(附完整代码)

本文提供了一套高效的西门子WinCC VBS脚本方案,帮助工程师在5分钟内将变量记录数据导出至Excel。方案详细解析了时区转换、数据库连接、SQL查询优化等核心难点,并附带了完整、可直接使用的VBS代码,解决了工业自动化项目中数据导出的实际痛点。

moss5的博客 616

coredata基本用法(一)

在项目中添加coredata过程详解

浮生若梦 为欢几何 1887

最新CobaltStrike4.8/CobaltStrike4.9、CS4.9/CS4.8、 Windows/Linux/Mac版下载

Cobalt Strike是一款基于java的渗透测试神器,常被业界人称为CS神器。自3.0以后已经不在使用Metasploit框架而作为一个独立的平台使用,分为客户端与服务端,服务端是一个,客户端可以有多个,非常适合团队协同作战,多个攻击者可以同时连接到一个团队服务器上,共享攻击资源与目标信息和sessions,可模拟APT做模拟对抗,进行内网渗透。 Cobalt Strike集成了端口转发、服务扫描,自动化溢出,多模式端口监听,win exe木马生成,win dll木马生成,java木马生成,

weixin_43167326的博客 7994

NSFetchRequest

NSFetchRequest 获取数据的请求,通过被管理数据的上下文来执行查询,比如 NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; 查询时,必须指定查询实体或实体名称,以 NSArray 形式返回查询结果,如果我们没有设置任何查询条件,则返回该 Entity 的所有...

weixin_33834075的博客 166

linux内核学习(一)---内核社区介绍及补丁提交

本系列开始会对linux内核进行系统性的学习,以源码与内核社区为基础,了解前沿的内核机制,同时也深度了解linux内核中的一些经典机制 本章会先对linux内核社区进行简单的介绍,包括源码下载、内核社区的修改提交

文艺小少年的博客 539

keil指定变量存储在外部SRAM

本文介绍在keil工程中如何将程序中的变量定义在外部SRAM,包括sct分散加载文件的配置和启动文件的设置。

kevin1499的博客 2097

iOS CoreData的使用

CoreData是一个专门管理数据服务的框架,把OC对象和存储在SQLite文件中的数据进行互相转换,极大地方便了开发者在数据服务方面的开发。 1. 创建CoreData 在文件创建区下,选择【Core Data】下的【Data Model】 输入CoreData的文件名Model.xcdatamodel Model.xcdatamodeld文件默认是Swift的,如果想要改成oc,可以在打开Model.xcdatamodeld文件,在右侧工具栏中修改。 2. 创建Entity CoreData文件下

假装你是大灰狼的专栏 6726

【如何学习CAN总线测试】——Python+Robot Framework框架实现UDS诊断自动化

由于项目需要进行UDS诊断测试,所以对这方面进行了研究学习,网上很少能查询到相关资料,故记录一下UDS自动化测试开发过程,由于保密原则,案例都是Demo,希望能帮到感兴趣的朋友。

测试领域技术分享 7480

CoreData—基础使用

创建自带CoreData的工程 在新建一个项目时,可以勾选Use Core Data选项,这样创建出来的工程系统会默认生成一些CoreData的代码以及一个.xcdatamodeld后缀的模型文件,模型文件默认以工程名开头。这些代码在AppDelegate类中,也就是代表可以在全局使用AppDelegate.h文件中声明的CoreData方法和属性。 系统默认生成的代码是非常简单的,只

ZH952016281的博客 2686

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

数据缓存——CoreData的使用

CoreData的使用   1、使用到的对象 (1)NSManagedObjectContext 操作数据库的上下文(数据库,获取与存储),即负责应用与数据库之间的交互 作用:插入数据、查询数据、删除数据 (2)NSManagedObjectModel  数据库中所有表格和他们的联系(数据模型),即代表CoreData模型文件,相  当于实体  作用:添加实体的属性与类型设置,建

番薯大佬的专栏 5061

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

CoreData基本使用

CoreData简介 CoreData是一门功能强大的数据持久化技术,位于SQLite数据库之上,它避免了SQL的复杂性,能让我们以更自然的方式与数据库进行交互。CoreData提供数据--OC对象映射关系来实现数据与对象管理,这样无需任何SQL语句就能操作他们。CoreData数据持久化框架是Cocoa API的一部分,⾸次在iOS5 版本的系统中出现,它允许按照实体-属性-值模型...

ZHANGBO9477的博客 265

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Swift CoreData 使用

使用 CoreData 1. 新建项目时选用 core data 或者在后来添加 .xcdatamodeld 文件 2. 在 AppDelegate 中 获取 persistentContainer 声明一个 lazy 变量 persistentContainer 把模型名字传递给初始化的方法 如果存在 store 返回 store class AppDelegate: UIResponde...

学习笔记 2178

Coredata第一课 认识coredata

问题 在iOS/Mac中我们有许多方式去持久化存储数据:NSUserDefault、Key chain、C语言文件接口、NSFileHandle、基础框架中的write方法、归档等等。在实际应用中,我们经常需要将这些数据按一定格式转换为 对象,并且进行一定的筛选等操作然后再使用,显得不是...

chengyaqiu2938的博客 157

coredata的使用

转载点击打开转载地址

潜龙勿用的专栏 1030

SwiftUI之简单CoreData使用后续

CoreData使用后续 在之前的基础上增加对已经录入的内容的修改。新建SwiftUI文件,命名为EditListToDo.swift。 内容如下(简单注释): import SwiftUI import CoreData struct EditListToDo: View { @Environment(\.managedObjectContext) var managedObjectContext @Environment(\.presentationMode) var presentationMode

jackwsd的博客 781

OC CoreData简单使用

  CoreData是苹果提供的一种ORM(对象型关系数据库),类似于JavaEE轻量级架构中得Hibernate。这里总结一下CoreData的使用流程。   1.创建Model      2.添加实体,同时添加属性      3.添加完属性后,即可以生成被管理模型   4.设计数据库管理类(WKDataManager)   WKDataManager.h ...

weixin_34345560的博客 513

CoreData

CoreData 一、简介 Core Data 是数据持久化存储的最佳方式,能够合理管理内存,避免使用sql的麻烦。 (1)NSManagedObjectContext(被管理的数据上下文) 操作实际内容(操作持久层) 作用:插入数据,查询数据,删除数据 (2)NSManagedObjectM...

chuotuihou4415的博客 171

CoreData的简单使用

iOS开发-CoreData的简单使用 什么是CoreData? CoreData是iOS5之后才出现的一个框架, 它提供了对象-关系映射(ORM)的功能, 即能够将OC对象转换成数据, 保存在SQLite数据库文件中, 也能够将保存在数据库中的数据还原成OC对象. 这个过程中, 我们不需要编写任何的sql语句, 这个有点类似于著名的Hibernate持久框架, 不过功能肯定没有Hibe

奋斗小青年的博客 439

Coredata

一. CoreData 是什么? Core Data 是 iOS SDK 里的一个很强大的框架,允许程序员以面向对象的方式储存和管理数据。使用 Core Data 框架,程序员可以很轻松有效地通过面向对象的接口管理数据Core Data 是一个模型层的技术。帮助建立代表程序状态的模型层,Core Data 也是一种 持久化技术,能将模型对象的状态持久化到磁盘,但它最重要的特点是: Core

github_35852596的博客 170

CoreData介绍

写在前面 在CoreData中有一些常用的类,称呼可能各不相同。所以这里先约定一些关键字,以便理解后面的一些内容,这些约定很多都是出现在苹果的官方文档中的。 NSPersistentStoreCoordinator(Persistent Store Coordinator),缩写为PSC。 NSManagedObjectContext(Managed Object Context

ZH952016281的博客 1709
上一篇: UIWebView数据自动检测开关
下一篇: CoreData原理
focusjava
博客等级 码龄14年 127粉丝 528原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址