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

twoodcc

macrumors P6
Original poster
Feb 3, 2005
15,307
26
Right side of wrong
ok, i want to make an app that all it really is a timer: while it runs, the time is ticking (going up). and when you quit the program, it saves the time. and then when it is launched again, the time starts from where it left off before.

so, you launch it, let it run for 5:05, then you close it. open it up later, it runs for 0:25, so it says 5:30 is the time.

does that make sense?

also, can i show it in years, months, days, hours, minutes, seconds?

is this possible?

thanks in advance
 
This would be a very simple application that you could create in a day without any previous knowledge of Cocoa. Of course, if you have no knowledge of application development, it will take you longer.

I would make this for you if I wasn't going out of town.
 
Yes. Obviously you'll need to know how to program and have some knowledge (or be willing to gain that knowledge) of Cocoa (or Carbon if you really want).

thanks for the reply.

This would be a very simple application that you could create in a day without any previous knowledge of Cocoa. Of course, if you have no knowledge of application development, it will take you longer.

I would make this for you if I wasn't going out of town.


thanks for the reply. I do have programming knowledge, but not much when it comes to Cocoa.

how would i go about this with cocoa though?
 
In general terms:
You need a backing store to keep the current time, and you need to store it when the app is closed. I'm not too well versed with this stuff, so i don't know if that should go in terminate:, etc. The backing store can be a file in the filesystem, an entry in a plist, etc. How to deal with these should be pretty easy to find.

Is the timer needs to be changing every second, you might look into something like what is described in this stackoverflow thread:
http://stackoverflow.com/questions/...g-a-number-and-showing-steps-on-a-cocoa-label

Essentially you just need to, on a timer, update a label, etc.

-Lee
 
In general terms:
You need a backing store to keep the current time, and you need to store it when the app is closed. I'm not too well versed with this stuff, so i don't know if that should go in terminate:, etc. The backing store can be a file in the filesystem, an entry in a plist, etc. How to deal with these should be pretty easy to find.

Is the timer needs to be changing every second, you might look into something like what is described in this stackoverflow thread:
http://stackoverflow.com/questions/...g-a-number-and-showing-steps-on-a-cocoa-label

Essentially you just need to, on a timer, update a label, etc.

-Lee

thanks for the reply and link.

i'm still not sure how to get started here. like i said, i do have programming experience, just not much with cocoa.

how would i save the time? with core data?
 
I created a very simple timer application for you to get started with. When the application opens, the timer starts counting. You can stop it or reset it.

You just need to add the function that stores the elapsed time to a file and also loads the value from the file.

