cocoa

How do you remove an object from an array ?

I was wondering how do you remove objects from an NSMutableArray, cause right now I use [astroids removeFromSuperview]; but it just gets rid of the image on screen but the instance itself is still present even when removed. ...

How to use @sum with CoreData

I have Week model that has Day as child objects. There is "days" relation property in Week model to access all associated Day objects. Day model has duration property. How can I figure out sum of day's durations for specified Week object? It would be great to have code example how to create a predicate object with @sum function. Also i...

Is libusb the preferred method on Mac OS X to access USB device?

Is libusb the preferred method to talk to a device over USB (using AT commands) on OS X these days? Is there any high level equivalent in cocoa? ...

Managing collections of tuples in Objective-C

I am fairly new to Objective-C and was wondering what the best way to manage collections of tuples was. In C I would use a 2D array or a struct. Should I be creating objects to contain these tuples? It seems like overkill for just sorting lists or is there no real extra load generated by object initialisation? ...

Interface-Builder outlets causing odd display behaviour

I've been working today on adding a sheet to the main window of my application. After having trouble seperating the two (main view/controller and sheet view/controller), I've gone with just having both views in the same xib and both controlled by the main controller. Now that it appears when the beginSheet method is called, I've designed...

@synthesize vs @dynamic, what are the differences?

what are the differences between implementating a @property with @dynamic or @synthesize?? thanks. ...

How do I save state with CALayers?

I have a simple iphone application that paints blocks using a subclass of CALayer and am trying to find the best way to save state or persist the currently created layers. I tried using Brad Larson's answer from this previous question on storing custom objects in the NSUserDefaults, which worked for persisting my subclass of CALayer, bu...

How do I manually highlight an NSPopUpButtonCell when drawing it (draw it using white instead of black)?

I've got a custom cell composed out of several cells, one of which is an NSPopUpButtonCell. When drawing my custom cell highlighted, I want to cause all the sub-cells to highlight as well (typically by turning white). With, for example an NSTextCell, if I call setHighlighted:YES before calling drawWithFrame:inView the cell will be draw...

Running sh script through AuthorizationExecuteWithPrivileges

Hi, I'm running an uninstallation script through cocoa app, and I noticed that launchctl command doesn't get executed. This is the part of the code that calls script (which contains sudo launchctl unload "name of the daemon") //pFileName is the name of the File NSString* pPath = [pCurrentBundle pathForResource:pFileName ofType:@"sh"]...

How can I make unicode characters from integers?

I want to make an array of Unicode characters, but I don't know how to convert integers into a Unicode representation. Here's the code I have so far NSMutableArray *uniArray = [[NSMutableArray alloc] initWithCapacity:0]; int i; for (i = 32; i < 300; i++) { NSString *uniString = [NSString stringWithFormat:@"\u%04X", i]; [uniArray addO...

Trying to grab integer from pre-defined p-list? ObjC/Cocoa

Hello, I'm working on an Objective-C/Cocoa roguelike, because I've always found that working on a game is the best way to learn about a language. I've gotten quite far with my game, but I'm having a problem. Each level.plist is defined with a few things, like so: <key>Save Location</key> <integer>0</integer> It's grabbed like so, I'...

customize Finder 'get info' window?

...

Best way to implement multiple levels within Objective-C roguelike?

I'm working on a roguelike using Objective-C/Cocoa to learn more. I've gotten most of the basic functionality out of the way, but I still have one problem I've been trying to figure out. Here's a breakdown of the process: First, the map is loaded: NSString* mapPath = [[NSBundle mainBundle] pathForResource:mapFileName ofType:mapFileTy...

Photoshop Plugin using Cocoa - How to get a preview

I'm implementing a Photoshop plugin on the Mac, and I'm doing it using Cocoa. Doing ok so far, but the next step is to provide a "preview" image, as a part of my plugin window, and I'm stuck. I'm a n00b Obj-C programmer, which isn't really helping :-) So far I've got something like this: int dataSize = gFilterRecord->bigDocumentD...

showsUserLocation with Location Services disabled

I have an MKMapView in my app and have a button that turns on showsUserLocation for the map, while the map is finding the location I display a spinner so the user knows its working. I know when to stop the spinner by adding NSKeyValueObserver to the map's userLocation property. However if the user has Location Services disabled then the ...

Cocoa (OSX) and CocoaTouch (iPhone) components in the same Xcode project file?

Is it possible to have an Xcode project file which contains both the Cocoa (MacOSX) and CocoaTouch (iPhone) versions of a component? I thought I was getting close until I realized that you need to set "Base SDK for All Configurations" in the Project Settings in order for the cross-compiler to be called (and for any CocoaTouch frameworks...

UserDefaults in system preference pane installed for multiple users in OSX...

Hi I have a background-only app that is controlled via a preference pane in the system preferences. To communicate between pref pane and app I use distributed notifications. User defaults are shared via [NSUserDefaults addSuiteNamed:]. This all works out very well. The problem occurs when the user installs the pref pane "for all users"...

Cocoa Touch: Accessor method + memory needs clarification

Please consider a problem constructing an array and returning it to a parent object. Please have a look at my code and comments below. My question is: Why does method THREE work while methods ONE and TWO do not? // **************************** // Master.m // **************************** // Simply declare array and call accessor NSMut...

Algorithm For Generating Unique Colors

I am looking for an algorithm that will generate a series of colors so that the colors will be as widely distributed as possible (so they won't easily be mixed up). I have a series of objects that have IDs that count up from 1. I would like to represent each of these with a different, aesthetically pleasing, color that won't get easily...

Can you manually implement Cocoa bindings?

I've had a crack at implementing bindings for my own NSView subclass. It works, but there are problems with retain cycles when binding to File's Owner from a nib file. After reading into it a little, I discovered that Apple had the same problem a few years back but have fixed it with some magic undocumented class (NSAutounbinder). There...