objective-c

Using the Cocoa framework, when setting a label, an explicit cast to NSString works but stringValue raises an exception. Why?

I'm setting a UILabel to a value stored in as a NSNumber. If I do this foo.label.text = [bar stringValue]; then I get a NSInvalidArgumentException However if I cast by doing: foo.label.text = (NSString *)bar; then things work ok. Can anyone explain why this could be the case? ...

[iPhone] Why does dot notation work and not brackets?

Hi, So I'm calling this: [leftSwitch hidden:NO]; but the iPhone Simulator just crashes (no compiler errors) when I click on the Segmented Control that calls the IBAction that this code is from. However, as soon as I change this to: leftSwitch.hidden = NO; it works...I made no other changes. ...

Declaring two classes that contain instance variables of each others' types.

Let’s say you wish to have two classes like so, each declaring an instance variable that is of the other’s class. @interface A : NSObject { B *something; } @end @interface B : NSObject { A *something; } @end It seems to be impossible to declare these classes with these instance variables. In order for A to include an IV o...

How to convert an NSString to hex values

I'd like to convert a regular NSString into an NSString with the (what I assume are) ASCII hex values and back. I need to produce the same output that the Java methods below do, but I can't seem to find a way to do it in Objective-C. I've found some examples in C and C++ but I've had a hard time working them into my code. Here are the ...

Objective C: CoreData and aggregation

Given a CoreData-Entity with an date (days) and an ammount called Transaction. Is it with CoreData possible (and how) to aggregate/group the 'table' (with all Transactions) by Date and calculate the sum of the day in a second column/attribute? (the SQL-Solution would be SELECT date, sum(ammount) FROM transaction GROUP BY date) ...

How to chop off file:// from NSURL

I have an NSURL. It is file://localhost/Users/Me/File.xml I want an NSString that is /Users/Me/File.xml Is there some nice function I can use to do this? ...

How to Schedule Method call in Objective C

Hi, I am try to do multi-threading in Objective C. What I want to do now is that, for some instance of objects, I want to have to way to call some function 5 seconds later. How can I do that? In Coco 2D, it's very easy to do it. They have something called scheduler. In Objective C, how to do it please? Thanks ...

making an apple-scriptable application in Objective C, getting bizarre errors

Ok, so I've got an application, and I want to make it scriptable. I set up the plist, I set up the sdef file. So far I have only one apple Event command: gotoPage. it takes an integer. and returns a boolean. The relevant XML is: <command name="gotoPage" code="dcvwgoto" description="Goto a specified page"> <cocoa class="A...

Generating a perfectly distributed grid from array

I'm looking for a formula or rule that will allow me to distribute n characters into a n*n grid with as perfect of a distribution as possible. Let's say we have an array of 5 characters, A through E. Here's an example of how it definitely shouldn't turn out: A B C D E B C D E A C D E A B D E A B C E A B C D With this pattern, the lett...

Declared Properties and assigning values with self

I understand how declared properties work - I just need a clarification on when Objective C is using the accessor method vs. when it is not. Say I have a property declared using retain: @property (nonatomic, retain) NSDate *date; ... and later... @synthesize date If I say: date = x Is that calling the accessor method? Or is it just ...

Can I mix OpenglES with standard Cocoa widgets on an iPhone app?

In case this is possible, it would be nice to see some examples! Thanks, rui ...

Check if NSURL is Local File

This is a pretty simple question- how can I check if a NSURL is linking to a local file? I know, RTFM, but I checked the documentation and I don't seem to see any methods related to this. The only methods I did find were -isFileReferenceURL and -isFileURL, but I think these only check if the URL directly links to a file. note: I'm mak...

NSDictionary causing EXC_BAD_ACCESS

I am trying to call objectForKey: on an nsdictionary ivar, but I get an EXC_BAD_ACCESS error. The nsdictionary is created using the JSON-framework and then retained. The first time I use it (just after I create it, same run loop) it works perfectly fine, but when I try to access it later nothing works. I am doing this code to try to figu...

Facing error in apple multitasking code

Actually I am working for multitasking and facing error please assist me, as I need to work on background application and also in foreground application - (void)applicationDidEnterBackground:(UIApplication *)application { UIApplication* app = [UIApplication sharedApplication]; // Request permission to run in the backgroun...

iPhone Apps, Objective C, a Graph, and Functions vs. Objects (or something like that)

Gentleones, I've got a UIImageView that I have in a UIView. This particular UIImageView displays a PNG of a graph. It's important for this particular view controller and another view controller to know what the graph "looks like," i.e., the function described by the PNG graph. These other view controllers need to be able to call a "func...

How to implement a cache for web resources? NSURLRequest cache or disk caching?

I have several UITableViews that asynchronously load the images, video, and text from the internet using NSURLRequest and NSURLConnection (Think similar to NYTimes app). That works fine. Currently the content isn't cached. I don't need offline access but just want to cache to speed up performance. What would be best: Using NSURLReques...

What happens with unarchived objects?

After I've unarchived an object with NSKeyedUnarchiver, I am able to use it like usual, but I am unable to re-archive it. When I try, it crashes. [NSKeyedArchiver archiveRootObject:unarchivedObject toFile:fileName]; I tried looking in the developer resources in apple but I haven't seen a thorough explination of proper usage of NSKeyed...

Optimising Database Calls

I have a database that is filled with information for films, which is (in turn) read in to the database from an XML file on a webserver. What happens is the following: Gather/Parse XML and store film info as objects Begin Statement For every film object we found: Check to see if record for film exists in database If no film rec...

iphone integer multiplication

I don't understand why this doesn't work: [abc = ([def intValue] - 71) * 6]; '*' should be the viable way of doing multiplication and 'abc' is defined as an NSInteger. ('def' is an NSString) ...

What is the difference between moveBackward: and moveLeft: when using NSResponder -interpretKeyEvents:?

I'm implementing a custom text box using -interpretKeyEvents: and am trying to figure out what the difference is between moveBackward: vs moveLeft: and moveForward: vs moveRight:. moveLeft: is bound to the left arrow and moveBackward: is bound to Ctrl + B. The documentation describes them almost identically and they seem to behave identi...