gpt4 book ai didi

iphone - 编码解码类错误的 int 属性

转载 作者:行者123 更新时间:2023-11-29 04:31:18 24 4
gpt4 key购买 nike

@interface Esame : NSObject{
NSString *nome;
int voto;
int crediti;
int anno;
}

@property (nonatomic, retain) NSString *nome;


- (id)initWithNome:(NSString*)nome voto:(int)voto crediti:(int)crediti anno:(int)anno;

@end

这是我的实现

#import "Esame.h"

@implementation Esame

@synthesize nome;


- (id)initWithNome:(NSString*)name voto:(int)voto crediti:(int)crediti anno:(int)anno {
if ((self = [super init])) {
self.nome = name;



}
return self;
}

- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {

nome = [decoder decodeObjectForKey:@"nome"] ;
voto = [decoder decodeIntForKey:@"voto"];
crediti = [decoder decodeIntForKey:@"crediti"];
anno = [decoder decodeIntForKey:@"anno"];

}
return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder {

if (nome) [encoder encodeObject:nome forKey:@"nome"];

if (voto) [encoder encodeInt:voto forKey:@"voto"];
if (crediti) [encoder encodeInt:crediti forKey:@"crediti"];
if (anno) [encoder encodeInt:anno forKey:@"anno"];

}


@end

我收到同样奇怪的错误...特别是在 NSString 中...出了什么问题?

最佳答案

尝试在 encodeInt: 之前删除条件语句;您可能应该始终对所有成员进行编码。另外,您可能应该声明您符合 NSCoding @interface Esame : NSObject<NSCoding> .

如果这不起作用,请尝试发布您看到的错误消息。

关于iphone - 编码解码类错误的 int 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11709767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com