cocoa

Object ownership in stringWithString and initWithString in NSString

I understand that any init... method initializes a new object and that NSString stringWithString makes a copy of the parameter string as a new object. I also understand that being the objects' owner, I can control the release/deallocation of any objects that I allocate. What I don't understand is when would I use the stringWithString met...

Padding in NSTextView -- possible without custom drawing?

In Cocoa, NSTextView has a rather shallow margin between text and border. Is there a way to specify a padding (distance between text and border of view) for a NSTextView without resorting to owner drawing? ...

How are binding specified for Interface Builder plugins?

I'm creating an Interface Builder plugin for an NSView subclass. I've been following the Interface Builder Plug-in Programming Guide but it's not answer all my questions. My class has one NSString property and 4 NSColor properties which I want to create bindings for at design time. I can't figure out where the bindings are specified in ...

Encrypting data in Cocoa, decoding in PHP (and vice versa)

The situation I'm trying to solve: in my Cocoa app, I need to encrypt a string with a symmetric cipher, POST it to PHP, and have that script decode the data. The process needs to work in reverse for returning an answer (PHP encodes, Cocoa decodes). I'm missing something because even though I can get both the key and initialization vect...

How does Apple make the info.plist display its "Information Property List"?

My plists simply start with "Root". Theirs contains arrays of useful stuff you can select to tweak the configuration. The specific info.plist I am looking at is in an iphone project. I have researched this a little bit, (not alot) but haven't even detected a smell of solution. What mechanism is putting this together? Can I bend it to my...

Extracting 32-bit RGBA value from NSColor

I've got an NSColor, and I really want the 32-bit RGBA value that it represents. Is there any easy way to get this, besides extracting the float components, then multiplying and ORing and generally doing gross, endian-dependent things? Edit: Thanks for the help. Really, what I was hoping for was a Cocoa function that already did this,...

Objective-C @class vs. #import

It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an #import it a simple ifndef so that an include only happens. My inquiry is this. When does one use #import ...

MVC architecture question for Mac application.

I have a controller class from which I call a method of model class. Now from this model class method I want to update textView object which is a data member of controller class continuously. I have method in the controller class to edit this textView. I tried creating a controller object from the model class method and edited the textVi...

Mounting a folder as a device in Finder using Cocoa

Is there a way to mount a folder on the hard disk as a device in Finder. The intend here is to provide the user with an easy way to get to a folder that my application uses to store data. I don't want my user to go searching for data in Application Data. I would rather allow them to make this data available as a mounted volume or device ...

How do I get keyboard events in an NSStatusWindowLevel window while my application is not frontmost?

After creating a translucent window (based on example code by Matt Gemmell) I want to get keyboard events in this window. It seems that there are only keyboard events when my application is the active application while I want keyboard events even when my application isn't active but the window is visible. Basically I want behavior like...

how to block a superclass method to be called to a subclass

I'm extending the functionality of a class with a subclass, and I'm doing some dirty stuff that make superclass methods dangerous (app will hang in a loop) in the context of the subclass. I know it's not a genius idea, but I'm going for the low-hanging fruit, right now it's gonna save me some time. Oh it's a dirty job, but someone's gott...

how to throw an exception in objective-c/cocoa?

what's the best way to throw an exception in objective-c/cocoa? ...

Should +initialize/+load always start with an: if (self == [MyClass class]) guard?

When implementing an +initialize or +load method in one of your Objective-C classes, should you always start with this kind of guard?: @implementation MyClass + (void)initialize { if (self == [MyClass class]) { ... } } ... @end Seems like code in +load and +initialize usually only wants to be executed once. So this w...

Object Scope - Objective C Question

This is a program I'm writing (myself as opposed to copying someone else's and thus not learning) as part of the ObjectiveC and Cocoa learning curve. I want to draw simple shapes on a NSView (limiting it to ovals and rectangles for now). The idea is that I record each NSBezierPath to an NSMutableArray so I can also investiagte/implement ...

Posix Error 14 (bad address) on open read stream in Cocoa. Hints?

I'm following the sample code in CFNetwork Programming Guide, specifically the section on Preventing Blocking When Working with Streams. my code is nearly identical to theirs (below) but, when I connect to my server, I get posix error 14 (bad address -- is that bad IP address (except it's not)? Bad memory address for some call I made? ...

What's the deal with NSZoneFree in -(void)dealloc?

In Apple's NSObject documentation, NSZoneFree is called in the - (void)dealloc example code: - (void)dealloc { [companion release]; NSZoneFree(private, [self zone]) [super dealloc]; } You can find it in context over here. I never had the notion that I should be calling NSZoneFree in my own NSObject subclasses (or what NS_...

Shark: how to filter down to one specific method

I'm new to Shark, and I was wondering if it's possible to narrow down a time sample to one specific method? Let's say I'd like to, just for the sake of it, know how much resources have been used on calls to the method 'count' for all NSArray (or subclasses) instances. ...

NSApplication delegate and Preference Panes

It seems that I can't control the NSApp delegate from within a System Preferences pane, which is understandable. Is there any other way I can have my object notified when the program becomes active? ...

event scope

Hi all! Given @interface Canvas:NSView { NSNumber * currentToolType; ... } declared in my .h file and in the .m file - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { currentToolType=[[NSNumber alloc]initWithInt:1]; } return self; } and further down -(void)m...

setNeedsDisplay not working?

Hi all! I have a problem redrawing a custom view in simple cocoa application. Drawing is based on one parameter that is being changed by a simple NSSlider. However, although i implement -setParameter: and -parameter methods and bind slider's value to that parameter in interface builder i cannot seem to make a custom view to redraw itsel...