6,142 questions
1331
votes
82
answers
1.0m
views
Xcode - How to fix 'NSUnknownKeyException', Reason: "… this class is not key value coding-compliant for the key X" error?
I'm trying to link a UILabel with an IBOutlet created in my class.
My application is crashing with the following error"
***
Terminating app due to uncaught exception
'NSUnknownKeyException', ...
1412
votes
39
answers
517k
views
How can I check for an active Internet connection on iOS or macOS?
I would like to check to see if I have an Internet connection on iOS using the Cocoa Touch libraries or on macOS using the Cocoa libraries.
I came up with a way to do this using an NSURL. The way I ...
776
votes
20
answers
387k
views
How do I create delegates in Objective-C?
I know how delegates work, and I know how I can use them.
But how do I create them?
205
votes
11
answers
152k
views
How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?
I have a UIImage (Cocoa Touch). From that, I'm happy to get a CGImage or anything else you'd like that's available. I'd like to write this function:
- (int)getRGBAFromImage:(UIImage *)image atX:(int)...
19
votes
3
answers
3k
views
Getting date from [NSDate date] off by a few hours
I am using
NSDate *date = [NSDate date];
for getting the date, but the date I get is off by 2 hours.
193
votes
12
answers
79k
views
What's the Best Way to Shuffle an NSMutableArray?
If you have an NSMutableArray, how do you shuffle the elements randomly?
(I have my own answer for this, which is posted below, but I'm new to Cocoa and I'm interested to know if there is a better ...
158
votes
9
answers
53k
views
How does an underscore in front of a variable in a cocoa objective-c class work?
I've seen in a few iPhone examples that attributes have used an underscore _ in front of the variable. Does anyone know what this means? Or how it works?
An interface file I'm using looks like:
@...
1048
votes
14
answers
449k
views
Constants in Objective-C
I'm developing a Cocoa application, and I'm using constant NSStrings as ways to store key names for my preferences.
I understand this is a good idea because it allows easy changing of keys if ...
341
votes
6
answers
538k
views
How do I use NSTimer?
How do I use an NSTimer? Can anyone give me step by step instructions?
718
votes
16
answers
172k
views
@class vs. #import
It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular ...
336
votes
10
answers
139k
views
NSString property: copy or retain?
Let's say I have a class called SomeClass with a string property name:
@interface SomeClass : NSObject
{
NSString* name;
}
@property (nonatomic, retain) NSString* name;
@end
I understand that ...
634
votes
14
answers
231k
views
Cocoa: What's the difference between the frame and the bounds?
UIView and its subclasses all have the properties frame and bounds. What's the difference?
211
votes
12
answers
136k
views
Execute a terminal command from a Cocoa app
How can I execute a terminal command (like grep) from my Objective-C Cocoa application?
363
votes
25
answers
51k
views
Exception thrown in NSOrderedSet generated accessors
On my Lion app, I have this data model:
The relationship subitems inside Item is ordered.
Xcode 4.1 (build 4B110) has created for me the file Item.h, Item.m, SubItem.h and SubItem.h.
Here is the ...
103
votes
13
answers
95k
views
HTML character decoding in Objective-C / Cocoa Touch
First of all, I found this: Objective C HTML escape/unescape, but it doesn't work for me.
My encoded characters (come from a RSS feed, btw) look like this: &
I searched all over the net and ...