Chapter 7 : Objective-C Classes, Objects, and Methods

This forum contains all the assignments and questions readers may have for each chapter.

Moderator: gary.bennett

Re: Chapter 7 : Objective-C Classes, Objects, and Methods

Postby pknuckey » Thu Nov 21, 2013 12:32 pm

Iam having a problem with a line of code, can some one help me? I am running Xcode 5.0.2 Error highlighted in red.

Thank you
Paul


//
// RadioStation.m
// RadioSations
//
//

#import "RadioStation.h"

@implementation RadioStation

+ (double)minAMFrequency {
return 520.0;
}
+ (double)maxAMFrequency {
return 1610.0;
}
+ (double)minFMFrequency {
return 89.3;
}
+ (double)maxFMFrequency {
return 107.9;
}

- (id)intWithName:(NSString *)newName atFrequency:(double)newFrequency {
self = [super init]; !!!!!! cannot assign to 'self' outside of a method in the init family
if (self !=nil) {
name = newName;
frequency = newFrequency;
}

return self;
}

-(NSString *)name {
return name;
}

- (void)setName:(NSString *)newName {
name = newName;
}

- (double)frequency {
return frequency;
}

- (void)setFrequency:(double)newFrequency {
frequency = newFrequency;
}

@end
pknuckey
 
Posts: 0
Joined: Mon Jan 21, 2013 6:01 pm

Re: Chapter 7 : Objective-C Classes, Objects, and Methods

Postby Drago » Mon Jun 16, 2014 9:27 pm

pknuckey wrote:Iam having a problem with a line of code, can some one help me? I am running Xcode 5.0.2 Error highlighted in red.

Thank you
Paul


//
// RadioStation.m
// RadioSations
//
//

#import "RadioStation.h"

@implementation RadioStation

+ (double)minAMFrequency {
return 520.0;
}
+ (double)maxAMFrequency {
return 1610.0;
}
+ (double)minFMFrequency {
return 89.3;
}
+ (double)maxFMFrequency {
return 107.9;
}

- (id)intWithName:(NSString *)newName atFrequency:(double)newFrequency {
self = [super init]; !!!!!! cannot assign to 'self' outside of a method in the init family
if (self !=nil) {
name = newName;
frequency = newFrequency;
}

return self;
}

-(NSString *)name {
return name;
}

- (void)setName:(NSString *)newName {
name = newName;
}

- (double)frequency {
return frequency;
}

- (void)setFrequency:(double)newFrequency {
frequency = newFrequency;
}

@end


misspelling: - (id)intWithName:
the correct is: -(id)initWithName:
"It's more fun to be a pirate than to join the navy."
Steve Jobs.
User avatar
Drago
 
Posts: 0
Joined: Thu Jun 20, 2013 3:41 pm

Previous

Return to Book -> Objective-C for Absolute Beginners: (2nd Edition) iPhone and Mac Programming Made Easy

cron