PDA

View Full Version : time app




twoodcc
Mar 31, 2009, 08:16 AM
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



robbieduncan
Mar 31, 2009, 09:35 AM
is this possible?


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).

themoonisdown09
Mar 31, 2009, 09:45 AM
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.

twoodcc
Mar 31, 2009, 12:05 PM
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?

lee1210
Mar 31, 2009, 12:22 PM
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/237621/obj-c-incrementing-a-number-and-showing-steps-on-a-cocoa-label

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

-Lee

twoodcc
Mar 31, 2009, 04:37 PM
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/237621/obj-c-incrementing-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?

themoonisdown09
Mar 31, 2009, 10:48 PM
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 (http://cid-5c909638503514c6.skydrive.live.com/browse.aspx/Public) (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.

twoodcc
Apr 1, 2009, 06:47 AM
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 (http://cid-5c909638503514c6.skydrive.live.com/browse.aspx/Public) (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.

twoodcc
Apr 1, 2009, 07:01 PM
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 (http://cid-5c909638503514c6.skydrive.live.com/browse.aspx/Public) (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?

robbieduncan
Apr 2, 2009, 02:35 AM
so how would i go about saving the data? would i use core data?

I'd suggest you use NSUserDefaults: CoreData is massively overkill to store a single value!

twoodcc
Apr 2, 2009, 06:00 AM
I'd suggest you use NSUserDefaults: CoreData is massively overkill to store a single value!

oh ok. so how would i go about doing that?

robbieduncan
Apr 2, 2009, 06:57 AM
oh ok. so how would i go about doing that?

Read the documentation (http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html)?

twoodcc
Apr 2, 2009, 09:24 AM
Read the documentation (http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html)?

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

kainjow
Apr 2, 2009, 09:51 AM
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.

twoodcc
Apr 2, 2009, 10:26 AM
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

kainjow
Apr 2, 2009, 10:32 AM
I'd suggest learning Objective-C first. This will make it far easier to learn Cocoa.

twoodcc
Apr 2, 2009, 10:44 AM
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

robbieduncan
Apr 2, 2009, 10:52 AM
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.

twoodcc
Apr 2, 2009, 11:48 AM
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

twoodcc
Apr 3, 2009, 07:29 PM
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.

twoodcc
Apr 3, 2009, 09:01 PM
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?

twoodcc
Apr 3, 2009, 09:55 PM
would NSCoding be a good method for saving this data?

twoodcc
Apr 3, 2009, 10:06 PM
would NSCoding be a good method for saving this data?

well, after trying to use this method, i broke the app

lee1210
Apr 4, 2009, 12:15 AM
To store:

//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:

//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 (http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html)
NSNumber (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsnumber_Class/Reference/Reference.html)
Foundation types, including NSTimeInterval (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html)

-Lee

twoodcc
Apr 4, 2009, 08:09 AM
To store:

//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:

//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 (http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html)
NSNumber (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsnumber_Class/Reference/Reference.html)
Foundation types, including NSTimeInterval (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html)

-Lee

thanks! now, do i have to put both of these in their own function for it to work?

GorillaPaws
Apr 4, 2009, 08:39 AM
Asking others to write code and then copy/pasting it will teach you absolutely nothing.

I just thought this should be mentioned again.

twoodcc
Apr 4, 2009, 08:46 AM
I just thought this should be mentioned again.

very helpful.

but since i have no teacher, i do have a book, but am still having trouble with cocoa, i don't see how i can just dream up how to do this on my own without someone showing/explaining how to do it

GorillaPaws
Apr 4, 2009, 09:21 AM
very helpful.

but since i have no teacher, i do have a book, but am still having trouble with cocoa, i don't see how i can just dream up how to do this on my own without someone showing/explaining how to do it

I'm not trying to be rude, just to say that your time would be better spent working from your book and asking for help understanding/clarifying concepts from it instead of asking people to write an app for you one question at a time and then pasting it all together (i.e. your strategy is faulty).

This stuff is hard, it takes a lot of time and effort (especially when you can only do it in your spare time).

twoodcc
Apr 4, 2009, 09:56 AM
I'm not trying to be rude, just to say that your time would be better spent working from your book and asking for help understanding/clarifying concepts from it instead of asking people to write an app for you one question at a time and then pasting it all together (i.e. your strategy is faulty).

This stuff is hard, it takes a lot of time and effort (especially when you can only do it in your spare time).

oh i know it's hard. if it was easy, i wouldn't be here. but i think everyone learns their own way. i, for one, have trouble following a book by myself and learning that way. i need a teacher. and since i can't afford to take classes from BNR, i am out of luck. so this is my other teacher - people on the internet (this case, MR).

the more questions i ask, the more projects i go thru, i will pick this up. sure, i might go thru a lot of tutorials online, etc, and i will go thru the book also.

but, i am trying the learn the way i know how to learn. if you can help me out, i would be very grateful. if you can't, no worries. i will continue to search and work for the answer.

granted, i might ask what seems like stupid questions, but if i don't ask, i won't learn

here is a quick video of what i have going on:

http://www.youtube.com/watch?v=9L8_nPyYZyE

here is a quick video of what i have going on:

http://www.youtube.com/watch?v=9L8_nPyYZyE

here's the same video, but i was trying to get it in HD

http://www.youtube.com/watch?v=L7Xe6dQkPtA

maybe it just takes awhile before HD is available

twoodcc
May 6, 2009, 08:48 AM
well i have not been working on this project, since i got stuck with saving the time and then calling it back.

i plan to try again, since i haven't looked at this in a few weeks.

if anyone can help me out with it, i'd appreciate it.