objective-c

Cost/benefit of multi-threaded text processing

I am working on a real-time syntax highlighter for the iPhone and I have created a custom UIView that takes a string, parses it and then highlights it in its drawRect: method. I've also implemented a blinking cursor. However, it is starting to get a little slow and I think that when I implement multi-line processing and chunk-processing,...

What's the best way to use Obj-C 2.0 Properties with mutable objects, such as NSMutableArray?

I have an Obj-C 2.0 class that has an NSMutableArray property. If I use the following code, then the synthesised setter will give me an immutable copy, not a mutable one: @property (readwrite, copy) NSMutableArray *myArray; Is there any reason that Apple didn't implement the following syntax? @property (readwrite, mutablecopy) NSMuta...

Can you access application delegate from within a UITableViewDataSource function?

I'm trying to figure out the SQLite functionality for the iPhone, and I'm having some problems reading my database file from an overridden UITableViewDataSource function. I am storing the database file location in an ivar (as an NSString) in my application delegate, however when I try to access that string from an overridden UITableViewD...

Unit testing with NSURLConnection

Hello! I want to test a piece of code that uses network (the NSURLConnection class, to be specific). The code (let’s call it NetworkManager) looks a bit like this: - (id) buildConnection { // some more code and then: return [NSURLConnection …]; } - (void) startNetworkSync { id connection = [self buildConnection]; //… }...

How do I make and use a Queue in Objective-C?

I want to use a queue data structure in my Objective-C program. In C++ I'd use the STL queue. What is the equivalent data structure in Objective-C? How do I push/pop items? ...

How do I Sort Collections in Objective-C?

I have an integer array in my Objective-C program. I'd like to sort it (ascending or descending, doesn't matter). In C++ I'd use the sort algorithm in the STL Algorithm library. How can I do this? ...

UILabel memory leak?

I have an NSTimer that fires off every second, and on that second I update a UILabel by setting the text property like so: remainglbl.text = [NSString stringWithFormat:@"%i:%02i", var1, var2]; It works fine, but when I run it in xcode with Start With Performance Tool -> Leaks, it appears that the memory just keeps on climbing and clim...

UITableView - add cells

I have a UITableViews inside of a TabBarController that are populated with separate arrays of data. Due to web syncing, this array updates, and I'd like to update the table. Calling: [self.tableView reloadData] will reload content in existing cells, but I need to add cells for the new data. It seems that this method is not calling -...

Execute Method Without Delay

I have a few methods inside my view controller that load up for future actions, I call them all within a single method so ie: - (void) updateSongInformation { artistName.text = @"Testing"; [self setupEmail]; [self checkStatus]; } If I take out the last 2 lines, the UILabel is updated instantaneously. Is there a way to r...

Objective-C 2.0; Assigning a Property; Leaking Memory?

I'm still learning about Objective-C memory management. I'm trying to implement several simple classes in an example program that I'm building. As an example, say I have the following class definition: #import <UIKit/UIKit.h> @interface customViewController : UIViewController { customObject *myCustomObject; } @property (ret...

How do I populate an NSPopupButton with an array of strings?

Simple question, but I am struggling a little to understand how Interface Builder interacts with the rest of the program developed in X-Code. My UI has an NSPopupButton that I would like to fill with an array of strings that I provide. I have a controller class that defines the method to execute when the button is clicked. Is that wher...

Drag-and-drop files onto an NSTableView?

I have an NSTableView which I wish to allow users to drag-and-drop video files onto. When they drop the file, it'll get added as a row in the table view. How would I go about doing this? Currently the tableview's takes its data from an Array Controller (which takes its data from a NSMutableArray) I found this documentation, but cannot ...

How do you test an asynchronous method?

I have an object that fetches XML or JSON over a network. Once this fetching is complete it calls a selector, passing in the returned data. So, for example I'd have something like: -(void)testResponseWas200 { [MyObject get:@"foo.xml" withTarget:self selector:@selector(dataFinishedLoading:)]; } I tried the route of implementing ...

What should I replace this code with?

I recently got an example of some code from a friend but he told me one line needs to be changed to make it work for me. Here's the code: - (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn: (NSTableColumn *)aTableColumn row:(int)rowIndex { if ([aCell respondsToSelector:@selector(setTextColor:)]) {...

Save NSMutableArray to disk

Hello, I have an NSMutableArray that holds objects of the type Person (NSString,NSString,int) I am looking for a easy way to save this array to disc and load it again later. I read alot about serialization but I never have done that. Maybe it's not the easiest way for me after all. ...

Flipping Quicktime preview & capture

I need to horizontally flip some video I'm previewing and capturing. A-la iChat, I have a webcam and want it to appear as though the user is looking in a mirror. I'm previewing Quicktime video in a QTCaptureView. My capturing is done frame-by-frame (for reasons I won't get into) with something like: imageRep = [NSCIImageRep imageRepWit...

Accessing DOM Webkit Objective C

Could someone who is familiar with webkit please explain or point me in the right direction as to why the following code does not work What i'm trying to do is load a page, have webkit parse it and simply print out the title. Here is what i've got: #include <iostream> #include <WebKit/WebKit.h> using namespace std; /* Seek Help */ ...

How do you sync a Core-Data application between a Mac and a iPhone?

Just wondering what code I would need to do this? ...

Objective-C/Cocoa: Proper design for delegates and controllers.

Consider the following common situation: You have some MainView in your Cocoa application, loaded from a NIB, which is controlled by a MainViewController. Your MainView contains some controls, such as a UILabel infoLabel. You also have a delegate MyDelegate class which receives some sort of event. You would like to make sure that whe...

Taking an RGB color and normalizing it with UIColor on the iPhone

Hey all, I'm looking for a straight forward way to convert a color from RGB, grabbing it from a tool like Photoshop, then convert it to a UIColor. Since UIColor uses normalized gamut of 0.0 to 1.0 for each color space, I'm not sure how this is done. Thanks for the solution. ...