Video Tutorial: Objective-C Classes and Methods

Learn the syntax to create Objective-C classes and methods, through a short and fun example. By Ray Wenderlich.

Leave a rating/review
Save for later
Share

Contents

Hide contents

Video Tutorial: Objective-C Classes and Methods

0 mins

Challenge

Your challenge is to implement a class called TemperatureConverter that has a single method called degreesFarenheitToCelsius. It should take a float as a parameter that represents the degrees in farenheit, and return a float that represents the degrees in celsius.

Add this code to your App Delegate to test it:

#import "AppDelegate.h"
#import "TemperatureConverter.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    float degreesFarenheit = 80.0;

    TemperatureConverter *converter = [[TemperatureConverter alloc] init];
    float degreesCelsius = [converter degreesFarenheitToCelsius:degreesFarenheit];
    
    NSLog(@"%0.2f degrees farenheit = %0.2f degrees celsius",
        degreesFarenheit, degreesCelsius);
    
    return YES;
}

@end

Download demo code

Download solution

Helpful links

Contributors

Over 300 content creators. Join our team.