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 5988049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:54:14+00:00 2026-05-22T22:54:14+00:00

Help please! my first program in objective c. Followed a tutorial word for word

  • 0

Help please! my first program in objective c. Followed a tutorial word for word but it gives me this error that I don’t know quite how to read for objective c.

SimpleCar.h:

#import <Cocoa/Cocoa.h>


@interface SimpleCar : NSObject {
    NSString* make;
    NSString* model;
    NSNumber* vin;
}

// set methods
- (void) setVin:   (NSNumber*)newVin;
- (void) setMake:  (NSString*)newMake;
- (void) setModel: (NSString*)newModel;

// convenience method
- (void) setMake: (NSString*)newMake
        andModel: (NSString*)newModel;

// get methods
- (NSString*) make;
- (NSString*) model;
- (NSNumber*) vin;

@end

SimpleCar.m:

#import "SimpleCar.h"


@implementation SimpleCar
// set methods
- (void) setVin: (NSNumber*)newVin {

    [vin release];
    vin = [[NSNumber alloc] init];
    vin = newVin;

}

- (void) setMake: (NSString*)newMake {

    [make release];
    make = [[NSString alloc] initWithString:newMake];

}

- (void) setModel: (NSString*)newModel {

    [model release];
    model = [[NSString alloc] initWithString:newModel];

}

// convenience method
- (void) setMake: (NSString*)newMake
        andModel: (NSString*)newModel {

    // Reuse our methods from earlier
    [self setMake:newMake];
    [self setModel:newModel];

}

- (NSString*) make {
    return make;
}

- (NSString*) model {
    return model;
}

- (NSNumber*) vin {
    return vin;
}

-(void) dealloc
{
    [vin release];
    [make release];
    [model release];
    [super dealloc];
}

@end

CarApp.m:

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

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

  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    SimpleCar *myCar = [[SimpleCar alloc] init];

    NSNumber *newVin = [NSNumber numberWithInt:123];

    [myCar setVin:newVin];
    [myCar setMake:@"Honda" andModel:@"Civic"];

    NSLog(@"The car is: %@ %@", [myCar make], [myCar model]);
    NSLog(@"The vin is: %@", [myCar vin]);

    [myCar release];

  [pool drain];

  return 0;
}

compiler call:

bash-3.2$ gcc CarApp.m SimpleCar.m -g -m64

error:

