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
292,249
questions
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 *...
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 ...
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 ...
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 ...
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 ...
1302
votes
19
answers
192k
views
performSelector may cause a leak because its selector is unknown
I'm getting the following warning by the ARC compiler:
"performSelector may cause a leak because its selector is unknown".
Here's what I'm doing:
[_controller performSelector:NSSelectorFromString(@"...
1281
votes
21
answers
588k
views
How do I check if a string contains another string in Objective-C?
How can I check if a string (NSString) contains another smaller string?
I was hoping for something like:
NSString *string = @"hello bla bla";
NSLog(@"%d",[string containsSubstring:@"hello"]);
But ...
1177
votes
30
answers
847k
views
Shortcuts in Objective-C to concatenate NSStrings
Are there any shortcuts to (stringByAppendingString:) string concatenation in Objective-C, or shortcuts for working with NSString in general?
For example, I'd like to make:
NSString *myString = @"...
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 ...
1109
votes
13
answers
469k
views
What is a typedef enum in Objective-C?
I don't think I fundamentally understand what an enum is, and when to use it.
For example:
typedef enum {
kCircle,
kRectangle,
kOblateSpheroid
} ShapeType;
What is really being ...
1049
votes
12
answers
340k
views
How do I animate constraint changes?
I'm updating an old app with an AdBannerView and when there is no ad, it slides off screen. When there is an ad it slides on the screen. Basic stuff.
Old style, I set the frame in an animation block.
...
1047
votes
14
answers
448k
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 ...
949
votes
14
answers
467k
views
How do I convert an NSString value to NSData?
How do I convert an NSString value to NSData?
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 > ...
775
votes
20
answers
401k
views
How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?
Is there a way to call a block with a primitive parameter after a delay, like using performSelector:withObject:afterDelay: but with an argument like int/double/float?