objective-c

How do I cede focus to the previous application in Cocoa?

Let's saying the user is currently on Chrome. So I have a HUD that is invoked by a global hotkey, the user then types something into it and on clicking Close or OK, the HUD goes away (just using [NSPanel orderOut:]) but my application is still focused (i.e. the Menu bar of my application is still visible). But I want the focus to go back...

How to convert nib/xib to objective C code?

I am just wondering is there a way to convert nib/xib file to ojbective C code? I just want to find the equivalent code to the nib/xib file (I've tried nib2objc, seems the result is not what I am after). Actually I want to compile this example http://developer.apple.com/iphone/library/samplecode/TableSearch/index.html without nib/xib ...

How should my Cocoa application store the user's license key?

After the user enters his / her license key, my application activates itself with that key (online). How do I store this activated state and the license key so that the next time the user opens the app, the app will know that it is already activated? ...

Application expiration using NSTimeInterval

How would I set this method to display the alert panel 30 days from the initial launch of the application? -(void)awakeFromNib { NSDate * today = [NSDate date]; NSTimeInterval expiry = (); if ([today timeIntervalSinceReferenceDate] > expiry){ NSRunAlertPanel(@"Trial period has ended", @"Please Register", nil, nil, nil); NSLog(@"e...

Dim iPhone Screen, but don't let it sleep

Happy Holidays! Alright, so here is my question. I have found by using Google (Hurray, GIYF) that I can disable the iPhone going to sleep in an application by using: application.idleTimerDisabled = YES; so the code looks like this: - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for c...

iPhone Implementing a Favorites list without Core Data?

I would like to add a separate tableview to my application which would provide the user with a list of their favorite books, separate from the tableview of every book in the application. They should be able to add and delete favorites from this tableview. These favorites would then be saved so that they aren't lost whenever the applicati...

Are there any BSD or LGPL libraries for calculating amortization schedules?

I'm looking to do some testing of loan calculations on the Mac. I know what an amortization schedule is, and yes, I know how to convert an algorithm into code, but I'm don't want to worry about screwing up the rounding, or reinventing the wheel. Are there any Open Source C or Objective-C libraries that handle such calculations? I know...

Obj-C circular buffer object, implementing one?

Hi! I've been developing for the iPhone for quite some time and I've been wondering if there's any array object that uses circular buffer in Obj-C? Like Java's Stack or List or Queue. I've been tinkering with the NSMutableArray, testing it's limits... and it seems that after 50k simple objects inside the array - the application is signif...

Getting information from a button using (id)sender

So, this is pretty straight forward, but I'm not sure how to do it. To get a title from a button, you can use: NSString *title = [sender titleForState:UIControlStateNormal]; However, is there a way to get other information from the button such as the "Label" or "hint"? And if there isn't, I want to be able to have different actions...

NSString memory leak

//opening DB if(sqlite3_step(statement) == SQLITE_ROW) result = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement,0)]; //! else result nil; return result; //close DB ...

how to avoid memory leaking when calling function in backgroundThread

I have problem with memory leak when i call function in background thread like [self performSelectorInBackground:@selector(myFunctionName) withObject:nil]; when this function is called in background the following warning displayed: 2009-12-26 16:05:46.777 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0x63851d0 of class NSU...

Vertical UITabBar

I wanted to make a UITabBar that when device-Orientation changes the icons of the TabBar match. Anyone who has used a Palm Pre/ Web OS device camera will know what i mean. At this stage i'm just interested in hearing different approaches to the problem. My solution is (theoretical) Subclass UITabBar, listen for the orientation change, ...

Objective-c saving raw text.

Hi there! I implemented saving and loading methods in my document-based application. In the saving method, I have [NSArchiver archivedDataWithRootObject:[self string]]; Where [self string] is a NSString. When saving a file with just "normal content" inside of it, the contents of the file created are: streamtypedè@NSStringNSObjec...

- (void)applicationWillResignActive:(UIApplication *)application never gets called

I'm trying to handle phone calls and standby and things of that nature. I added the function - (void)applicationWillResignActive:(UIApplication *)application and - (void)applicationDidBecomeActive:(UIApplication *)application to my UIApplicationDelegate. When coming out of standby, "applicationDidBecomeActive" always gets called. ...

Battery Percentage - Getting An Accurate Test On Any iPhone

Hello all, I am looking for a way to run an accurate test on an iPhone and find how long it takes for battery percentage to drop. While considering this I thought Would the temperature of the battery make a difference to my result i.e If I took my iPhone outside and ran the test would it be consistent with the test I ran indoors? Does...

Obj-C selector not recognized on property?

I'm getting a NSObject doesNotRecognizeSelector error when trying to set a property and I'm not sure why. The error occurs on the first line of setWithNSColor. I'm a bit confused how a property that's properly synthesized could be not recognized. @interface ScopeColor : NSObject { NSString *colorIntegerString; float redColor; float gr...

Using performSelectorInBackground to load UITableViewCell image in background, performance

I have a method for loading images for UITableViewCell in the background. I use performSelectorInBackground. The problem is these threads are finishing and loading images even though they may not be on the screen anymore. This can be taxing on resources, especially when the use scrolls quickly and lots of cells are created. The images ...

NSUserDefaults - How to tell if a key exists

Alright, so I'm working on a small iPhone app, and I am using NSUserDefaults as my data persistence. It only has to keep track of a few things, such as some names and some numbers so I figure I might as well keep it simple. I found this page for some reference, but I don't think it can answer my question. Basically, I want to be able ...

Wrap text in a UILabel with quotes?

By default, UILabels truncate text and then put an ellipsis on the end. How might I wrap all the text, including the ellipse, in double quotes? ...

Objective C: Write a function to return the position of the last character in a UILabel?

A UILabel's text is drawn in a CGRect(x,y,size,width). The label can have multiple lines of text. Is it possible to write a function to return a CGPoint within this rectangle that designates the position of the last character? I ask because I am trying to wrap the text of a UILabel in an arbitrary prefix and suffix. The prefix/suffix n...