I'm wanting to make one of my methods to run every 60 seconds when my App is running, how would I do that?
+5
A:
- (void) startTimer
{
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:60
target:self
selector:@selector(timerFired:)
userInfo:nil
repeats:YES];
}
- (void) stopTimer
{
[self.myTimer invalidate];
}
- (void) timerFired:(NSTimer*)theTimer
{
NSLog(@"yay");
}
slf
2009-09-27 14:52:26
Hmm. http://snapplr.com/fmga
Joshua
2009-09-27 14:59:33
You have to add a myTimer property to your class.
Georg
2009-09-27 15:08:19
What do you mean?
Joshua
2009-09-27 15:14:33
`self.myTimer` indicates that the object has an instance variable called `myTimer`. You have to add a `NSTimer *myTimer` declaration to the list of instance variables for the class.
mipadi
2009-09-27 15:26:28
I tried putting `NSTimer *myTimer` into the Header file, but … http://snapplr.com/zyv2
Joshua
2009-09-27 15:31:38
-> this should go into your @interface: @property NSTimer *myTimer; This should go into your @implementation: @synthesize myTimer;
Georg
2009-09-27 15:41:33
Still one error. http://snapplr.com/r7w7
Joshua
2009-09-27 15:50:40
@Joshua - Jeebus! how do you expect to add a property to a class when it's outside of the interface?
Abizern
2009-09-27 15:53:45
Joshua, I recommend you re-read http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html to brush up on class definitions
sbooth
2009-09-27 16:17:29
Seriously -- go read the basic introduction to cocoa programming guides. These kinds of questions indicate a complete lack of knowledge of the targeted environment. Nothing wrong with that, but fixing it with sequences of questions like the above will get you nowhere fast.
bbum
2009-09-27 18:12:29
If his past questions and answers and comments are any indication, Joshua does not read or write code. If you don't provide him a code sample, he's stuck. If you do provide him a code sample, he copies it and pastes it into his app verbatim and then asks in comments about the errors that ensue when it doesn't work.
Peter Hosey
2009-09-27 19:01:26
I and others have told him to read the documentation and/or a book before. I think it's pretty clear that he's ignoring that advice and continuing on his current path.
Peter Hosey
2009-09-27 19:03:12
And just after I wrote that, I see that he's reasoned his own solution to a problem. Maybe he is making progress after all? http://stackoverflow.com/questions/1483676/making-a-nspopupbutton-display-all-my-ical-calandars#comment-1335225 I'm not saying we should write him off entirely. My suggestion is, don't give him code samples. Give him specific advice in English, perhaps with documentation links, instead.
Peter Hosey
2009-09-27 19:10:14
+1
A:
While the answer is valid, your question is incomplete.
Why do you need to run this method regularly? If it is to poll iCal for tasks every 60 seconds this isn't the best solution. What you need to be doing is observing the notifications that CalCalender store puts outs
Abizern
2009-09-27 16:16:30
Really, It needs to be triggered whenever something changes in an NSOutlineView, like a Row is added, deleted or editing. Is there something I could observe for that?
Joshua
2009-09-27 16:26:19
You can post your own notifications from the methods that do the adding, deleting and editing.
Abizern
2009-09-27 16:38:16
This document on notifications should help. It has a section on posting notifications: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Notifications/Introduction/introNotifications.html
nall
2009-09-27 17:28:40
Even better, use Key-Value Observing. Add yourself as an observer of the array property on the controller that owns it.
Peter Hosey
2009-09-27 18:59:05