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:
- How do I get rid of the warning above?
- 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