草庐IT

ios - 在示例核心数据项目中出错

coder 2023-07-28 原文

我从中了解到核心数据:http://www.appcoda.com/introduction-to-core-data/ ,但是我自己开发样例工程的时候,很多错误都出现在两个文件中。 任何帮助将不胜感激,因为我是 iPhone 开发的新手

    //
//  PupilViewController.m
//  Pupils
//
//  Created by Lukasz Mozdzen on 21.04.2013.
//  Copyright (c) 2013 Lukasz Mozdzen. All rights reserved.
//

#import "PupilViewController.h"

@interface PupilViewController ()
@property (strong) NSMutableArray *pupils;

@end

@implementation PupilViewController


- (NSManagedObjectContext *)managedObjectContext
{
    NSManagedObjectContext *context = nil;
    id delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate performSelector:@selector(managedObjectContext)]) {
        context = [delegate managedObjectContext];
    }
    return context;
}


- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // Fetch the devices from persistent data store
    NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Pupil"];
    self.pupils = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];

    [self.tableView reloadData];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.pupils.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    NSManagedObject *pupil = [self.pupils objectAtIndex:indexPath.row];
    [cell.textLabel setText:[NSString stringWithFormat:@"%@ %@", [pupil valueForKey:@"name"], [pupil valueForKey:@"surname"]]];
    [cell.detailTextLabel setText:[pupil valueForKey:@"telephone"]];

    return cell;
}



@end

错误日志:

/Users/Lukasz/Desktop/Pupils/Pupils/PupilViewController.m:36:5: Use of undeclared identifier 'NSFetchRequest'

/Users/Lukasz/Desktop/Pupils/Pupils/PupilViewController.m:36:21: Use of undeclared identifier 'fetchRequest'

/Users/Lukasz/Desktop/Pupils/Pupils/PupilViewController.m:36:38: Use of undeclared identifier 'NSFetchRequest'

/Users/Lukasz/Desktop/Pupils/Pupils/PupilViewController.m:37:62: Use of undeclared identifier 'fetchRequest'

/Users/Lukasz/Desktop/Pupils/Pupils/PupilViewController.m:62:5: Unknown type name 'NSManagedObject'; did you mean 'NSManagedObjectModel'?

/Users/Lukasz/Desktop/Pupils/Pupils/PupilViewController.m:63:67: Receiver type 'NSManagedObjectModel' for instance message is a forward declaration

/Users/Lukasz/Desktop/Pupils/Pupils/PupilViewController.m:64:36: Receiver type 'NSManagedObjectModel' for instance message is a forward declaration

也在其他文件中:

//
//  PupilDetailViewController.m
//  Pupils
//
//  Created by Lukasz Mozdzen on 21.04.2013.
//  Copyright (c) 2013 Lukasz Mozdzen. All rights reserved.
//

#import "PupilDetailViewController.h"

@interface PupilDetailViewController ()

@end

@implementation PupilDetailViewController


- (NSManagedObjectContext *)managedObjectContext {
    NSManagedObjectContext *context = nil;
    id delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate performSelector:@selector(managedObjectContext)]) {
        context = [delegate managedObjectContext];
    }
    return context;
}




- (IBAction)cancel:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)save:(id)sender {
    NSManagedObjectContext *context = [self managedObjectContext];

    // Create a new managed object
    NSManagedObject *newPupil = [NSEntityDescription insertNewObjectForEntityForName:@"Pupil" inManagedObjectContext:context];
    [newPupil setValue:self.nameTextField.text forKey:@"name"];
    [newPupil setValue:self.surnameTextField.text forKey:@"surname"];
    [newPupil setValue:self.telephoneTextField.text forKey:@"telephone"];

    NSError *error = nil;
    // Save the object to persistent store
    if (![context save:&error]) {
        NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
    }

    [self dismissViewControllerAnimated:YES completion:nil];
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

错误日志:

/Users/Lukasz/Desktop/Pupils/PupilDetailViewController.m:38:5: Unknown type name 'NSManagedObject'; did you mean 'NSManagedObjectModel'?

/Users/Lukasz/Desktop/Pupils/PupilDetailViewController.m:38:34: Use of undeclared identifier 'NSEntityDescription'; did you mean 'kSecAttrDescription'?

/Users/Lukasz/Desktop/Pupils/PupilDetailViewController.m:38:34: Bad receiver type 'CFTypeRef' (aka 'const void *')

/Users/Lukasz/Desktop/Pupils/PupilDetailViewController.m:39:6: Receiver type 'NSManagedObjectModel' for instance message is a forward declaration

/Users/Lukasz/Desktop/Pupils/PupilDetailViewController.m:40:6: Receiver type 'NSManagedObjectModel' for instance message is a forward declaration

/Users/Lukasz/Desktop/Pupils/PupilDetailViewController.m:41:6: Receiver type 'NSManagedObjectModel' for instance message is a forward declaration

/Users/Lukasz/Desktop/Pupils/PupilDetailViewController.m:45:11: Receiver type 'NSManagedObjectContext' for instance message is a forward declaration

有人可以帮忙吗?

最佳答案

在使用之前,您需要在包中添加 coredata 框架。

如您所说,您是iPhone开发新手,建议您引用apple docs on coredata在实现之前。

关于ios - 在示例核心数据项目中出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16143427/

有关ios - 在示例核心数据项目中出错的更多相关文章

  1. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  2. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  3. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  4. ruby - Ruby 有 `Pair` 数据类型吗? - 2

    有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳

  5. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  6. ruby - 我如何添加二进制数据来遏制 POST - 2

    我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_

  7. 世界前沿3D开发引擎HOOPS全面讲解——集3D数据读取、3D图形渲染、3D数据发布于一体的全新3D应用开发工具 - 2

    无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD

  8. FOHEART H1数据手套驱动Optitrack光学动捕双手运动(Unity3D) - 2

    本教程将在Unity3D中混合Optitrack与数据手套的数据流,在人体运动的基础上,添加双手手指部分的运动。双手手背的角度仍由Optitrack提供,数据手套提供双手手指的角度。 01  客户端软件分别安装MotiveBody与MotionVenus并校准人体与数据手套。MotiveBodyMotionVenus数据手套使用、校准流程参照:https://gitee.com/foheart_1/foheart-h1-data-summary.git02  数据转发打开MotiveBody软件的Streaming,开始向Unity3D广播数据;MotionVenus中设置->选项选择Unit

  9. 使用canal同步MySQL数据到ES - 2

    文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co

  10. ruby - 安装libv8(3.11.8.13)出错,Bundler无法继续 - 2

    运行bundleinstall后出现此错误:Gem::Package::FormatError:nometadatafoundin/Users/jeanosorio/.rvm/gems/ruby-1.9.3-p286/cache/libv8-3.11.8.13-x86_64-darwin-12.gemAnerroroccurredwhileinstallinglibv8(3.11.8.13),andBundlercannotcontinue.Makesurethat`geminstalllibv8-v'3.11.8.13'`succeedsbeforebundling.我试试gemin

随机推荐