Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:51:12+00:00 2026-05-31T09:51:12+00:00

I am currently learning Objective-C. I have created a class to hold information about

  • 0

I am currently learning Objective-C. I have created a class to hold information about cars (BasicCar). Also created a child class to hold the car’s color and amount of doors (ExtendedCar). All properties are text (NSString) except for the amount of doors, which is of type int.

My parent class:

#import <Foundation/Foundation.h>
#import <cocoa/cocoa.h>

@interface BasicCar : NSObject {

NSString *make;
NSString *model;

}

@property (readwrite, retain) NSString* make;
@property (readwrite, retain) NSString* model;


@end

#import "BasicCar.h"

@implementation BasicCar

@synthesize make;
@synthesize model;

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }

    return self;
}


@end

My child class:

#import <Foundation/Foundation.h>
#import <cocoa/cocoa.h>
#import "BasicCar.h"

@interface ExtendedCar : BasicCar {

NSString* color;
int doors;

}

@property (readwrite,retain) NSString* color;
@property (readwrite) int doors;

@end


#import "ExtendedCar.h"

@implementation ExtendedCar : BasicCar

@synthesize color;
@synthesize doors;


@end

My main code:

#import <Foundation/Foundation.h>
#import "BasicCar.h"
#import "ExtendedCar.h"

int main (int argc, const char * argv[])
{


ExtendedCar *myCar1 = [[ExtendedCar alloc]init];
NSString *carMake = @"BMW";
NSString *carModel = @"M5";
NSString *carColor = @"blue";
int carDoors = 4;

[myCar1 setMake:carMake];
[myCar1 setModel:carModel];
[myCar1 setColor:carColor];
[myCar1 setDoors:carDoors];



ExtendedCar *myCar2 = [[ExtendedCar alloc]init];
carMake = @"Hummer";
carModel = @"H3";
carColor = @"green";
carDoors = 4;

[myCar2 setMake:carMake];
[myCar2 setModel:carModel];
[myCar2 setColor:carColor];
[myCar2 setDoors:carDoors];


NSLog(@"Make: %@, Model: %@, Color: %@, Doors: %@ \n\n",[myCar1 make],[myCar1 model],[myCar1 color], [myCar1 doors]);

NSLog(@"Make: %@, Model: %@, Color: %@, Doors: %@ \n\n",[myCar2 make],[myCar2 model], [myCar2 color], [myCar2 doors]);


return 0;
}

Now when I debug it, I get an EXC_BAD_ACCESS error in Xcode at this line:

NSLog(@"Make: %@, Model: %@, Color: %@, Doors: %@ \n\n",[myCar1 make],[myCar1 model],[myCar1 color], [myCar1 doors]);

Why is this happening and what can I do to fix this? It does not happen when I remove the ‘doors’ part, so it has to do something with the ‘int’ data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:51:13+00:00Added an answer on May 31, 2026 at 9:51 am

    As Jeremy said in a comment, you’re using the wrong format specifier. %@ is the format specifier for obj-c objects. This is correct for make, model, and color, but it’s not correct for doors because that’s a C primitive datatype (int). The correct format specifier for ints is %i (or %d).

    NSLog(@"Make: %@, Model: %@, Color: %@, Doors: %d \n\n",[myCar1 make],[myCar1 model],[myCar1 color], [myCar1 doors]);
    
    NSLog(@"Make: %@, Model: %@, Color: %@, Doors: %d \n\n",[myCar2 make],[myCar2 model], [myCar2 color], [myCar2 doors]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently learning objective-c. I have heard (and experienced) that the best way to
I currently learning about scrum and want to learn from experienced professionals in the
im currently learning python (in the very begining), so I still have some doubts
im currently learning stacks in java and have a quick question. what will the
I am currently learning Perl. I have Perl hash that contains references to hashes
Hi I'm currently learning Ruby On Rails and I have a little mistake. I
I'm currently learning (by doing) objective-c by implementing a feature I felt is missing
I've currently been learning Objective-C and Cocoa for some time but I feel that
Currently learning Scheme/Racket and have problem running this piece of code. (if (or (<
I am currently learning regex but need this quite urgently. I have a set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.