gpt4 book ai didi

iphone - 我的类(class)实现不完整?

转载 作者:行者123 更新时间:2023-12-03 17:07:04 25 4
gpt4 key购买 nike

//
// Possession.m
// RandomPossessions
//
// Created by Paxton Harman on 1/14/11.
// Copyright 2011 Santa Barbara City College. All rights reserved.
//

#import "Possession.h"


@implementation Possession
@synthesize possessionName, serialNumber, valueInDollars, dateCreated;
@end

- (id)initWithPossessionName:(NSString *)name;


valueindollars:(int)value
serialNumber:(NSString *)sNumber
{
// Call the superclass's designated initializer
self = [super init];
// Did the superclass's designated initializer fail?
if (!self)
return nil;

// Give the instance variables initial values
[self setPossessionsName:name];
[self setSerialNumber:sNumber];
[self setValueInDollars:value];
dateCreated = [[NSDate alloc] init];

// Return the address of the newly initialized object
return self;

}
- (id)initWithPossessionName:(NSString *)name
{
return [self initWithossessionName:name
valueInDollars:0
serialnNumber:@""];
}
@end

- (NSString *)description {

NSString *descriptionString =
[[NSString alloc] initWithFormat:@"%@ (%@): Worth $%d, Recorded on %@",
possessionName,
serialNumber,
valueInDollars,
dateCreated];
return descriptionString;
}

- (id)init {
return [self initWithPossessionName:@"Possession"
valueInDollars:0
serialNumber:@""];
}

+(id)randomPossesion {

// Create two arrays with a list of possible adjectives and nouns
// Note: When using NSArray's arrayWithObjects;, you can pass as many
// objects as you like. At the end of that list, you put nil to
// signify that there are no more objects - otherwise you will crash.
// The nil value is not added to the array, but it used by the method
// to determine the end of the list.
NSArray *randomAdjectiveList = [NSArray array WithObjects:@"Fluffy",
@"Rusty",
@"Shiny", nil];
NSArray *randomNounList = [NSArray arrayWithObjects:@"Bear",
@"Spork",
@"Mac", nil];

// Get the index of random adjective/noun from the lists
// Note: The % operator, called the modulo operator, gives
// you the remainder. So adjectiveIndex is a random number
// from 0 to 2 inclusive, in this case.
int adjectiveIndex = random() % [randomAdjectiveList count];
int nounIndex = random() % [randomNounList count];

NSString *randomName = [NSString stringWithFormat:@"%@ %@",
[randomAdjectiveList objectAtIndex:adjectiveIndex],
[randomNounList objectAtIndex:nounIndex]];

int randomValue = random() % 100;

NSString *randomSerialNumber = [NSString stringWithFormat:@"%c%c%c%c%c",
'0' + random() % 10,
'A' + random() % 26,
'0' + random() % 10,
'A' + random() % 26,
'0' + random() % 10];

// Once again, ignore the memory problems with this method
// We use "self" instead of the name of the class in class methods...
// Keep reading to find out why
Possession *newPossesion =
[[self alloc] initWithPossessionName:randomName
valueInDollars:randomValue
serialNumber:randomSerialNumber];
return newPossession;
}

在第 14 行和第 19 行,它给了我“不完整的占有实现”和预期的“{”在“valueindollars”之前,恭敬地。有什么帮助吗? cocoa 新手

最佳答案

您有两个@end指令。两者都不在正确的位置。令人惊讶的是,它们应该位于实现 block 的末尾。

在此方法签名中,删除分号(最好是空行):

- (id)initWithPossessionName:(NSString *)name;

valueindollars:(int)value
serialNumber:(NSString *)sNumber

这个错误让 Jacob Relkin 和 Adam Eberbach 感到困惑,导致他们尝试修复实际上不存在的东西。

在便利初始化器 - (id)initWithPossessionName:(NSString *)name-init 中,您正在调用一个不存在的方法 - 有您调用的选择器中存在一些拼写错误,如果没有额外的分号,您实际定义的选择器中也会出现一些大写问题。

关于iphone - 我的类(class)实现不完整?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4766657/

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