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 iOS Design Patterns Two-Stage Object Creation Test: Two-stage Object Creation

"Your factory method needs to take a ColoredCircle pointer", can someone show me how to complete this task?

We need a ColoredCircle factory method named "asteroid" which has color "grey" and a diameter of 1.5. Start by writing the declaration for this class method.

I am not familiar to iOS Design Patterns, and the video lecture so far did not explain clearly on how to complete this task, need somebody to walk me through with this assignment.

asteroid.h
# import "ColorCircle.h"

@implementation ColoredCircle
+(asteroid) init {
  return [self initWithDiameter:1.5  andColor:@"grey"];
}

+(asteroid)  initWithDiameter:(float)d andColor: (NSString *)c {
    self = [super iniWithDiameter:d];
    .f (self) {
        self.color = c;
    }
    return self;
}

@end
asteroid.m
//
// ColoredCircle.m
// Alloc_Init_vid3
//
//

#import "ColoredCircle.h"

@implementation ColoredCircle

+(asteroid) init {
   return [initWith Diameter: 1.5 and Color:@"grey"];
}

@end
Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

I really recommend doing the Objective-C basics course first before diving into iOS design patterns, which is an intermediate course. Please don't get me wrong, I am only trying to help here.

3 Answers

Evgeny Mitko
Evgeny Mitko
13,578 Points

The answer is:

asteroid.h

#import <Foundation/Foundation.h>
#import "ColorCircle.h"

@interface asteroid : NSObject

+(ColoredCircle *) asteroid;


@end

and asteroid.m (Moderator edited: for typo from "asteroid.h to asteroid.m)

//
// ColoredCircle.m
// Alloc_Init_vid3
//
//

#import "asteroid.h"

@implementation asteroid

+(ColoredCircle*) asteroid {
  ColoredCircle*asteroid = [[ColoredCircle alloc] initWithDiameter: 1.5 andColor: @"grey"];
}

@end
Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

The + (ColoredCircle *) asteroid method is missing the return statement, as far as I can tell. Can you confirm?

Chris Adamson
Chris Adamson
132,143 Points

If you watch the power and flexibility lesson, the solution to the first part is at the bottom:

+(ColoredCircle*) asteroid;

hello guys how you guys can answer the second part of this method I am stock and do not know how to do it! By calling the designated initializer, code the implementation for the asteroid class method.