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

  • Home
  • SEARCH
  • 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 6577545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:39:01+00:00 2026-05-25T15:39:01+00:00

I’m trying to run through all the Objective C I possibly can as fast

  • 0

I’m trying to run through all the Objective C I possibly can as fast as I can for my new job. I’ve divided up my training so I do 1/2 with cocoa tutorials and I thought it also made sense to try to learn Objective C from a general perspective as well so the other 50% i’m trying to learn out of the “Programming In Objective C” book by Stephan Kochan (2004). Many of his examples up through the first 50 pages or so seem to imply that there is a way to make a simple class (interface, implementation, and main) all in the same file. I have been trying to compile this in the mac Snowleopard terminal for the sake of speed, but as soon as I call a method inside the main I get compile errors.

I know its not my gcc compiler because the file will compile, and I can even write a printf statement, but as soon as I try to call a method, I get compile errors. I would appreciate it if someone could demonstrate a simple inclusive objectivec.m file that actually works with a method call.

here’s my code

#import <stdio.h>
#import <objc/Object.h>

@interface testing1 : Object
{
int number;
}

-(void) setNum:(int)a;
-(void) print;
@end

@implementation testing1;
-(void) setNum:(int) a{
number = a;
}


-(void) print{

printf("this is the number %i \n", number);

}

@end

int main(int argc, char* argv[] )
{
//testing1 *test =[testing1 new];
//[test setNum: (int)34];
printf("testing");
//[test print];
}

this will compile in the terminal with — gcc tester1 -o myProg -l objc
I’ve tried to call those methods several different ways but it does not work

any help is appreciated. Perhaps I need to break it up and use make – I don’t know
Thanks
MIke

  • 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-25T15:39:02+00:00Added an answer on May 25, 2026 at 3:39 pm

    You have ; at the end of @implementation –

    @implementation testing1;  // Semi colon shouldn't be present at the end
    

    With that modification made, you should see the result. Online result of the program

    [test setNum: (int)34];
    

    Here typecasting 34 to int is unnecessary. You can just pass the message setNum to reference test with 34 followed by colon.

    [test setNum:34 ];
    

    Interface declarations should go in header while the implementation to source files. Only source files get compiled. Before even the compilation phase, pre-processor just copies the content of all imported files to the translation units. So,

    testing.h

    #import <Foundation/NSObject.h>
    @interface testing1 : NSObject
    {
        int number;
    }
    
    -(void) setNum:(int)a;
    -(void) print;
    @end
    

    testing.m

    #import <stdio.h>
    #import "testing.h"
    
    // You should definitely import just stdio.h header here because of printf function usage
    // testing.h also to be imported or else compiler doesn't know what is testing1.
    
    @implementation testing1
    -(void) setNum:(int) a{
        number = a;
    }
    -(void) print{    
        printf("this is the number %i \n", number);
    }
    @end
    

    main.m

    #import <stdio.h>
    #import "testing.h"
    
    int main(int argc, char* argv[] )
    {
        testing1 *test =[testing1 new]; 
        [test setNum: 34];
        printf("testing");
        [test print];
    
         return 0;
    }
    

    Now you need to compile the two source files from which corresponding object files are generated. Linker combines these object files to give the final executable.

    gcc -o test testing.m main.m -framework Foundation
    

    Run –

    ./test
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to loop through a bunch of documents I have to put
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a text area in my form which accepts all possible characters from

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.