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 is an object-oriented programming language combining features of C () and Smalltalk (). It is a strict superset of C (any valid C code is equally valid Objective-C code, with the minor exception that id is a free identifier for user use in C while it is a keyword in Objective-C), and it inherits its object-oriented capabilities from Smalltalk. All procedural syntax is identical to that of C, and all object-oriented syntax is an implementation of Smalltalk messaging.

Objective-C was created primarily by Brad Cox and Tom Love in the early 1980s at their company Stepstone. It is now primarily developed by Apple, Inc.

Objective-C is a general-purpose, high-level, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It is the main programming language used by Apple for and and their respective APIs, and .

Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods. It also adds language-level support for object graph management and object literals while providing dynamic typing and binding, deferring many responsibilities until run time.

Hello World in Objective-C

#import <Foundation/Foundation.h>

int main(void)
{
    NSLog(@"Hello World!");
    return 0;
}

Syntax

Objective-C is a thin layer on top of C, and moreover is a strict superset of C; it is possible to compile any C program with an Objective-C compiler, and to freely include C code within an Objective-C class. Objective-C derives its object syntax from Smalltalk. All of the syntax for non-object-oriented operations (including primitive variables, pre-processing, expressions, function declarations, and function calls) is identical to that of C, while the syntax for object-oriented features is an implementation of Smalltalk-style messaging.

Objective-C has many powerful features as detailed below:


References

Frequently posted questions in the Objective-C tag

Books

Video Tutorial

  • Developing iOS 7 Apps for iPhone and iPad by Stanford University - FREE
    From the site, "Tools and APIs required to build applications for the iPhone and iPad platform using the iOS SDK. User interface designs for mobile devices and unique user interactions using multi-touch technologies. Object-oriented design using model-view-controller paradigm, memory management, Objective-C programming language." (Similar courses are also available for iOS 8 & 9, but only in Swift)

Related Tags

292452 questions
326
votes
22 answers

Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:

So I was making an rss reader for my school and finished the code. I ran the test and it gave me that error. Here is the code it's referring to: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath…
Nick Scottman
  • 3,289
  • 2
  • 14
  • 8
324
votes
7 answers

Why I get the console warning: [Process] kill() returned unexpected error 1 when I load a WKWebView in iOS13.2?

Since I installed the iOS 13.2 beta, I have been getting a debug console error message. It happens every time I load a ViewController with a WKWebView object in the storyboard. Then the following message is shown continuously while the web view is…
L33MUR
  • 4,002
  • 2
  • 12
  • 27
324
votes
9 answers

Differences between strong and weak in Objective-C

What are the differences between strong and weak in @property declarations of pointers to objects? Also, what does nonatomic mean?
Mark Pegasov
  • 5,109
  • 9
  • 26
  • 30
320
votes
8 answers

How do I create a category in Xcode 6 or higher?

I want to create a category on UIColor in my app using Xcode 6. But the thing is that in Xcode 6 there is no Objective-C category file template. Is there any option to create a category in Xcode 6?
Yalamandarao
  • 3,852
  • 3
  • 20
  • 27
319
votes
18 answers

Detect current device with UI_USER_INTERFACE_IDIOM() in Swift

What is the equivalent of UI_USER_INTERFACE_IDIOM() in Swift to detect between iPhone and iPad? I get an Use of unresolved identifier error when compiling in Swift.
Berry Blue
  • 15,330
  • 18
  • 62
  • 113
318
votes
7 answers

Why does viewWillAppear not get called when an app comes back from the background?

I'm writing an app and I need to change the view if the user is looking at the app while talking on the phone. I've implemented the following method: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; …
Philip Walton
  • 29,693
  • 16
  • 60
  • 84
317
votes
23 answers

UITableview: How to Disable Selection for Some Rows but Not Others

I am displaying in a group tableview contents parsed from XML. I want to disable the click event on it (I should not be able to click it at all) The table contains two groups. I want to disable selection for the first group only but not the second…
Warrior
  • 39,156
  • 44
  • 139
  • 214
313
votes
21 answers

How to control the line spacing in UILabel

Is it possible to reduce the gap between text, when put in multiple lines in a UILabel? We can set the frame, font size and number of lines. I want to reduce the gap between the two lines in that label.
Abhinav
  • 37,684
  • 43
  • 191
  • 309
312
votes
2 answers

Why does Apple recommend to use dispatch_once for implementing the singleton pattern under ARC?

What's the exact reason for using dispatch_once in the shared instance accessor of a singleton under ARC? + (MyClass *)sharedInstance { // Static local predicate must be initialized to 0 static MyClass *sharedInstance = nil; static…
Proud Member
  • 40,078
  • 47
  • 146
  • 231
309
votes
35 answers

UIImageView missing images in Launch Screen on device

I have an app that supports iOS8 and later, built in Xcode 7 and I am using a XIB for a Launch Screen (I do not have launch images). The view contains a single UILabel with the app version, and 2 UIImageViews with images that are both present in…
MFW
  • 3,101
  • 2
  • 11
  • 3
308
votes
12 answers

UIRefreshControl without UITableViewController

Just curious, as it doesn't immediately seem possible, but is there a sneaky way to leverage the new iOS 6 UIRefreshControl class without using a UITableViewController subclass? I often use a UIViewController with a UITableView subview and conform…
Keller
  • 17,051
  • 8
  • 55
  • 72
307
votes
13 answers

How to use NSURLConnection to connect with SSL for an untrusted cert?

I have the following simple code to connect to a SSL webpage NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url]; [ NSURLConnection sendSynchronousRequest: urlRequest returningResponse: nil error: &error ]; Except it gives an…
erotsppa
  • 14,248
  • 33
  • 123
  • 181
307
votes
21 answers

UIActivityViewController crashing on iOS 8 iPads

I am currently testing my app with Xcode 6 (Beta 6). UIActivityViewController works fine with iPhone devices and simulators but crashes with iPad simulators and devices (iOS 8) with following logs Terminating app due to uncaught exception…
Bhumit Mehta
  • 16,278
  • 11
  • 50
  • 64
304
votes
7 answers

How do you print out a stack trace to the console/log in Cocoa?

I'd like to log the call trace during certain points, like failed assertions, or uncaught exceptions.
robottobor
  • 11,595
  • 11
  • 39
  • 37
303
votes
13 answers

Make a float only show two decimal places

I have the value 25.00 in a float, but when I print it on screen it is 25.0000000. How can I display the value with only two decimal places?
ron