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
772
votes
20 answers

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?
Andy Jacobs
  • 15,187
  • 13
  • 60
  • 91
761
votes
27 answers

How to link to apps on the app store

I am creating a free version of my iPhone game. I want to have a button inside the free version that takes people to the paid version in the app store. If I use a standard…
matt
  • 1,895
  • 5
  • 19
  • 26
754
votes
13 answers

Generating random numbers in Objective-C

I'm a Java head mainly, and I want a way to generate a pseudo-random number between 0 and 74. In Java I would use the method: Random.nextInt(74) I'm not interested in a discussion about seeds or true randomness, just how you accomplish the same…
rustyshelf
  • 44,963
  • 37
  • 98
  • 104
754
votes
63 answers

Placeholder in UITextView

My application uses an UITextView. Now I want the UITextView to have a placeholder similar to the one you can set for an UITextField. How to do this?
user142019
718
votes
16 answers

@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 inclusions. I also understand that an #import is a…
Coocoo4Cocoa
  • 48,756
  • 50
  • 150
  • 175
689
votes
31 answers

How do I test if a string is empty in Objective-C?

How do I test if an NSString is empty in Objective-C?
Jamey McElveen
  • 18,135
  • 25
  • 89
  • 129
684
votes
43 answers

iOS 8 UITableView separator inset 0 not working

I have an app where the UITableView's separator inset is set to custom values - Right 0, Left 0. This works perfectly in iOS 7.x, however in iOS 8.0 I see that the separator inset is set to the default of 15 on the right. Even though in the xib…
user3570727
  • 10,163
  • 5
  • 18
  • 24
648
votes
9 answers

What does the NS prefix mean?

Many classes in Cocoa/Cocoa Touch have the NS prefix. What does it mean?
Martin08
  • 20,990
  • 22
  • 84
  • 93
635
votes
22 answers

UITextField text change event

How can I detect any text changes in a textField? The delegate method shouldChangeCharactersInRange works for something, but it did not fulfill my need exactly. Since until it returns YES, the textField texts are not available to other observer…
karim
  • 15,408
  • 7
  • 58
  • 96
632
votes
6 answers

Send and receive messages through NSNotificationCenter in Objective-C?

I am attempting to send and receive messages through NSNotificationCenter in Objective-C. However, I haven't been able to find any examples on how to do this. How do you send and receive messages through NSNotificationCenter?
Cathy
621
votes
26 answers

Location Services not working in iOS 8

My app that worked fine on iOS 7 doesn't work with the iOS 8 SDK. CLLocationManager doesn't return a location, and I don't see my app under Settings -> Location Services either. I did a Google search on the issue, but nothing came up. What could be…
ozg
  • 17,532
  • 5
  • 19
  • 21
584
votes
26 answers

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: dispatch_queue_t?#>, <#block: dispatch_block_t?#>)
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
581
votes
18 answers

How to convert an NSString into an NSNumber

How can I convert a NSString containing a number of any primitive data type (e.g. int, float, char, unsigned int, etc.)? The problem is, I don't know which number type the string will contain at runtime. I have an idea how to do it, but I'm not sure…
Enyra
  • 17,542
  • 12
  • 35
  • 44
577
votes
6 answers

In Objective-C, how do I test the object type?

I need to test whether the object is of type NSString or UIImageView. How can I accomplish this? Is there some type of "isoftype" method?
James Skidmore
  • 49,340
  • 32
  • 108
  • 136
574
votes
11 answers

Should IBOutlets be strong or weak under ARC?

I am developing exclusively for iOS 5 using ARC. Should IBOutlets to UIViews (and subclasses) be strong or weak? The following: @property (nonatomic, weak) IBOutlet UIButton *button; Would get rid of all of this: - (void)viewDidUnload { // ... …