不可接受的属性值类型:property [英] Unacceptable type of value for attribute: property

查看:63
本文介绍了不可接受的属性值类型:property的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Core Data 创建了我的应用程序,声明了 2 个属性,SongLyrics 和 MovieSongName,两者都是字符串.然后在 xib 中,我为 MovieSongName 创建了一个文本字段,并为 SongLyrics 创建了一个文本视图.为了存储这些,我使用了以下代码

I created my app using Core Data, declared 2 attributes, SongLyrics and MovieSongName, both as string. Then in xib I created a text field for MovieSongName and a text view for SongLyrics. For storing these I used the following code

-(void)saveData
{
    LyricsAppDelegate *appDelegate = [[UIApplication sharedApplication] 
                                  delegate];

    NSManagedObjectContext *managedObjectContext = [appDelegate managedObjectContext];
    NSEntityDescription *entityDesc = [NSEntityDescription    
                                       entityForName:@"Lyrics"        
                              inManagedObjectContext:managedObjectContext];
    NSManagedObject *LyricsObjectEnglish;
    LyricsObjectEnglish = [NSEntityDescription    
                           insertNewObjectForEntityForName:@"English_Songs"   
                                    inManagedObjectContext:managedObjectContext];
   [LyricsObjectEnglish setValue:song_lyrics.text forKey:@"SongLyrics"];
   [LyricsObjectEnglish setValue:song_name forKey:@"MovieSongName"];

   song_lyrics.text=@"";
   song_name.text=@"";
   NSError *error; 
   [managedObjectContext save:&error];
}

点击保存按钮时,应用程序因以下错误而中止.

when clicking on the save button app gets aborted with the following error.

2012-01-27 10:50:52.071 Lyrics[4624:207] * 由于未捕获的异常NSInvalidArgumentException"而终止应用程序,原因:不可接受的属性值类型:property ="电影歌曲名称";所需类型 = NSString;给定类型 = UITextField;值 = >.'

2012-01-27 10:50:52.071 Lyrics[4624:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "MovieSongName"; desired type = NSString; given type = UITextField; value = >.'

谁能帮帮我?我是第一次使用 Core Data,有点困惑.

Can any one help me? I'm using Core Data for the first time and I'm a little confused.

推荐答案

该错误准确地告诉您问题是什么.具体来说,MovieSongName 需要一个 NSString 值,但是你给它的值是一个 UITextField 因为你试图给它 song_name 而不是 song_name.text.

The error is telling you exactly what the problem is. Specifically, MovieSongName needs an NSString value, but the value you are giving it is a UITextField because you are trying to give it song_name rather than song_name.text.

正确的代码是:

[LyricsObjectEnglish setValue:song_name.text forKey:@"MovieSongName"];

这篇关于不可接受的属性值类型:property的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