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

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
Hey guys, I've got a few Cocoa issues I'm having trouble getting over. Believe me, I've tried figuring them out on my own and I can't get any of them.

  • Every once in a while, (NOT every time) when I build and go, the debugger also loads and gives me the error seen in the image below. I don't have much practice with the debugger, so I don't really know what the problem is, other than it has to do with a calendar date. Any insight?
  • I know Core Data stores its data on its own, but I changed to a Core Data Document-Based app with the same name, same structure, etc. and everything is gone. Is there any way to remedy this?
  • In MyDocument.m, i can call a method that does: [self updateApplicationBadge]. I'm trying to call the same method in a separate class, but I can't figure out how to get the instance of the MyDocument. Like instead of [self updateApplicationBadge], [MyDocument updateApplicationBadge].

Thanks guys! :D
 

Attachments

  • Picture 1.png
    Picture 1.png
    104.9 KB · Views: 134
sorry, i'm new to cocoa programming, but one thing I do know (concerning referencing My Document) is that in Interface Builder, "File's Owner" is supposed to be an instance of My Document. Programmatically, i'm not sure how that helps, but the thought just jumped out from my brain when I read what you were having a problem with.
As far as the debugger is concerned, I would set a breakpoint in your code where that is happening (preferably just before) and step-thru, monitoring the variables that are being dealt with in that section of code.
Good luck!
 
sorry, i'm new to cocoa programming, but one thing I do know (concerning referencing My Document) is that in Interface Builder, "File's Owner" is supposed to be an instance of My Document. Programmatically, i'm not sure how that helps, but the thought just jumped out from my brain when I read what you were having a problem with.
As far as the debugger is concerned, I would set a breakpoint in your code where that is happening (preferably just before) and step-thru, monitoring the variables that are being dealt with in that section of code.
Good luck!
Ya, I've used File's Owner before to connect the Outlets/Actions defined in MyDocument.h, but the programmatically part is what I'm stuck on. :) As for the breakpoints, I don't actually know where the error is happening, so I don't know where to place the breakpoint. :eek:
 
Hey guys, I've got a few Cocoa issues I'm having trouble getting over. Believe me, I've tried figuring them out on my own and I can't get any of them.

  • In MyDocument.m, i can call a method that does: [self updateApplicationBadge]. I'm trying to call the same method in a separate class, but I can't figure out how to get the instance of the MyDocument. Like instead of [self updateApplicationBadge], [MyDocument updateApplicationBadge].

Thanks guys! :D

Basic OO programming. Is updateApplicationBadge a class method (prefixed with a +) or an instance method (prefixed with a -). If it's a class method then you can just use [classname method]. It sounds like it not a class method and you have defined a utility class to update your dock badge and want to call a method in it. This would appear to be a good time to use a singleton object.

This would look something like this
Code:
@implementation DockIconController
static DockIconController* _sharedDockIconController;
+ (id) sharedInstance
{
    if (! _sharedDockIconController)
    {
		// There is not a shared instance so create one...
        _sharedDockIconController = [[DockIconController alloc] init];
    }
    // return the shared nstance
    return _sharedDockIconController;
}

- (void) updateApplicationBadge
{
  // Your code here
}
@end

You would use this something like this:

Code:
[[DockIconController sharedInstance] updateApplicationBadge];
 
Basic OO programming. Is updateApplicationBadge a class method (prefixed with a +) or an instance method (prefixed with a -). If it's a class method then you can just use [classname method]. It sounds like it not a class method and you have defined a utility class to update your dock badge and want to call a method in it. This would appear to be a good time to use a singleton object.

This would look something like this
Code:
@implementation DockIconController
static DockIconController* _sharedDockIconController;
+ (id) sharedInstance
{
    if (! _sharedDockIconController)
    {
		// There is not a shared instance so create one...
        _sharedDockIconController = [[DockIconController alloc] init];
    }
    // return the shared nstance
    return _sharedDockIconController;
}

- (void) updateApplicationBadge
{
  // Your code here
}
@end

You would use this something like this:

Code:
[[DockIconController sharedInstance] updateApplicationBadge];

They should probably be using the offical singleton design pattern which is:
Code:
static MyGizmoClass *sharedGizmoManager = nil;

+ (MyGizmoClass*)sharedManager
{
    @synchronized(self) {
        if (sharedGizmoManager == nil) {
            [[self alloc] init]; // assignment not done here
        }
    }
    return sharedGizmoManager;
}
 
+ (id)allocWithZone:(NSZone *)zone
{
    @synchronized(self) {
        if (sharedGizmoManager == nil) {
            sharedGizmoManager = [super allocWithZone:zone];
            return sharedGizmoManager;  // assignment and return on first allocation
        }
    }
    return nil; //on subsequent allocation attempts return nil
}
 
- (id)copyWithZone:(NSZone *)zone
{
    return self;
}
 
- (id)retain
{
    return self;
}
 
- (unsigned)retainCount
{
    return UINT_MAX;  //denotes an object that cannot be released
}
 
- (void)release
{
    //do nothing
}
 
- (id)autorelease
{
    return self;
}
 
I see what you guys are saying, but the problem is, I'm trying to get the instance of MyDocument. Like the method is defined in MyDocument.h, and is implemented in MyDocument.m. I want to call it from another class, called iProcrastinateMO.m.
 
From the look of the picture, it would seem that your app is multi-threading, and the heartbeat thread (possibly, based on the NSCalendarDate stuff in there) has been assigned to thread 3. Go look at thread 0, 1, and 2 to see where the actual crash is; I suspect thread 3 is merely hanging wherever the crashed one is (maybe it's waiting for data), especially since the line its on is blue, not red. Red indicates the crash line.
 
You can ask the NSDocumentController for an array of documents and work through them. Or if you simply want the foremost document you can use:

Code:
[[NSDocumentController sharedDocumentController] currentDocument];

As I always seem to end up saying: it's all in the documentation :p
 
From the look of the picture, it would seem that your app is multi-threading, and the heartbeat thread (possibly, based on the NSCalendarDate stuff in there) has been assigned to thread 3. Go look at thread 0, 1, and 2 to see where the actual crash is; I suspect thread 3 is merely hanging wherever the crashed one is (maybe it's waiting for data), especially since the line its on is blue, not red. Red indicates the crash line.
Hmm, whenever I try to go to the other threads, they just get weirder and weirder. (just a bunch of mach's and other 3/4-letter, terse messages)

You can ask the NSDocumentController for an array of documents and work through them. Or if you simply want the foremost document you can use:

Code:
[[NSDocumentController sharedDocumentController] currentDocument];

As I always seem to end up saying: it's all in the documentation :p
Ah, that did it! :D Thanks a bunch.
 
Can you post a screenshot for thread 0, preferably showing the entirety of the stack trace (the part in the upper left corner)?
I would, if I could find a thread 0. :) Here's a post of thread 1, though!
 

Attachments

  • Picture 1.png
    Picture 1.png
    48 KB · Views: 81
  • Picture 2.png
    Picture 2.png
    76.3 KB · Views: 82
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.