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

Calculating the number of days between two dates in Objective-C

Possible Duplicate: How can I compare two dates, return a number of days I have two dates (as NSString in the form "yyyy-mm-dd"), for example: NSString *start = "2010-11-01"; NSString *end = "2010-12-01"; I'd like to implement: -…
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
59
votes
6 answers

How to create a centered UICollectionView like in Spotify's Player

I am have a lot of difficulty trying to create a UICollectionView like in Spotify's Player that acts like this: The problem for me is two fold. 1) How do I center the cells so that you can see the middle cell as well as the one of the left and…
59
votes
2 answers

-fembed-bitcode is not supported on versions of iOS prior to 6.0

Recently i downloaded xcode 7 beta and facing the error: -fembed-bitcode is not supported on versions of iOS prior to 6.0 Is there any work around to fix this issue with out changing deployment target? Thanks in advance.
Kiran
  • 1,145
  • 1
  • 8
  • 22
59
votes
3 answers

Creating a selector from a method name with parameters

I have a code sample that gets a SEL from the current object, SEL callback = @selector(mymethod:parameter2); And I have a method like -(void)mymethod:(id)v1 parameter2;(NSString*)v2 { } Now I need to move mymethod to another object, say…
BlueDolphin
  • 9,765
  • 20
  • 59
  • 74
59
votes
23 answers

StoryBoard Assistant Editor stopped showing associated file

Xcode storyboard assistant editor stopped showing related files. "Automatic" is selected and "Class" is filled in Identity Inspector. It was working before, but know it has stopped. "Auto" or "CounterPart" modes are still woking for other files…
Add080bbA
  • 1,818
  • 1
  • 18
  • 25
59
votes
5 answers

Create NSString by repeating another string a given number of times

This should be easy, but I'm having a hard time finding the easiest solution. I need an NSString that is equal to another string concatenated with itself a given number of times. For a better explanation, consider the following python example: >>…
Sergio Acosta
  • 11,418
  • 12
  • 62
  • 91
59
votes
10 answers

self.tableView.reloadData() not working in Swift

I'm attempting to learn Swift & the basics of iOS dev at the same time, so bear with me. I've got a TableViewController that is firstly parsing a local JSON file and rendering it's very simple data into TableViewCell and SectionHeaderViews. Within…
chandlervdw
  • 3,197
  • 4
  • 19
  • 21
59
votes
2 answers

How to add a subview that has its own UIViewController in Objective-C?

I am struggling with subviews that have their own UIViewControllers. I have a UIViewController with a view (light pink) and two buttons on a toolbar. I want blue view to display when the first button is pressed and the yellow view to display with…
Patricia
  • 5,019
  • 14
  • 72
  • 152
59
votes
13 answers

Number of occurrences of a substring in an NSString?

How can I get the number of times an NSString (for example, @"cake") appears in a larger NSString (for example, @"Cheesecake, apple cake, and cherry pie")? I need to do this on a lot of strings, so whatever method I use would need to be relatively…
igul222
  • 8,557
  • 14
  • 52
  • 60
59
votes
12 answers

tap gesture recognizer - which object was tapped?

I'm new to gesture recognizers so maybe this question sounds silly: I'm assigning tap gesture recognizers to a bunch of UIViews. In the method is it possible to find out which of them was tapped somehow or do I need to find it out using the point…
suMi
  • 1,536
  • 1
  • 17
  • 30
59
votes
7 answers

What's the difference between synchronous and asynchronous calls in Objective-C, versus multi-threading?

For the longest time I thought asynchronous was synonymous to running something on a background thread, while synchronous meant on the main thread (blocking UI updates and interactions). I understand that not running on the main thread for expensive…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
59
votes
10 answers

Understanding retain cycle in depth

Lets say we have three objects: a grandparent, parent and child. The grandparent retains the parent, the parent retains the child and the child retains the parent. The grandparent releases the parent. What will happen in this case ?
Tariq
  • 9,861
  • 12
  • 62
  • 103
59
votes
17 answers

UITextView link detection in iOS 7

I have a UITextView which is managed via Interface Builder. As data detection I have "Links" checked. In iOS 6 everything is working fine and links are highlighted and are clickable. In iOS 7 though, all links remain just plain text. The editable…
Tobias
  • 1,577
  • 1
  • 13
  • 20
59
votes
2 answers

NSMutableArray addObject not working

I have declared an NSMutableArray *categories in my view controller .h file, and declared a property for it. In the parser:foundCharacters: method of the NSXMLParser delegate in my .m file, I have this code: -(void)parser:(NSXMLParser *) parser…
joec
  • 3,533
  • 10
  • 60
  • 89
59
votes
4 answers

Getting Current Time in string in Custom format in objective c

I want current time in following format in a string. dd-mm-yyyy HH:MM How?
sagarkothari
  • 24,520
  • 50
  • 165
  • 235
1 2 3
99
100