Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Object-Oriented Objective-C Diving Deeper - Classes, Properties and Methods Creating Methods!

YAO GANG
YAO GANG
3,330 Points

How can I write a method in one page to pass this code challenge? I write this method in one Cococlass and main.m

calculate.h

import <Foundation/Foundation.h>

@interface calculateTip : NSObject

@property (nonatomic) float subtotal;

  • (void)multiply;

@end

calculate.m

import "calculateTip.h"

@implementation calculateTip

  • (void)multiply{

    self.subtotal = self.subtotal * 0.2;

}

@end

main.m

import <Foundation/Foundation.h>

import "calculateTip.h"

calculateTip *result = [[calculateTip alloc]init]; [result multiply];

variable_assignment.mm
#calculate.h
#import <Foundation/Foundation.h>

@interface calculateTip : NSObject

@property (nonatomic) float subtotal;


- (void)multiply;


@end


#calculate.m
#import "calculateTip.h"

@implementation calculateTip

- (void)multiply{

    self.subtotal = self.subtotal * 0.2;

}



@end


#main.m  
#import <Foundation/Foundation.h>
#import "calculateTip.h"
calculateTip *result = [[calculateTip alloc]init];
[result multiply];

1 Answer

Andres Aguero
Andres Aguero
30,545 Points

Hi there,

You need to specify the return type as float not as void.

-(float) calculateTip: (float) subtotal {
  return subtotal * .2; 
}

Then you need to copy the method signature into the interface/header file to be able to use it on other files like this.

-(float) calculateTip: (float) subtotal;
YAO GANG
YAO GANG
3,330 Points

yes. Thanks a lot