Questions tagged [objective-c]
This tag should be used only on questions that are about Objective-C features or depend on code in the language. The tags [cocoa] and [cocoa-touch] should be used to ask about Apple's frameworks or classes. Use the related tags [ios], [macos], [apple-watch] and [tvos] for issues specific to those platforms.
objective-c
36,442
questions
1500
votes
44
answers
525k
views
Passing data between view controllers
I'm new to iOS and Objective-C and the whole MVC paradigm and I'm stuck with the following:
I have a view that acts as a data entry form and I want to give the user the option to select multiple ...
1138
votes
17
answers
380k
views
How do I call Objective-C code from Swift?
In Swift, how does one call Objective-C code?
Apple mentioned that they could co-exist in one application, but does this mean that one could technically re-use old classes made in Objective-C whilst ...
1792
votes
98
answers
654k
views
How can I make a UITextField move up when the keyboard is present - on starting to edit?
With the iOS SDK:
I have a UIView with UITextFields that bring up a keyboard. I need it to be able to:
Allow scrolling of the contents of the UIScrollView to see the other text fields once the ...
1324
votes
27
answers
486k
views
How do I sort an NSMutableArray with custom objects in it?
What I want to do seems pretty simple, but I can't find any answers on the web. I have an NSMutableArray of objects, and let's say they are 'Person' objects. I want to sort the NSMutableArray by ...
774
votes
20
answers
386k
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?
332
votes
26
answers
185k
views
What should my Objective-C singleton look like? [closed]
My singleton accessor method is usually some variant of:
static MyClass *gInstance = NULL;
+ (MyClass *)instance
{
@synchronized(self)
{
if (gInstance == NULL)
gInstance =...
1371
votes
18
answers
341k
views
How can I disable ARC for a single file in a project?
I am using ARC successfully in my project. However, I have encountered a few files (e.g., in unit tests and mock objects) where the rules of ARC are a little more fragile right now. I recall hearing ...
174
votes
4
answers
49k
views
What is the best way to deal with the NSDateFormatter locale "feature"?
It seems that NSDateFormatter has a "feature" that bites you unexpectedly: If you do a simple "fixed" format operation such as:
NSDateFormatter* fmt = [[NSDateFormatter alloc] ...
584
votes
26
answers
296k
views
dispatch_after - GCD in Swift?
I've gone through the iBook from Apple, and couldn't find any definition of it:
Can someone explain the structure of dispatch_after?
dispatch_after(<#when: dispatch_time_t#>, <#queue: ...
1948
votes
28
answers
536k
views
What's the difference between the atomic and nonatomic attributes?
What do atomic and nonatomic mean in property declarations?
@property(nonatomic, retain) UITextField *userName;
@property(atomic, retain) UITextField *userName;
@property(retain) UITextField *...
113
votes
11
answers
26k
views
When to use -retainCount?
I would like to know in what situation did you use -retainCount so far, and eventually the problems that can happen using it.
Thanks.
422
votes
12
answers
101k
views
How dangerous is it to compare floating point values?
I know UIKit uses CGFloat because of the resolution independent coordinate system.
But every time I want to check if for example frame.origin.x is 0 it makes me feel sick:
if (theView.frame.origin.x ...
908
votes
36
answers
532k
views
How to check iOS version?
I want to check if the iOS version of the device is greater than 3.1.3
I tried things like:
[[UIDevice currentDevice].systemVersion floatValue]
but it does not work, I just want a:
if (version > ...
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.
274
votes
28
answers
162k
views
How to force NSLocalizedString to use a specific language
On iPhone NSLocalizedString returns the string in the language of the iPhone.
Is it possible to force NSLocalizedString to use a specific language to have the app
in a different language than the ...