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
343
votes
8 answers

Emulating aspect-fit behaviour using AutoLayout constraints in Xcode 6

I want to use AutoLayout to size and layout a view in a manner that is reminiscent of UIImageView's aspect-fit content mode. I have a subview inside a container view in Interface Builder. The subview has some inherent aspect ratio which I wish to…
chris838
  • 5,148
  • 6
  • 23
  • 27
343
votes
34 answers

UITableView Cell selected Color?

I have created a custom UITableViewCell. The table view is showing data fine. What I am stuck in is when user touches cell of tableview, then I want to show the background color of the cell other than the default [blue color] values for highlighting…
Mc.Lover
  • 4,813
  • 9
  • 46
  • 80
341
votes
6 answers

How do I use NSTimer?

How do I use an NSTimer? Can anyone give me step by step instructions?
lab12
  • 6,400
  • 21
  • 68
  • 106
339
votes
31 answers

UIScrollView scroll to bottom programmatically

How can I make a UIScrollView scroll to the bottom within my code? Or in a more generic way, to any point of a subview?
nico
  • 9,668
  • 8
  • 26
  • 28
338
votes
13 answers

Best architectural approaches for building iOS networking applications (REST clients)

I'm an iOS developer with some experience and this question is really interesting to me. I saw a lot of different resources and materials on this topic, but nevertheless I'm still confused. What is the best architecture for an iOS networked…
MainstreamDeveloper00
  • 8,436
  • 15
  • 56
  • 102
338
votes
89 answers

Hidden Features of Xcode

With a huge influx of newbies to Xcode, I'm sure there are lots of Xcode tips and tricks to be shared. What are yours?
schwa
  • 11,962
  • 14
  • 43
  • 54
336
votes
10 answers

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 name may be assigned a NSMutableString in which…
Debajit
  • 46,327
  • 33
  • 91
  • 100
333
votes
26 answers

What should my Objective-C singleton look like?

My singleton accessor method is usually some variant of: static MyClass *gInstance = NULL; + (MyClass *)instance { @synchronized(self) { if (gInstance == NULL) gInstance = [[self alloc] init]; } …
schwa
  • 11,962
  • 14
  • 43
  • 54
332
votes
17 answers

What is the best way to unit test Objective-C code?

What frameworks exist to unit test Objective-C code? I would like a framework that integrates nicely with Apple Xcode.
Kim
  • 4,593
  • 5
  • 21
  • 18
330
votes
8 answers

Can I use Objective-C blocks as properties?

Is it possible to have blocks as properties using the standard property syntax? Are there any changes for ARC?
gurghet
  • 7,591
  • 4
  • 36
  • 63
328
votes
12 answers

How to print Boolean flag in NSLog?

Is there a way to print value of Boolean flag in NSLog?
Devang
  • 11,258
  • 13
  • 62
  • 100
328
votes
16 answers

How can I import Swift code to Objective-C?

I have written a library in Swift and I wasn't able to import it to my current project, written in Objective-C. Are there any ways to import it? #import "SCLAlertView.swift" - 'SCLAlertView.swift' file not found
Dark Matter
  • 3,638
  • 3
  • 14
  • 14
327
votes
15 answers

How to hide 'Back' button on navigation bar on iPhone?

I added a navigation control to switch between views in my app. But some of the views shouldn't have 'Back' (the previous title) button. Any ideas about how to hide the back button?
Chilly Zhong
  • 16,763
  • 23
  • 77
  • 103
327
votes
6 answers

UIView frame, bounds and center

I would like to know how to use these properties in the right manner. As I understand, frame can be used from the container of the view I am creating. It sets the view position relative to the container view. It also sets the size of that view. Also…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
327
votes
20 answers

Replacement for deprecated sizeWithFont: in iOS 7?

In iOS 7, sizeWithFont: is now deprecated. How do I now pass in the UIFont object into the replacement method sizeWithAttributes:?
James Kuang
  • 10,710
  • 4
  • 28
  • 38