Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-10-2010, 09:54 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 7
nexus is on a distinguished road
Default Issues with data type.

Hey all,

I'm trying to develop a setAgeWithInt method in my .m file but keep getting a warning: Assingment makes integer from pointer without a cast. I know this is a data type issue.

Here is my .h:

Code:
@interface Dog : NSObject {				
	
	NSString *name;
	NSString *breed;
	int age;
}

- (void) bark;
- (void) setName: (NSString *) n;		
- (void) setBreed: (NSString *)b;
- (void) setAgeWithInt: (int *)x;

@end
Here is my .m:
Code:
#import "Dog.h"

@implementation Dog

- (void) bark { 
	
	NSLog(@"Woof, says %@. She is a %@ and she is %d years old.", name, breed, age);	//	%d is used for integer values.

}

- (void) setName:(NSString *)n	{ 
	
	name = n;
}

- (void) setBreed:(NSString *)b	{ 
	
	breed = b;

}

- (void) setAgeWithInt:(int *)x {
	
	age = x;
	
}
Also, I'd like to create a setAge method that allows me to use float values. In the bark method, using %d, i'd like that to display the age whether it is int or float. Is this possible?

Thank you

Last edited by nexus; 04-10-2010 at 10:02 PM.
nexus is offline   Reply With Quote
Old 04-10-2010, 11:22 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 7
nexus is on a distinguished road
Default

Ok, I fixed the warning.

Now setAgeWithInt method declaration in my .h looks like:

Code:
- (void) setAgeWithInt: (int)x;
My method code in my .m looks like:

Code:
- (void) setAgeWithInt:(int)x {
	
	age = x;
	
}
but I would l still like a way to get the bark method to display age whether it's a float or an int.
nexus is offline   Reply With Quote
Old 04-11-2010, 05:22 AM   #3 (permalink)
Maker of Games
 
Mr Jack's Avatar
 
Join Date: Nov 2009
Location: Coventry, UK
Posts: 395
Mr Jack is on a distinguished road
Default

Quote:
Originally Posted by nexus View Post
but I would l still like a way to get the bark method to display age whether it's a float or an int.
You could do in a messy fashion by storing a flag based on which you're storing, but it's not a great way of doing it. It's up to you to decide how you want to store such things and then display accordingly. Personally, I wouldn't ever store an age: instead store the Date of Birth and calculate the age from the current date. You can then decide how you wish to display the age accordingly - for example you might want to show number of days if they're under 31 days, weeks up to three months, months up to a year and whole years thereafter.
__________________


Visit Mr Jack Games for my blog and more about my games
Mr Jack is offline   Reply With Quote
Old 04-12-2010, 11:55 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 7
nexus is on a distinguished road
Default

Thank you Jack, that's a great way to do the age. Any hand7 scripts for calculating an age from a given date?
nexus is offline   Reply With Quote
Old 04-13-2010, 07:00 AM   #5 (permalink)
Maker of Games
 
Mr Jack's Avatar
 
Join Date: Nov 2009
Location: Coventry, UK
Posts: 395
Mr Jack is on a distinguished road
Default

I'm not familiar with the Objective-C date classes; have a look at the documentation for NSDate.
__________________


Visit Mr Jack Games for my blog and more about my games
Mr Jack is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 464
14 members and 450 guests
7twenty7, AlanFloyd, David-T, imac74, Jaxen66, logan, lovoyl, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0