objective-c

how to use dateWithTimeIntervalSinceNow fun?

can anybody has sample code to show. ...

What is the best way to define string constants in an objective-c protocol?

I have defined a protocol that all my plug-ins must implement. I would also like the plug-ins to all use certain strings, like MyPluginErrorDomain. With integers this is quite easily achieved in an enum, but I can't figure out how to do the same with strings. Normally, in classes I would define extern NSString * const MyPluginErrorDoma...

How to close the front application window using cocoa objective c

i want to close the front window of my application. can anybody help me? ...

memory management guidelines on foundation functions

While memory management for the foundation classes are consistent and documented, i was surprised to find (via the friendly EXC_BAD_ACCESS) that Foundation functions like e.g NSStringFromSelector() seem to return pointers to constant storage - which is at least not mentioned in the documentation for the function. Is that behaviour docum...

Pull-up refactoring, Objective-C

I have two similar classes, MultiSlotBlock and SingleSlotBlock. They have started to share a lot of common code so I have decided to do some refactoring and pull some of the methods up to a new superclass, let's call it Block. Now one of the methods that I pull up, simplified for the example, looks like this: // (Block.mm) - (void)...

download web page data in objective-c iphone ?

How you get web page data and set the data to string ? somthing like : NSString *str = GetWebPageData("www.mysite.com/webpage.html"); in the str, i will see "html my web page html" for example ...

Play m4p with AudioQueue

Is it possible to play protected m4p files with AudioQueue? I tried NSSound (it can play m4p) and the AudioQueue sample afplay (does not work otb). Is there any way to play m4p with AudioQueue? ...

How to center NSSegmentedControl

Hi, I've added an NSSegmentedControl to a pane on an horizontal split view on a normal window. I thought that adjusting the springs would make the segmented control centre itself automatically, but it doesn't. How can keep it centred? I was told to add an observer for when the parent view's frame changes, and manually adjust the positi...

Copy Directories With copyItemAtPath?

I am trying to copy the directory "DATA_001" (and its contents) into the directory "CRYO". I was under the impression that I could do this using copyItemAtPath like I would for a file? Is this the wrong way to be doing this? NSString *sourceDir = @"/Users/Fuzzygoat/Documents/DATA_001"; NSString *destDir = @"/Users/Fuzzygoat/Documents/...

getting google translate api for iphone

hi, i want to use google translate api from the iphone. what i found is : http://code.google.com/p/gdata-objectivec-client/ but in the list i can not see the translate api. where i can found the library ? thanks. ...

NSThread object retained twice?

I have a class derived from NSThread: @interface FSEventMonitorThread : NSThread { FSEventStreamRef m_fseStreamRef; CFRunLoopRef m_runLoop; } - (id) initWithStream: (FSEventStreamRef)fseStreamRef; - (void) dealloc; - (void) main; @end @implementation FSEventMonitorThread - (id) initWithStream: (FSEventStreamRef)fse...

Using Scanf with ObjC and iPhone

Hi, trying to make an iPhone app and going through the tutorials and books recommended by those before me :) I'm trying to find information on the scanf/storing user input data from a text field into a variable which I can use later in my program. The text field is actually a number field, so I am trying to save the integers they input a...

'TileMap' may not respond to '+mapNamed:'

Here's an odd one. I have a class named TileMap with the following interface: @interface TileMap : NSObject { int *data; int tilesWide; int tilesHigh; NSString *imageName; } + (id)mapNamed:(NSString *)filename; - (id)initWithFile:(NSString *)filename; @end The implementation looks like this: @implementation TileMap + (id)mapNa...

Objective C - how to get current screen resolution?

Hi, is there any way to get the users screen resolution with objective c? Thanks. Solution: int width = [[NSScreen mainScreen] frame].size.width; int height = [[NSScreen mainScreen] frame].size.height; ...

How do you tell if a key exists for an object using Key-Value Coding?

I'd like to test whether an object has a writeable @property in the iPhone SDK. One possible way of doing this is to check the -valueForKey: method, but that seems rather inelegant! Example: @try { id *value = [instance valueForKey:@"myProperty"]; } @catch (NSException * e) { // Key did not exist } Is there a better...

Trigger web-request when user scrolls to bottom of UITableView

Hi, i'm trying to get a UIActivityIndicatorView to "appear and animate" when a user scrolls to the bottom of a UITableView…. Upon reaching the bottom of the table view, a web-request is made that will take a few seconds to complete and then the UIActivityIndicatorView should "stop and hide" I'm triggering the appearance of the UIActivi...

What is the correct usage of arrayWithContentsOfURl?

This is a bit basic; I am trying to retrieve http data for an iPhone app. I have www.myhost.com/test.html that reads <array><string>test</string><string>test2</string></array> Then I have NSURL *baseURL = [NSURLRLWithString:@"http://www.myhost.com/test.html"]; NSArray *array = [NSArray arrayWithContentsOfURL:baseURL]; NSLog(@"%@", [...

Set programmatically a custom subclass of UINavigationBar in UINavigationController

Does anyone know how can I use my custom subclass of UINavigationBar if I instantiate Navigation Controller programmatically (without IB)? Drag a Navigation Controller in IB show me an under Navigation Bar and using Identity Inspectory I can change class type and set my own subclass of UINavigationBar but programmatically I can't: navi...

NSString - doubleValue is returning NaN from a viable NSString

Ok, so I am pulling an NSString from and NSMutableArray and storing it in an NSString: entry = [NSString stringWithString:[array objectAtIndex:row]]; This is wrapped inside of a couple different for-loops. I then convert it to a doubleValue and store it in a number but apparently [entry doubleValue] only returns a NaN instead of a num...

How to make use of sender parameter in IBAction-call

Within an action method such as - (IBAction)myAction:(id)sender { // do something } what can the sender parameter be used for? Is it possible to detect what type of click (such as left mouse down) was made on the control that invoked the action? If so how? ...