【发布时间】:2010-08-20 18:18:46
【问题描述】:
我目前正在使用 Objective-C 上的实用截屏视频来帮助我使用 Objective-c 进行编程。我有 Java 和 C++ 的背景,但是我很难适应 Objective 中的所有内容(主要是因为我对语法不满意)。 以下是我收到的所有代码错误。 我也在 movie.m 类中收到警告:Wirtable atomic property 'title' 不能将合成的 setter/getter 与用户定义的 setter/getter 配对
感谢您的帮助。
我收到此错误
Current language: auto; currently objective-c
warning: Couldn't find class validation function, calling methods on uninitialized objects may deadlock your program.
Program received signal: “EXC_BAD_ACCESS”.
我通过调试器运行它,下面代码中电影的地址是红色的
main.m
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Movie *movie = [[Movie alloc] initWithTitle:@"iron man"
andRating:5
andYear:2008];
[movie play];
NSLog(@"our movie is %@", movie);
[pool drain];
return 0;}
电影.h
interface Movie : NSObject {
NSString *title;
int rating;
int year;
}
- (id)initWithTitle:(NSString *)newTitle
andRating:(int)newRating
andYear:(int) year;
@property(assign) NSString *title;
@property(assign) int rating;
@property(assign) int year;
-(void) play;
@end
电影.m
#import "Movie.h"
@implementation Movie
@synthesize title;
@synthesize rating;
@synthesize year;
-(id)initWithTitle:(NSString *)newTitle
andRating:(int)newRating
andYear:(int)newYear;
{
self = [super init];
if(nil != self){
self.title = newTitle;
self.rating = newRating;
self.year = newYear;
}
return self;
}
-(NSString *) description{
NSString *oldDescription = [super description];
return [NSString stringWithFormat: @"%@ title =%@, rating =%d year=%@",
oldDescription, self.title, self.rating, self.year];
}
- (void)setTitle:(NSString *)newTitle {
title = [newTitle capitalizedString];
}
-(void) play {
NSLog(@"Playing %@", self);
}
【问题讨论】:
标签: objective-c exc-bad-access