Undefined symbols for architecture x86_64:
  "___CFConstantStringClassReference", referenced from:
      CFString in ccR0Zlgm.o
      CFString in ccR0Zlgm.o
      CFString in ccR0Zlgm.o
      CFString in ccR0Zlgm.o
  "_objc_msgSend", referenced from:
      _main in ccR0Zlgm.o
      -[SimpleCar setVin:] in ccJfVliU.o
      -[SimpleCar setMake:] in ccJfVliU.o
      -[SimpleCar setModel:] in ccJfVliU.o
      -[SimpleCar setMake:andModel:] in ccJfVliU.o
     (maybe you meant: l_objc_msgSend_fixup_release, l_objc_msgSend_fixup_alloc )
  "_NSLog", referenced from:
      _main in ccR0Zlgm.o
  "_objc_msgSend_fixup", referenced from:
      l_objc_msgSend_fixup_alloc in ccR0Zlgm.o
      l_objc_msgSend_fixup_release in ccR0Zlgm.o
      l_objc_msgSend_fixup_release in ccJfVliU.o
      l_objc_msgSend_fixup_alloc in ccJfVliU.o
     (maybe you meant: l_objc_msgSend_fixup_release, l_objc_msgSend_fixup_alloc )
  "_OBJC_CLASS_$_NSAutoreleasePool", referenced from:
      objc-class-ref in ccR0Zlgm.o
  "_OBJC_CLASS_$_NSNumber", referenced from:
      objc-class-ref in ccR0Zlgm.o
      objc-class-ref in ccJfVliU.o
  "_objc_msgSendSuper2", referenced from:
      -[SimpleCar dealloc] in ccJfVliU.o
  "_OBJC_METACLASS_$_NSObject", referenced from:
      _OBJC_METACLASS_$_SimpleCar in ccJfVliU.o
  "__objc_empty_cache", referenced from:
      _OBJC_METACLASS_$_SimpleCar in ccJfVliU.o
      _OBJC_CLASS_$_SimpleCar in ccJfVliU.o
  "__objc_empty_vtable", referenced from:
      _OBJC_METACLASS_$_SimpleCar in ccJfVliU.o
      _OBJC_CLASS_$_SimpleCar in ccJfVliU.o
  "_OBJC_CLASS_$_NSObject", referenced from:
      _OBJC_CLASS_$_SimpleCar in ccJfVliU.o
  "_OBJC_CLASS_$_NSString", referenced from:
      objc-class-ref in ccJfVliU.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
  • 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-22T22:54:15+00:00Added an answer on May 22, 2026 at 10:54 pm

    It looks like you just created an Xcode Workspace without an Xcode project. Here’s a project that you could use:

    http://www.markdouma.com/developer/CarApp.zip

    Generally, you just choose File > New Project to create a new project. You’d likely want a Foundation-based command-line program for this particular project.

    Unfortunately, the tutorial didn’t give the best implementation of the SimpleCar class. Below is one possible rewrite:

    #import "SimpleCar.h"
    
    @implementation SimpleCar
    
    -(void) dealloc
    {
        [vin release];
        [make release];
        [model release];
        [super dealloc];
    }
    
    
    // set methods
    - (void) setVin: (NSNumber*)newVin {
        [newVin retain];
        [vin release];
        vin = newVin;
    //    [vin release];
    //    vin = [[NSNumber alloc] init];
    //    vin = newVin;
    }
    

    The commented code above is the original code. It is both potentially dangerous and also leaks memory. The first line of the original code releases vin before doing anything else, which is potentially dangerous. For example, what if in your CarApp.m you did this:

    NSNumber *vinValue = [car vin];
    [car setVin:vin];
    NSLog(@"car's vin == %@", [car vin]); // unpredictable results/crash
    

    The original code would have released the existing vin value without bothering to make sure the value being passed in wasn’t actually vin itself. By setting vin = newVin, it was setting vin to point to itself but after being released. Any subsequent attempts to send messages to vin would result in a crash or unpredictable results.

    The original code also leaks memory. Instances of NSNumber are immutable, so creating a number through alloc/init doesn’t really make much sense (since it will always be zero, and can never be changed). My replacement code first retains the value that is passed in, in case it happens to be vin. It then releases vin and then assigns vin to newVin.

    The setMake: and setModel: methods are problematic for the same reasons.

    - (void) setMake: (NSString*)newMake {
        [newMake retain];
        [make release];
        make = newMake;
    //    [make release];
    //    make = [[NSString alloc] initWithString:newMake];
    }
    
    - (void) setModel: (NSString*)newModel {
        [newModel retain];
        [model release];
        model = newModel;
    //    [model release];
    //    model = [[NSString alloc] initWithString:newModel];
    }
    
    // convenience method
    - (void) setMake: (NSString*)newMake
            andModel: (NSString*)newModel {
        // Reuse our methods from earlier
        [self setMake:newMake];
        [self setModel:newModel];
    }
    
    - (NSString*) make {
        return make;
    }
    - (NSString*) model {
        return model;
    }
    - (NSNumber*) vin {
        return vin;
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Guys could you please help me refactor this so that it is sensibly
first of all please let me say that I am quite new to objective
Please help! I'm really at my wits' end. My program is a little personal
Please help me convert this line to C#. objManagementBaseObject.SetPropertyValue(hDefKey, CType(&H & Hex(RegistryHive.LocalMachine), Long)) Related
Please help me with a spellcheck program in C. The majority of the coding
This is the first time i am working with Lists and I don't seem
I have to write program that create process using pipe() . My first task
I pretty much have this solved but for some reason the first If statement
I am getting a little confused and need some help please. Take these two
Please help! Background info I have a WPF application which accesses a SQL Server

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.