Paxton
Paxton

Reputation: 11

Incomplete implementation of my class?

//
//  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;
}

at line 14 and 19 it's giving me "incomplete implementation of possesion" and Expected '{' before 'valueindollars, respectfully. Any help?? new to cocoa

Upvotes: 1

Views: 1362

Answers (2)

Jens Ayton
Jens Ayton

Reputation: 14558

You have two @end directives. Neither is in the right place. They should be at – suprise – the end of your implementation block.

In this method signature, remove the semicolon (and preferably the blank lines):

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

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

This error is confusing Jacob Relkin and Adam Eberbach, causing them to try to fix things that aren’t actually there.

In the convenience initializers - (id)initWithPossessionName:(NSString *)name and -init, you’re calling a method that doesn’t exist – there are several typos in the selector you’re calling in one, and some capitalization problems in the one you’d actually be defining if it weren’t for the extra semicolon.

Upvotes: 2

user189804
user189804

Reputation:

Jacob is right. Also you should do

@interface Possession (private)

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

@end

before your implementation block. Method declarations can't appear in an implementation; they must go in the interface. Your function prototypes are being advertised to your class only so they are in that sense private. But private isn't a special name here, you could say

@interface Possession (frobozz)

if you wanted. Just not

@interface Possession

because that would duplicate the interface definition that is probably in your .h file. So the whole thing must look like

@import "Possession.h"
// public prototypes, properties, ivars etc. in the .h file 

@interface Possession (private)
// prototypes here
@end

@implementation Possession

// all your code here

@end

// end is the last thing in the file

Upvotes: 0

Related Questions