//
//  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行,敬请原谅。有帮助吗?可可新手

最佳答案

您有两个@end指令。两者都不在正确的地方。它们应该处于–惊奇–实现块的末尾。

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

- (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/

10-10 21:06