-1
@implementation Fruit{
-(void) setWeight: (int)a{
    weight=a;
}
-(void) setType:t{
    Type=t;
}
-(void) setName:n{
    name=n;
}

the error is in the 2nd line shown. i tried the show invisible spaces trick and it didnt work.

2 Answers 2

6

You've got an open bracket { next to your implementation, delete that and make sure your file ends in @end

Edit: The other problems are

  1. You're writing your setters incorrectly. You need to provide a type like you did for setWeight int, for the type and name.

  2. If you're going to make your own setters it needs to be _type = t, and _name = n

I just wrote this code and it builds without issue:

@interface Fruit : NSObject
@property (nonatomic) int weight;
@property (nonatomic, strong) NSString *type;
@property (nonatomic, strong) NSString *name;
@end


#import "Fruit.h"

@implementation Fruit
-(void) setWeight: (int)a{
    _weight=a;
}
-(void) setType:(NSString *)t{
    _type=t;
}
-(void) setName:(NSString *)n{
    _name=n;
}

@end
3
  • 1
    i already noticed that and took care of it and im still getting the error, Aug 15, 2013 at 1:34
  • Never mind, i misread this, after reading it a second time i was able to fix it. Aug 15, 2013 at 1:40
  • Be sure to accept it once you're happy with the final answer. Glad it worked.
    – Peter Foti
    Aug 15, 2013 at 1:41
1

You don't need brackets around your @implementation. Instead, you just need to put a @end after it

@implementation Fruit
...
@end
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.