cocoa

@property attribute for NSNumber?

In the following am I right (keeping in mind the NSNumber is an object) to use assign with NSNumber? @property(assign) NSNumber *mass; Also if I used retain I would need to add a release, but if I created the NSNumber with an alloc would I not need to release twice, once for retain and once for alloc? @property(retain) NSNumber *mass...

Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple's built-in iSight? I've seen lots of tutorials on recording video but none on simply taking a picture. Any help or guidance is appreciated! Collin ...

In Cocoa, is there a way to programmatically resize a view (in this case a window) to fit all of it's subviews?

Think tic-tac-toe. You are creating the buttons in rows and columns and you want to set the width and height of the parent window (actually, the size of the window's contentView, right?). But maybe you want to sometimes use a 4x4 grid or 5x5, so you can't use a default window setting. I iterate and do math to determine the positioning o...

Updating UI when model is changed

I have a series of UITableViewCell elements with various UIControls to set model values. When I make a change to model, I am having difficulty finding a way to update the UITableViewCell that displays the calculated property from the model. I have placed the model in AppDelegate, and accessing it directly from RootViewController. ...

Cocoa Loading a ViewNib

When creating a nib, I have 2 types to create, a WindowNib or a ViewNib. I see the difference is, the window nib has a window, and a view. How do I load a view nib into another window? Do I have to create a WindowController and add a window then load the nib in the window? ...

Cocoa WebView cross-thread access

I have a C++ class running in its own thread that needs to execute some javascript in a WebView that's part of a Cocoa app. I have the C++ app call a method in the Cocoa window's controller and it in turns runs the javascript, passing in the data. It seems to work part of the time, but crash a lot of the time as well (somewhere in WebVie...

Using QCView and iSight to capture image

Hello all! I have a QCView that loads a Quartz file which gives you iSights feedback (basically like a QTCaptureView) Everything displays fine The button simply takes a snapshot using the following simple lines of code - (void)takePicture:(id)sender {NSImage *currentImage = [outputView valueForOutputKey:@"ImageOutput"]; [[currentImage...

Huge memory leak in NSBitmapImageRep

I have a method that analyzes pixel data inside an NSBitmapImageRep that is built from a CGImageRef. Here is the relevant code: CGImageRef ref; // omitted code for initializing ref NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:ref]; uint32* bitmapPixels = (uint32*) [bitmapRep bitmapData]; // do stuff with bitma...

How do I define a writable type for an application with a "Viewer" role?

I have an application that has the Viewer role for PDF files. Although my application does not edit the PDF files, it does allow the user to save the PDF file (if it is too large or complex for the workflow that my application handles). When the SaveDocumentAs: method is called, I get the following warning: Trying to save a document...

When should transient properties in CoreData be included in the object model?

I am unsure about the correct definition of transient properties: One can define transient properties in the object model and then calculate them when needed in the related class. But things work just as well if you specify a class and define arbitrary getter methods for any transient property without declaring it in the object model (...

How can I create a document-based application that cannot create a new document?

I have a document-based application that is designed to process existing documents, not to create new documents. How do I prevent the application from creating a new, blank document when launched by opening it from the Finder? ...

What are common Cocoa pitfalls?

Triggered by Mike Ash’s newest article “Dangerous Cocoa Calls” from his great Friday Q&A series, I want to know which are the things in Cocoa that made your code stumble. Mike has compiled a great list of evil API uses that are mostly about thread and exception safety. I’m sure that there are more hidden pitfalls that Cocoa programmers s...

Hashes in Cocoa and Objective-C

Hi, I'm writing an application for Mac. I need some code which generates a hash from a string. I need to create these hashes: MD2 MD4 MD5 SHA-0 SHA-1 How can I do this? Thanks. ...

Enqueue a selector to the run loop - is [NSObject performSelector:withObject:afterDelay:] the way to go?

Hi guys, I'd like to have a method be executed after the current method has passed and the UI has been updated. For that purpose, I'm using [object performSelector:@selector(someSelector) withObject:someObject afterDelay:0.0] right now. According to Apple's documentation, this creates a NSTimer which will then trigger and append the sel...

CGContextDrawImage leak

I have a custom view that draws an CGImage using: - (void) drawImage { CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; CGRect imageRect = {{0,0}, {CGImageGetWidth(image), CGImageGetHeight(image)}}; CGContextDrawImage(context, imageRect, image); } It looks like the memory used by the ...

componentsSeparatedByString for SFV files.

Hi, I'm having an NSString like this: music that rocks.mp3 e99a65fb The problem is that between the filename (musicthatrocks.mp3) and the CRC32 checksum (e99a65fb) there could be many more spaces then one. How can I split the line into an array? I thought of using componentsSeparatedByString, but my problem is that the filename ca...

How do you refer to each of these?

Can anyone tell me how I refer to these, is the first a system managed object and the second a user managed object, whats the terminology I should be using in objective-c / cocoa to refer to each of these? 01 +(Planet *) planet { gPlanetCount++; return [[[self alloc] init] autorelease]; } int main(int argc, const char * argv[]...

view hierarchy refresh timing

I'm trying to add a progress meter, or other "I'm busy right now" notification to my view hierarchy right before doing some intense computation that will block the UI. My code looks some thing like: //create view [currentTopView addSubView:imBusyView]; //some initialization for the intense computation [computation startComputing]; U...

how to display indicator

I cannot display Indicator View. ItemController.h #import <UIKit/UIKit.h> @interface ItemController : UITableViewController { UIView* loadingView; UIActivityIndicatorView* indicator; } @property (nonatomic, retain) UIView *loadingView; @property (nonatomic, retain) UIActivityIndicatorView *indicator; @end ItemController.m .....

How to limit the length of text for labels?

This could be really easy but I it's not obvious when I google it. I have few NSMenuItem items that get populated at runtime and the label can be very long.How do set a limit for the title with the "..." in the middle of the text? ...