cocoa

How to declare a function in Cocoa after the function using it?

I'm slowly building my application to a working state. I'm using two functions called setCollection and addToCollection. These functions both accept NSArray as input. I also have a function called add in which I use both of these functions. When I try to compile, Xcode shows an error: 'setCollection' undeclared (first use in this f...

OCMock: Make a stub do something

I'm getting used to OCMock. Coming from a Java/JMock background I'm now looking for the ability to say [[[myMock stub] returnValueFromCustomMethod] someMockedMethod]; where returnValueFromCustomMethod is defined in the test class. I was originally thinking something along the terms of [[[myMock stub] usingSelector:@selector(myMethod:)] s...

Why is my comparing if statement not working?

Why is the following code (in cocoa) not working? NSString *extension = [fileName pathExtension]; NSString *wantedExtension = @"mp3"; if(extension == wantedExtension){ //work } in Xcode this just runs without warnings or errors but doesn't do what I think it SHOULD do. ...

Is there a framewok / API I could use to export iPhone-SDK's ABRecordRef instances to vCard?

I'm looking at source code from Funambol, but the dependencies are so huge, I'm rethinking of using them, not to mention the code is based on OC++. Can anyone help me out on this? Thanks. ...

How can I divide a bound array in parts that automatically fill the table?

I used this 'tutorial' to bind my array called 'collection' to a NSTableview on my interface: http://www.cocoadev.com/index.pl?NSArrayController The interfacebuilder stuff isn't that hard. It becomes difficult when I try to actually show the data in my array into the view. in my .h file: @interface MyDocument : NSDocument { NSMuta...

Shared Objects in Cocoa

Hey guys. I'm working with CoreData in Cocoa (not document-based). My problem is, that I want to access the SAME NSArrayController from different NIBs. But every NIB has an own instance of this NSArrayController. My question is now how I could generate sharedObjects (like the NSUserDefaultsController). It would help me a lot. Thanks fo...

Can you help me understand retain counts in cocoa/objective-c?

> .h file: NSString *myString; @property (nonatomic, retain) NSString *myString; > .m file: self.myString = [[NSString alloc] init]; If i'm not wrong i will end up with an NSString instance with retain count of +2. Right? I'm curious because Apple's example for Location uses "self." for initialization. Why? I checked and it does show...

Reduce UIImage size to a manageable size (reduce bytes)

I want to reduce the number of bytes of an image captured by the device, since i believe the _imageScaledToSize does not reduce the number of bytes of the picture (or does it?) - i want to store a thumbnail of the image in a local dictionary object and can't afford to put full size images in the dictionary. Any idea? ...

How to split a NSDecimalnumber between decimal & integer & back

I can't figure how get the integral & decimal value from a NSDecimalnumber. For example, if I have 10,5, how get 10 & 5? And if I have 10 & 5, how return to 10,5? ...

Java equivalent of Cocoa NSNotification?

I am writing a Java application using SWT widgets. I would like to update the state of certain widgets upon a certain event happening (for example, updating the data model's state). Is there something in Java similar to Cocoa's NSNotificationCenter, where I can register an object to listen for notification events and respond to them, as...

Bind user defaults to different identifier

I have a preference pane bundle (it runs in the System Preferences). I designed the interface using Interface Builder where I binded a "start automatically" checkbox to the Shared User Defaults. This works great but it writes the preference to com.apple.systempreferences. I would like to keep my preferences in the com.example.mybundle de...

How can I use OCMock objects with code that calls isKindOfClass ?

Hi, I'd like to test some code with OCMock. The innards of the code are calling [NSObject isKindOfClass] on the mock object I'm providing to the code, like so: if ([object isKindOfClass:[FancyClass class]]) { ...} However, when I provide an OCMockObject-based mock created like this: mock = [OCMockObject mockForClass:[FancyClass clas...

Can you translate php function quoted_printable_decode() to an NSString-based, objective-C function / category method?

In http://php.net/quoted_printable_decode, I found ways to do it using preg_replace. Anyone who knows any code that could convert a normal NSString to something RFC 2045 section 6.7? Thanks in advance! ...

How to get some values from CoreData-Entities to code.

Hey guys! =) I've created in my CoreData app an entity with some attributes. Imagine a tableview and a bound NSArrayController. With both I create (and edit) my entity "instances". My question is how I can get the values of these attributes to my code. If there are more questions: http://twitter.com/xP_ablo ...

Drawing massive amounts of data in NSView, or something else?

I have hundreds of thousands of points of time series data that I want to represent to the user. My current solution is to render said data to a PNG with a 3rd party library and then load that PNG into a NSImage and display it in a scroll view. This works great, except that: NSImages more than 32k pixels wide don't display properly ...

"Save" in CoreData-apps

I've here a CoreData app (no document-based), 1 entity and 1 tableview for edit/add/remove "instances" of the entity. Now I can manual add and save but I would like to a) save automaticly changes b) add automaticly some "instances" with the first start. I think a) can be solved with NSNotifications. But which to use by entities? ...

Preserving window position in Interface Builder

Is there a way to preserve window position in Interface Builder? Every time I reopen a nib file, the MainWindow.xib window finds its way back to the top left of the screen, behind the window containing the interface I'm laying out. Moving it back to where I had it before every time is starting to get on my nerves. Seems like there should...

Custom NSControl target/action howto!

I have a custom NSControl that acts as sort of a two dimensional slider where you can drag a handle around the view. I added a few class specific methods and the only ones I overrode were the mouse actions and drawRect. My question is, how do I get it to implement target action? How can I make it behave like a slider and continuously sen...

How do I dispose of my own sharedInstance in Objective-C?

If I have a class that has a sharedInstance of itself (singleton pattern) or a shared instance of another class, how do I make sure that shared instance is released properly when my program exits? Better yet, can you point me to some documentation about this? sample class (with all other methods removed for clarity): @interface Foo : N...

How to use Mac OS X Cocoa events for multitouch gestures

I'm writing a program that has an NSView embedded in an NSScrollView which user can zoom. I'd love to set it up so the user can zoom the view using the multitouch pinch gesture supported on MacBook Air and the new unibody MacBooks/MacBooks Pro and in applications like Safari and iPhoto. I've hunted through Apple's documentation and can't...