objective-c

How do I detect if an application is document-based?

I'm developing a Cocoa/Objective C application that reads the active document from any application using AppScript. I've done this part successfully, but it would be really good to be able to tell for sure whether the application is document-based or not. The obvious approach is to look at the AXDocument attribute of the active window w...

SQLite - a smart way to remove and add new objects

Hi, I have a table in my database and I want for each row in my table to have an unique id and to have the rows named sequently. For example: I have 10 rows, each has an id - starting from 0, ending at 9. When I remove a row from a table, lets say - row number 5, there occurs a "hole". And afterwards I add more data, but the "hole" is s...

How to create multiple buttons dynamically and handle their separate events? + iPhone SDK

Hi All, Now I am creating a IPhone App. I need to create multiple buttons dynamically and handle their corresponding events separately. Can each button events behave separately, or can I send a variable or an object to a method and depending upon that value differentiate the button behavior. Can anybody point me to how to do that? Plea...

Best approach to debugging applicationDidReceiveMemoryWarning on iPhone?

Need advice on how to debug this. I'm new with limited environments and have no previous embedded or smart phone programming experience so I could use some clues. Already aware of: Instruments, Clanger Static Analysis, manual code review, etc. Instruments seems to be very helpful in general but quite time consuming and freezes up a lot o...

Detecting iPhone/iPod Touch Accessories

I've been searching and can't seem to find the answer elsewhere - is it possible to detect if the iPod Touch/iPhone has any headphones or other accessories connected to it? I'm building an app that requires a microphone, and need to know if the "iSomething" has one connected or not, either via the dock connection, or using the headphone...

SQLite database - cannot see updates

Hi, I have a sqlite database and I am adding to it new words. The problem is that I can see them added to a table only after restarting application. The "SELECT" statement doesn't "see" newly added elements before restarting application. Why may this happen? I am creating some kind of a dictionary. Here is how I add new items: const ...

How do i add button style cells to table views in iPhone apps?

I'm not able to find any specific examples in apple's documentation on this. I want to add two to three buttons to a table view programmatically, much like the contacts app does with the send text message/ add to favorites buttons on a contacts's info. does anyone know how to configure this? ...

Is this a valid use of an Objective-C pointer?

This is a beginner level question in which I'm curious if this is a valid use of a pointer in a statement such as: NSMutableDictionary *foo = [bar mutableCopy]; I get confused when that is valid versus when I'd need to do the following: NSMutableDictionary *foo = [[NSMutableDictionary alloc] initWithCapacity:0]; foo = [bar mutableCo...

String replacement in Objective-C

What is the best way to replace a character is a string in Objective-C for iPhone SDK? ...

UITouch movement speed detection

I'm trying to detect the speed of touch movement and i'm not always getting the results I'd expect. (added: Speed spikes around too much) Can anyone spot if i'm doing something funky or suggest a better way of doing it ? - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ self.previousTimestamp = event.timestamp; } - ...

NSMutableArray as @property with readonly

Suppose I have something like this: @property (readonly) NSMutableArray *someArray; Can I modify [obj someArray] even though the @property is set to readonly? ...

Is Objective-C on Linux garbage collected?

Objective-C v2.0 (which is what the mac uses) got a new feature, Garbage Collection. I'm a kid on a Linux PC (Ubuntu in case your wondering). So my question is, using the gcc/g++ compiler is Objective-C Garbage Collected? ...

Emacs, Objective-C, and autocomplete

I recently switched to emacs for my code editing, and it mostly works well. However, for Objective-C I find myself missing Xcode's autocomplete feature as I have trouble remembering the long function names such as - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType d...

SQLite - sorting a table

Hi, I have a database in SQLlite and I'd like to sort my table in an alphabetical order. How can I do it? Is there a way to sort entries using only SQLite or do I have first to read a table into an array, sort it and afterwards to write it into a database? Here is my query: "SELECT entry FROM table WHERE id=?" I need to get data from t...

NSTextField with "padding" on the right

I am trying to get the "remaining chars notice" to show up within my rounded NSTextField and I got it with two NSTextFields with help of the Interface Builder and it already looks like that: But when I write a little bit more it looks like that: The only thing I could think of is to subclass NSTextField and do something with it so ...

Weird leak when using [NSStringObject UTF8String]

I have this function: -(void) debugPrint { printf("name: %s", [_name UTF8String]); } This results in a runtime error: [Session started at 2009-03-21 15:02:26 -0700.] 2009-03-21 15:02:26.319 TGui[20063:10b] *** _NSAutoreleaseNoPool(): Object 0x10a290 of class NSCFData autoreleased with no pool in place - just leaking Stack: (0x923...

Displaying a URL in a UITableViewCell in a different color from the rest of the text.

I'm working through the Stanford iPhone programming course online. The Presence app assignment pulls Twitter and displays each one in a separate UITableViewCell. Updates often include URL's and I'd like to know how to display just the URL text in blue, having it be tappable. I can parse the text for URL's with no problem, just no idea...

Layer.frame not updated after CAKeyframeAnimation?

Hi, I'm trying to animate a layer's position. It animates, but it's frame property is not updated at the end of the animation, it seems only its presentationLayer is. Here's what I'm doing: CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint (path, NULL, layer.frame.origin.x, layer.frame.origin.y); CGPathAddLineToPoint(p...

How to change the frame rate of a core animation instance?

Take CABasicAnimation for example. How do you lower the frame rate (overhead)? Animations run smooth, but my touchesMoved method skips a beat. Want to reduce the animation frame rate so touchesMoved is not skipping movements. ...

Wrap NSButton title

Any way to have a NSButton title to wrap when it's width is longer than the button width, instead of getting clipped? I'm trying to have a radio button with a text that can be long and have multiple lines. One way I thought about having it work is to have an NSButton of type NSRadioButton but can't get multiple lines of text to work. ...