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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:34:59+00:00 2026-05-27T18:34:59+00:00

After programming with C# and Java for many years I finally decided to learn

  • 0

After programming with C# and Java for many years I finally decided to learn Objective-C in order to start programming iOS Devices as well as Mac OS X, and I have to admit it is very different then most modern c-based programming languages. I am getting the following warning in my code:

warning: passing argument 1 of ‘SetAge’ makes pointer from integer without a cast

Here is my code:

Dog.h

#import <Cocoa/Cocoa.h>


@interface Dog : NSObject {
    int ciAge;
    NSString * csName;
}

- (void) Bark;
- (void) SetAge: (int *) liAge;
- (void) SetName: (NSString *) lsName;

@end

Dog.m

#import "Dog.h"

@implementation Dog

- (void) Bark
{
    NSLog(@"The dog %@ barks with age %d", csName, ciAge);  
}

- (void) SetAge: (int *) liAge {
    ciAge = (int)liAge;
}

- (void) SetName: (NSString *) lsName {
    csName = lsName;
}
@end

HelloWorld.m

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


int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    int liTemp = 75;
    NSString * lsCity = @"Chicago";
    NSDate * loDate = [NSDate date];

    // insert code here...
    NSLog(@"The temperature is %d currently in %@, on %@", liTemp, lsCity, loDate);

    int liAge = 10;

    // Call Dog class
    Dog * Dog1 = [Dog new];
    [Dog1 SetAge:(int)liAge]; // The Warning happens here
    [Dog1 SetName:@"Fido"];

    [Dog1 Bark];


    [pool drain];
    return 0;
}

My Questions Are:

  1. How do I get rid of the warning above?
  2. Instead of creating methods in the Dog Class for setting Age and Name, how could I have make Age and Name public class level variables that I could directly assign to?

Any help would be much appreciated!

Thanks,
Pete

  • 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-27T18:34:59+00:00Added an answer on May 27, 2026 at 6:34 pm

    Don’t declare an int as a pointer. Change your code from:

    - (void) SetAge: (int *) liAge
    

    to

    - (void) SetAge: (int) liAge
    

    and

    - (void) SetAge: (int *) liAge {
        ciAge = (int)liAge;
    }
    

    to

    - (void) SetAge: (int) liAge {
        ciAge = liAge;
    }
    

    Consider making age and name a property. Change:

    - (void) SetAge: (int *) liAge;
    - (void) SetName: (NSString *) lsName;
    

    to

    @property (nonatomic, readwrite) NSInteger age; //Don't declare as pointer
    @property (nonatomic, retain) NSString *name; //DO declare as pointer
    

    Also, don’t forget to synthesize them in your implementation file:

    @synthesize age, name;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After five years of professional Java (and to a lesser extent, Python) programming and
I'm working with someone who's looking to get back into programming after several years
I'm in an introductory comp-sci class (after doing web programming for years) and became
After years in embedded programming, I have to develop a Windows app. I dug
After spending three weeks learning Objective-C and Cocoa programming for my work, I've been
after some years in Java and C# now I'm back to C++. Of course
After years of programming, we all have a set of small functions used as
I've learned programming from Java, then tried to learn one programming language per year,
After some research, it seems like I would have to start by programming an
I'm new to Windows programming and after reading the Petzold book I wonder: is

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.