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
460
votes
6 answers

@import vs #import - iOS 7

I am playing around with some of the new iOS 7 features and working with some of the Image Effects as discussed in the WWDC video "Implementing Engaging UI on iOS". For producing a blur effect within the source code for the session, UIImage was…
jamdaddy25
  • 4,838
  • 3
  • 13
  • 11
455
votes
33 answers

Getting current device language in iOS?

I'd like to show the current language that the device UI is using. What code would I use? I want this as an NSString in fully spelled out format. (Not @"en_US") EDIT: For those driving on by, there are a ton of useful comments here, as the answer…
Moshe
  • 57,511
  • 78
  • 272
  • 425
451
votes
13 answers

How to print out the method name and line number and conditionally disable NSLog?

I'm doing a presentation on debugging in Xcode and would like to get more information on using NSLog efficiently. In particular, I have two questions: is there a way to easily NSLog the current method's name / line number? is there a way to…
rein
  • 32,967
  • 23
  • 82
  • 106
440
votes
0 answers

Capture image via captureStillImageAsynchronouslyFromConnection with no shutter sound

There are a lot of questions about this problem on SO: AVFoundation, how to turn off the shutter sound when captureStillImageAsynchronouslyFromConnection? How can I mute the capture sound in AVFoundation? I wish i could mute shutter sound of camera…
k06a
  • 17,755
  • 10
  • 70
  • 110
439
votes
20 answers

What goes into your .gitignore if you're using CocoaPods?

I've been doing iOS development for a couple of months now and just learned of the promising CocoaPods library for dependency management. I tried it out on a personal project: added a dependency to Kiwi to my Podfile, ran pod install…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
437
votes
29 answers

Core Data: Quickest way to delete all instances of an entity

I'm using Core Data to locally persist results from a Web Services call. The web service returns the full object model for, let's say, "Cars" - could be about 2000 of them (and I can't make the Web Service return anything less than 1 or ALL…
Adaromas
  • 4,383
  • 3
  • 17
  • 5
433
votes
5 answers

How exactly does __attribute__((constructor)) work?

It seems pretty clear that it is supposed to set things up. When exactly does it run? Why are there two parentheses? Is __attribute__ a function? A macro? Syntax? Does this work in C? C++? Does the function it works with need to be static? When…
Casebash
  • 114,675
  • 90
  • 247
  • 350
425
votes
13 answers

throwing an exception in objective-c/cocoa

What's the best way to throw an exception in objective-c/cocoa?
Steph Thirion
  • 9,313
  • 9
  • 50
  • 58
420
votes
12 answers

How dangerous is it to compare floating point values?

I know UIKit uses CGFloat because of the resolution independent coordinate system. But every time I want to check if for example frame.origin.x is 0 it makes me feel sick: if (theView.frame.origin.x == 0) { // do important operation } Isn't…
Proud Member
  • 40,078
  • 47
  • 146
  • 231
417
votes
9 answers

Is It Possible to NSLog C Structs (Like CGRect or CGPoint)?

I want to be able to debug C structures without having to explicitly type every property that they consist of. i.e. I want to be able to do something like this: CGPoint cgPoint = CGPointMake(0,0); NSLog(@"%@",cgPoint); Obviously the '%@' won't…
mazniak
  • 5,849
  • 6
  • 28
  • 23
414
votes
19 answers

Set UIButton title UILabel font size programmatically

I need to set the font size of the title UILabel of a UIButton programmatically.
syam s
407
votes
8 answers

File is universal (three slices), but it does not contain a(n) ARMv7-s slice error for static libraries on iOS, anyway to bypass?

I upgraded Xcode version and when using external static libraries, I get this message: ld: file is universal (3 slices) but does not contain a(n) armv7s slice: /file/location for architecture armv7s clang: error: linker command failed with exit…
Dafna Elazazer
  • 4,083
  • 2
  • 13
  • 6
406
votes
10 answers

What is the difference between #import and #include in Objective-C?

What are the differences between #import and #include in Objective-C and are there times where you should use one over the other? Is one deprecated? I was reading the following tutorial: http://www.otierney.net/objective-c.html#preamble and its…
Ryan Guill
  • 13,558
  • 4
  • 37
  • 48
404
votes
8 answers

Assign a variable inside a Block to a variable outside a Block

I'm getting an error Variable is not assignable (missing __block type specifier) on the line aPerson = participant;. How can I make sure the block can access the aPerson variable and the aPerson variable can be returned? Person *aPerson =…
tommi
  • 6,883
  • 8
  • 37
  • 60
399
votes
34 answers

How to dismiss keyboard for UITextView with return key?

In IB's library, the introduction tells us that when the return key is pressed, the keyboard for UITextView will disappear. But actually the return key can only act as '\n'. I can add a button and use [txtView resignFirstResponder] to hide the…
Chilly Zhong
  • 16,763
  • 23
  • 77
  • 103