Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
I'm working on a framework, mostly for learning but partly because I had something I want to be able to use, but I realized I don't really know how to make methods. I've used various kinds, but I don't really know what anything is or how to make one with multiple values etc..
First, what's the difference between (id) and (void)? I know that part of the method specifies what kind of object is accepted when the method is called, but I don't see the difference between those two.

Now for the real question. Here's how I want my currently fictional method:

- (void)animateIntValueTo:_____ atSpeed:_____ {

}

What goes in those blanks? I know in the documentation, it would do something like: (int)anInt or (NSNumber *)aNumber but doing either of those gave me an error, something like 'NSNumber has already been defined' or something like that. Do I need to put variables/objects declared in my header in the blank spaces? If not, how do I get the values the user puts in the slots?
Thanks in advance,
Nate
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
I'm working on a framework, mostly for learning but partly because I had something I want to be able to use, but I realized I don't really know how to make methods. I've used various kinds, but I don't really know what anything is or how to make one with multiple values etc..
First, what's the difference between (id) and (void)? I know that part of the method specifies what kind of object is accepted when the method is called, but I don't see the difference between those two.

Now for the real question. Here's how I want my currently fictional method:

- (void)animateIntValueTo:_____ atSpeed:_____ {

}

What goes in those blanks? I know in the documentation, it would do something like: (int)anInt or (NSNumber *)aNumber but doing either of those gave me an error, something like 'NSNumber has already been defined' or something like that. Do I need to put variables/objects declared in my header in the blank spaces? If not, how do I get the values the user puts in the slots?
Thanks in advance,
Nate

Basically they are just telling you what types the method accepts.

Interface

Code:
-(void) animateIntValueTo:(int)myInt :atSpeed:(float)myFloat;

Implementation

Code:
-(void) animateIntValueTo:(int)myInt :atSpeed:(float)myFloat
{
	
}

Edit : Fixed post.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
So I just replace myX with a variable or object?

Also :atSpeed: is just a typo right? The first colon shouldn't be there?

Thanks! I really gotta pay you some day...
Nate
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
Also :atSpeed: is just a typo right? The first colon shouldn't be there?

I think the extra colon is just used to state that the first set of arguments is finished and that the next one is coming up. It compiled fine anyway, not sure myself I only started learning Objective-C properly on Saturday.

Edit : Just looked through some of the system headers and, yes, you are right, it is incorrect having the extra colon.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
ok. It works fine without it as well.
How have you been helping me all this time if you only started objective C last saturday???
Nate
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
I'm still getting used to the documentation and using google... usually my google results are useless lol. But I do google and check the documentation before asking these questions.

This framework is causing more problems than I expected...

I want to capture the object that called my method into an NSObject instance I created so I can manipulate it in another method... how do I do that?
The closest thing I can find is to do this...
[object copy:sender];
but sender isn't a keyword apparently, and doing (id)sender doesn't work either.
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
I'm still getting used to the documentation and using google... usually my google results are useless lol. But I do google and check the documentation before asking these questions.

This framework is causing more problems than I expected...

I want to capture the object that called my method into an NSObject instance I created so I can manipulate it in another method... how do I do that?
The closest thing I can find is to do this...
[object copy:sender];
but sender isn't a keyword apparently, and doing (id)sender doesn't work either.

Pass the object as an argument to the method then copy it within the method and return the copied object?

- (NSObject *)myCopyObjectMeth:(NSObject *)myObject
{

}
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
here's my .h and .m... please excuse any messiness.
Code:
#import <Cocoa/Cocoa.h>


@interface ESAnimation : NSObject {
	NSView *object;
	int loopXTimes;
	NSTimer *timer;
}
- (void)animateIntTo:(int)x atSpeed:(float)y;
- (void)animateFloatTo:(float)x atSpeed:(float)y;
- (void)animateDoubleTo:(double)x atSpeed:(float)y;
- (void)animateStringTo:(NSString *)x atSpeed:(float)y;
- (BOOL)animationIsDone;
@end
Code:
#import "ESAnimation.h"


@implementation ESAnimation
- (void)animateIntTo:(int)x atSpeed:(float)y {
	
	loopXTimes=x;
	timer=[[NSTimer scheduledTimerWithTimeInterval:y target:self selector:@selector(incrementInt:) userInfo:nil repeats:YES] retain];
}
- (void)animateFloatTo:(float)x atSpeed:(float)y {
	
}
- (void)animateDoubleTo:(double)x atSpeed:(float)y {
	
}
- (void)animateStringTo:(NSString *)x atSpeed:(float)y {
	
}

- (void)incrementInt:(NSTimer *)aTimer {
	int loop=loopXTimes;
	loopXTimes++;
	if (loopXTimes==loop) {
		[timer invalidate];
		[timer release];
		timer=nil;
	}
}
- (void)incrementFloat:(NSTimer *)aTimer {
	
}
- (void)incrementDouble:(NSTimer *)aTimer {
	
}
- (void)incrementString:(NSTimer *)aTimer {
	
}
- (BOOL)animationIsDone {
	BOOL a=1;
	return a;
	//Will make BOOL value 1 when animation is finished
}
@end

This current code works fine but doesn't exactly do anything. My goal with this class is to be able to animate variables, including strings. When I was messing a teensy bit with CA I found out that if I try animating an int it doesn't do anything. So what I want is to be able to use my methods instead, so that when used that value will increment at the set speed until it reaches the target number, thus animating it. I have a more complicated idea for animating strings but it's the same idea.

Unfortunately just using a C loop will freeze all input until it's done of course, so I need to use a timer which involves a second method which is proving to be a pain.
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
So basically your current methods are just providing the means to animate, other methods will do the drawing?

If that is the case, you really don't need to know about any of that when designing a framework. You just need to provide an interface (classes and methods) that the programmer uses. You do not need to know how the programmer uses them and the programmer does not need to know how you implement your methods.

You can worry about that once you have finished your framework and actually need to use it :).
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
Code:
int loop=loopXTimes;
loopXTimes++;
if (loopXTimes==loop)
...

Just took a quick look at the code, and the above bit has obvious issues. ;)

loopXTimes is loop+1, so when you compare if they're equal - they will never be, so that if statement will never be true.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
thanks for pointing that out :)

This is proving to be a bigger problem than I thought. The programmer won't have the chance to update the value each time the timer fires.
Does anyone have a solution to my problem? I either need to allow the programmer to redraw his objects with the new value, or somehow handle it myself. I'm not sure how to do either, unless someone can show me how to do that selector thing so that I can call a method the programmer wrote each time around, so he can handle redrawing that way. Unfortunately, I don't know how.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
ok thanks.

I'm trying to figure out how to use a selector or a vague reference I found to fireMethod: but so far with no luck. I want the programmer to be able to specify his own redrawing method that will be called each time the value is updated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.