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
60
votes
2 answers

What is the difference between Highlighted and Selected UIButton's State?

Can anyone tell me What is the difference between Highlighted and Selected state of a UIButton?
Jamal Zafar
  • 2,179
  • 2
  • 27
  • 32
60
votes
4 answers

Objective-C Protocol Forward Declarations

ObjectProperties.h @protocol ObjectProperties @property (strong, nonatomic) NSString *name; @property (strong, nonatomic) NSDate *date; @property (assign, nonatomic) int64_t index; @end ClassA.h #import…
edelaney05
  • 6,822
  • 6
  • 41
  • 65
60
votes
7 answers

Xcode - How to connect XIB to ViewController Class

I created first my TestViewController.h and *.m. Afterwards my TestView.xib. Now I need to tell my xib: "Yes, please take the class TestViewController as my File's Owner". I open up my xib, go to the Identity Inspector of its fileOwner and choose…
mogio
  • 843
  • 2
  • 7
  • 18
60
votes
6 answers

Why can't we use a dispatch_sync on the current queue?

I ran into a scenario where I had a delegate callback which could occur on either the main thread or another thread, and I wouldn't know which until runtime (using StoreKit.framework). I also had UI code that I needed to update in that callback…
60
votes
14 answers

How do I get the current date in Cocoa

I'm getting started developing for the iPhone and as such I am looking at different tutorials online as well as trying some different things out myself. Currently, I'm trying to create a countdown until midnight. To get the number of hour, minutes,…
Jason
  • 17,276
  • 23
  • 73
  • 114
59
votes
9 answers

Change the UITableViewCell Height According to Amount of Text

I need to be able to adjust the height of a single cell in my UITableView so that it fits the amount of text in its detail label. I have played with the following but it hasn't work for me: How do I wrap text in a UITableViewCell without a custom…
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253
59
votes
2 answers

Prototype Cells in a nib instead of a storyboard

For better re-usability I want to create a table view outside of my Storyboard. Now when I create a UITableView based ViewController with Nib in Xcode I get the default TableView in the nib file. However, I am not able in Interface Builder to add…
Besi
  • 22,579
  • 24
  • 131
  • 223
59
votes
15 answers

Change color on checkmark in UITableView

Could someone be so kind to show me how to change the color on the checkmark in UITableView? I have searched but don't seem to get it to work. Cheers
PeterK
  • 4,243
  • 4
  • 44
  • 74
59
votes
6 answers

How can I compute a SHA-2 (ideally SHA 256 or SHA 512) hash in iOS?

The Security services API doesn't appear to allow me to compute a hash directly. There are plenty of public domain and liberally licensed versions available, but I'd rather use a system library implementation if possible. The data is accessible via…
James
  • 24,676
  • 13
  • 84
  • 130
59
votes
8 answers

How can I call a method in Objective-C?

I am trying to build an iPhone app. I created a method like this: - (void)score { // some code } and I have tried to call it in an other method like this: - (void)score2 { @selector(score); } But it does not work. So, how do I call a…
ashish
59
votes
1 answer

How to implement an IMP function that returns a large struct type determined at run-time?

Background: CamelBones registers Perl classes with the Objective-C runtime. To do this, every Perl method is registered with the same IMP function; that function examines its self & _cmd arguments to find which Perl method to call. This has worked…
Sherm Pendley
  • 13,556
  • 3
  • 45
  • 57
59
votes
7 answers

Difference between protocol and delegates?

What is the difference between a protocol and a delegate? and, How can we declare variables in a protocol class?
er.mobileapp
  • 1,287
  • 4
  • 15
  • 21
59
votes
2 answers

Difference between [NSMutableArray array] vs [[NSMutableArray alloc] init]

can someone tell me the difference in declare an mutable array with: NSMutableArray *array = [NSMutableArray array]; and NSMutableArray *array = [[NSMutableArray alloc] init]; Because in the beginning I was declaring all my arrays with alloc, and…
Adelino
  • 2,530
  • 4
  • 20
  • 32
59
votes
6 answers

Why is detailTextLabel not visible?

detailTextLabel is not visible (code below). Can you tell me why? // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString…
Chatar Veer Suthar
  • 15,541
  • 26
  • 90
  • 154
59
votes
1 answer

What does @dynamic do in Objective-C?

Objective-C has a feature called @dynamic. Google only lists results about dynamic typing. I rarely see this in code and I don't understand what it is used for. Can anyone explain me this? Thanks.
user142019
1 2 3
99
100