I have uploaded the application to my SkyDrive (Hotmail's online disk drive). Please let me know once you've downloaded it so I can take it off.

Note: You must have XCode 3 to build it and Leopard to run it.
 
I created a very simple timer application for you to get started with. When the application opens, the timer starts counting. You can stop it or reset it.

You just need to add the function that stores the elapsed time to a file and also loads the value from the file.

I have uploaded the application to my SkyDrive (Hotmail's online disk drive). Please let me know once you've downloaded it so I can take it off.

Note: You must have XCode 3 to build it and Leopard to run it.

thanks so much! I will download it today as soon as i get home from work.
 
I created a very simple timer application for you to get started with. When the application opens, the timer starts counting. You can stop it or reset it.

You just need to add the function that stores the elapsed time to a file and also loads the value from the file.

I have uploaded the application to my SkyDrive (Hotmail's online disk drive). Please let me know once you've downloaded it so I can take it off.

Note: You must have XCode 3 to build it and Leopard to run it.

alright, i downloaded it! thanks!

i ran it just to see it, and it seems to work. but when you click "stop", visually it does stop, but when you click "resume" it jumps to where it would have been if you didn't click stop. in other words, it really doesn't stop.

but that's not a big deal.

so how would i go about saving the data? would i use core data?
 

thanks for the link. i will look at it in more detail after work. i know there is sample code with that link, but just a simple example would really help me out (without having to look thru all the code to find it, and even then i probably won't understand what i find)

like i said, the syntax i'm used to is visual basic, c#, java, php, etc. where cocoa is totally different
 
What's your goal? Is it to learn Cocoa, or is it to write a timer app? If the latter, I'd suggest using something you already know if you have knowledge in other languages. I thought I remember you doing some Java before? That certainly would do the job. If you're trying to learn Cocoa, you won't get far just by piecing things together without an understanding of what's happening.
 
What's your goal? Is it to learn Cocoa, or is it to write a timer app? If the latter, I'd suggest using something you already know if you have knowledge in other languages. I thought I remember you doing some Java before? That certainly would do the job. If you're trying to learn Cocoa, you won't get far just by piecing things together without an understanding of what's happening.

thanks for the reply

the main goal is to learn Cocoa. i know that piecing things together will not really help me, that's why if i get an example, with some sort of instruction with it, then i might start to catch on.

for some reason i have had a really hard time with cocoa. i bought the book (3rd edition), and have not finished the book, but do plan to. but i just can't quite get it like i do php or java
 
I'd suggest learning Objective-C first. This will make it far easier to learn Cocoa.
 
i tried to go that route, and i made a few apps that ran in the terminal. but didn't seem to help me with cocoa

You need to learn the language (C then Objective-C) then the API (Cocoa). It's not something you will learn in 5 minutes. You need to take time to follow the tutorials that teach you the basics on the Apple site, get a book, follow it through and learn the basic paradigms. Once you understand the main patterns in Cocoa it all starts to fall into place.

Asking others to write code and then copy/pasting it will teach you absolutely nothing.
 
You need to learn the language (C then Objective-C) then the API (Cocoa). It's not something you will learn in 5 minutes. You need to take time to follow the tutorials that teach you the basics on the Apple site, get a book, follow it through and learn the basic paradigms. Once you understand the main patterns in Cocoa it all starts to fall into place.

Asking others to write code and then copy/pasting it will teach you absolutely nothing.

thanks for the reply.

i understand that i need to go thru the whole process to really learn cocoa, but without a teacher, that won't be easy - and it won't be quick either. granted, if i did not work all day, then i could probably go thru all of that. but i can't. so i'm trying another route.

i didn't ask anyone to write the app for me. i was asking how to go about making this app. and i later asked for some examples on how to do certain things. i believe that i can learn from that. but maybe i can't - we'll see.

this weekend i plan on really knocking this out, one way or the other. i really can't during the week, b/c i have to work all day, and then study what i did at work that day b/c i am tested on it. yes i know, that's my problem
 
ok, so i'm trying to implement NSUserDefaults, and don't really know how to go about it.

what type of variable is TimeSinceDate? i think i want to write that the the defaults, and call it on startup of the app.
 
ok, so i'm trying to implement NSUserDefaults, and don't really know how to go about it.

what type of variable is TimeSinceDate? i think i want to write that the the defaults, and call it on startup of the app.

ok, i overlooked that timeSinceDate is an NSTimeInterval variable. but when i try to update that variable with the userdefaults, it says incompatible data types. but i've tried every type. what am i supposed to do?
 
To store:
Code:
//Assume myNSUD is your NSUserDefaults * that is initialized
//Assume currentTimeElapsed is an NSTimeInterval with the value you want to store
[myNSUD setObject: [NSNumber numberWithDouble:currentTimeElapsed] forKey:@"Time Elapsed"];

To retrieve:
Code:
//Assume myNSUD is your NSUserDefaults * that is initialized
NSNumber *tempTime = (NSNumber *)[myNSUD objectForKey:@"Time Elapsed"];
NSTimeInterval savedTime = [tempTime doubleValue];
//savedTime is now set to the value previously stored

References:
NSUserDefaults
NSNumber
Foundation types, including NSTimeInterval

-Lee
 
To store:
Code:
//Assume myNSUD is your NSUserDefaults * that is initialized
//Assume currentTimeElapsed is an NSTimeInterval with the value you want to store
[myNSUD setObject: [NSNumber numberWithDouble:currentTimeElapsed] forKey:@"Time Elapsed"];

To retrieve:
Code:
//Assume myNSUD is your NSUserDefaults * that is initialized
NSNumber *tempTime = (NSNumber *)[myNSUD objectForKey:@"Time Elapsed"];
NSTimeInterval savedTime = [tempTime doubleValue];
//savedTime is now set to the value previously stored

References:
NSUserDefaults
NSNumber
Foundation types, including NSTimeInterval

-Lee

thanks! now, do i have to put both of these in their own function for it to work?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.