cocoa

How to redirect the nslog output to file instead of console.

I have cocoa application running on OS X. I have used NSLog for debugging purpose. Now I want to redirect the log statements to file instead of console. I have used this method but it results logging in Console as well as in file. - (BOOL)redirectNSLog { // Create log file [@"" writeToFile:@"/NSLog.txt" atomically:YES encoding:...

Displaying a string in Cococa

I made a Cocoa program that lets the user enter their name in NSTextField. When the user presses a button, another textbox is supposed to say Hello to them. This is the code I tried to use. NSString *myString = [textField stringValue]; [textView setString: @"Hello " myString]; This does not work. How can it be fixed? ...

Reference counting in Cocoa

Hi, I assume according to "Cocoa design patterns" book i'm reading that the retain function is implemented using something like this : - (int)retainCount // Returns the receiver's current reference count { int result = 1; // receiver not in table, its count is 1 void *tableValue = NSMapGet( [[self class] _myRefCountMapTable], self);...

Displaying the date in Cocoa

If I run the following code: [textView setString: [ NSString stringWithFormat: @"Hello %@. Today is %@", [ textField stringValue ], [ NSDate date]] ]; it says Hello Phenom. Today is 2010-07-06 02:37:43 -0700 How can I fix it so that it instead says Hello Phenom. Today is Tuesday, July 6 ...

App crashes on invoking CGPDFContentStreamWithPage

Hi all, I am trying to parse a PDF and extract catalogue from it. For this purpose I am using following code: - CGPDFPageRef page = CGPDFDocumentGetPage(document, currentPage); //1 myContentStream = CGPDFContentStreamCreateWithPage (page); //2 myScanner = CGPDFScannerCreate (myContentStream, table, NULL); //3 CGPDFScannerSca...

How to know who will take ownership?

Recipe example RecipeAddViewController *addController = [[RecipeAddViewController alloc] initWithNibName:@"RecipeAddView" bundle:nil]; addController.delegate = self; Recipe *newRecipe = [NSEntityDescription insertNewObjectForEntityForName:@"Recipe" inManagedObjectContext:self.mana...

Initiate key presses in Cocoa

Hi, Im writing a server to receive key events from an iPhone. I can send a message from the iPhone and have my server display it, on the Mac, now i just need to translate that into a Key press, and simulate that press in Cocoa. Could anyone offer me a starting point, as i guess this is quite low level. Thanks ...

Prevent duplicates when importing RSS feed to Core Data

Trying to import a RSS feed into Core Data. Once they are imported, when trying to update the feed again afterwards, how do I most efficiently prevent duplicates. Right now it checks every item against the datastore during the parsing, which is not very efficient. I looked into the Top Songs sample from Apple. It uses a least recently u...

Rotate .swf file in WebVIew in Mac OS X

Hi I am developing a Cocoa application to embed a .swf file in a WebView and rotate the content of the Webview. The .swf file is an interactive flash file. Everything works fine, but when I rotate the content of the WebView, the drawing of the flash and playback get rotated, but not the interactive points of the .swf file. They stay in ...

Cocoa memory management rule

Hi, The Cocoa "Memory Management Programming Guide" document says: You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message. You are responsible for relinquishing ownership of objects y...

How to associate a 4-char OSType / NSFileHFSTypeCode with a particular UTI

I am writing a MacFuse plugin, and would like finder to use the appropriate icons & launch the appropriate app when a file is opened. It is not possible for me to add an extension to the file, so my only other option in Snow Leopard is the NSFileHFSTypeCode. I have reviewed all of the codes registered on my machine using http://www.rub...

kqueue NOTE_EXIT doesn't work

Hi everybody. I am trying to use Apple's example of using kqueue but the callback is never called unless I start observing the kqueue after the process starts. But the lifetime of the process is short and i need the code to work if the process starts before or after I start observing it. ...

dataWithContentsOfURL return value not nil when URL empty

Hi everybody, i have a problem using dataWithContentsOfURL. I'm loading some images from the internet in a loop. The Problem is: if the image at the URL doesn't exist, dataWithContentsOfURL does NOT return nil as expected. The apple reference says it returns nil if NSData could not be created. Here's the Code: NSString *TermineImgFile...

Crash invalidates url for NSPersistentStoreCoordinator

I have a Core Data app that has a bug that causes the app to crash and I have not tracked down its cause yet. One of the results of the crash is that the next time the app is started up it can not open the persistent store used by the application previously. The following error is returned from the addPersistentStoreWithType: method: ...

abort() called in gethostbyname - how to handle

I get a abort() which I am not able to 'catch' in my code. Perhaps I am missing some understanding; can you give me some insight or perhaps help me with the abort() ? Please note; the code works fine for thousands of users I have; but a very few (two now) have reported this crash. First the code (simplified): 244: -(void)openBSDSocket...

DRAW (print - not the graph) an equation in Quartz (iPhone SDK)

I'm trying to draw equations to the screen. Not the graphs or sth just the equation, but in a "pretty" way (f.e. like they look on wikipedia ). I've done some research but could find a "build-in-way", but maybe i overlooked something?!? So i've decided to draw them by myself. I'm not very experienced, so don't blaim me if my idea is com...

How to enable HTML client-side SQL database in embedded webkit app (test app on github)

I've got a super simple little OS X app with a minimal embedded webkit view that needs client-side SQL database support enabled. I've put the test app up on github but just can't get the client-side storage working. I'm using Xcode v3.2.3 with the WebKit framework it provides, but have also tried using the webkit nightly without luck. ...

Portable code for deprecated userInfo dictionary key (Cocoa)

In Mac OSX 10.6, the NSErrorFailingURLStringKey userInfo dictionary key is deprecated in favor of NSURLErrorFailingURLStringErrorKey. I am trying to write my program to be portable to both Mac OSX 10.5 and 10.6. For the time being, I'm just using the old key--but my compiler is giving me annoying deprecated warnings. // The following ca...

Extend NSMutableArray for bi-directional association management

I am a great fan of code generation (from UML) and coming from the Java world, I wonder how I would implement automated bi-directional association management in Objective-C. Image an association Partner <-> Address, one-to-many and navigable from both ends. What I would like to achieve is that if I append an Address to a Partner that Ad...

Cocoa NSTask help

Hey guys, I need a bit of help with NSTask. Also, I am new to Cocoa / Obj-C programming, so please bear with me. I am trying to make a directory. Then, remove it. So here is what I have so far: NSLog (@"START"); NSTask *task; task = [[NSTask alloc] init]; [task setLaunchPath: @"/bin/mkdir"]; NSArray *arguments; arguments = [NSArray a...