Languages Features Creators Calendar CSV Resources Blog About Pricing Add Language
GitHub icon

Objective-C

Objective-C - Programming language

< >

Objective-C is a programming language created in 1984 by Brad Cox.

#43on PLDB 39Years Old 12.4kUsers
15Books 0Papers 536kRepos

Try now: Riju

Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It was the main programming language used by Apple for the OS X and iOS operating systems, and their respective application programming interfaces (APIs) Cocoa and Cocoa Touch prior to the introduction of Swift. The programming language Objective-C was originally developed in the early 1980s. Read more on Wikipedia...


Example from Riju:
#import <Foundation/Foundation.h> int main() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello, world!"); [pool drain]; return 0; }
Example from hello-world:
/* Build on OS X: clang -framework Foundation -fobjc-arc objc.m -o objc Build on Linux with GNUstep: clang `gnustep-config --objc-flags` `gnustep-config --base-libs` -fobjc-nonfragile-abi -fobjc-arc objc.m -o objc */ #import <Foundation/Foundation.h> int main(void) { NSLog(@"Hello World"); }
/* Hello World in Objective-C. ** Since the standard implementation is identical to K&R C, ** a version that says hello to a set of people passed on ** the command line is shown here. */ #include <stdio.h> #include <objpak.h> int main(int argc,char **argv) { id set = [Set new]; argv++;while (--argc) [set add:[String str:*argv++]]; [set do:{ :each | printf("hello, %s!\n",[each str]); }]; return 0; }
Example from Linguist:
#import "Foo.h" @implementation Foo @end
Example from Wikipedia:
-(void) firstLabel: (int)param1 secondLabel: (int)param2;

Keywords in Objective-C

auto break case char const continue default do double else enum extern float for goto if inline int long register restrict return short signed sizeof static struct switch typedef union unsigned void volatile while Bool Complex _Imaginary BOOL Class bycopy byref id IMP in inout nil NO NULL oneway out Protocol SEL self Super YES @ @interface @end @implementation @protocol @class @public @protected @private @property @try @throw @catch() @finally @synthesize @dynamic @selector atomic nonatomic retain

Language features

Feature Supported Token Example
Conditionals โœ“
Switch Statements โœ“
Constants โœ“
While Loops โœ“
MultiLine Comments โœ“ /* */
/* A comment
*/
Print() Debugging โœ“ printf
Comments โœ“
// A comment
Message Passing โœ“
Line Comments โœ“ //
// A comment
Interfaces โœ“
@protocol Printing
   -(void) print;
@end
File Imports โœ“
// #import ensures that a file is only ever included once so that you never have a problem with recursive includes.
#import 
#include 
#include 
Constructors โœ“
Pointers โœ“
Single Dispatch โœ“
Strings โœ“ "
"hello world"
Scientific Notation โœ“
Case Sensitivity โœ“
Assignment โœ“
Increment and decrement operators โœ“
Zero-based numbering โœ“
Variadic Functions โœ“
double average(int count, ...)
{
 //
}
Manual Memory Management โœ“
#include 
#include 
int main(void)
{
  int *poin = malloc(4);
  free(poin);
}
Macros โœ“
// https://learn.microsoft.com/en-us/cpp/preprocessor/macros-c-cpp?redirectedfrom=MSDN&view=msvc-170
// https://gcc.gnu.org/onlinedocs/cpp/Macro-Arguments.html
#define min(X, Y)  ((X) < (Y) ? (X) : (Y))
  x = min(a, b);          โ†’  x = ((a) < (b) ? (a) : (b));
  y = min(1, 2);          โ†’  y = ((1) < (2) ? (1) : (2));
  z = min(a + 28, *p);    โ†’  z = ((a + 28) < (*p) ? (a + 28) : (*p));
Integers โœ“
int pldb = 80766866;
Type Casting โœ“
double da = 3.3;
double db = 3.3;
double dc = 3.4;
int result = (int)da + (int)db + (int)dc; //result == 9
Directives โœ“
#include 
#define height 10
#ifdef
#endif
#if
#else
#ifndef
#undef
#pragma
Gotos โœ“
// C/C++ program to check if a number is 
// even or not using goto statement 
#include  
using namespace std; 
  
// function to check even or not 
void checkEvenOrNot(int num) 
{ 
    if (num % 2 == 0) 
        goto even; // jump to even 
    else
        goto odd; // jump to odd 
  
even: 
    cout << num << " is evenn"; 
    return; // return if even 
odd: 
    cout << num << " is oddn"; 
} 
  
// Driver program to test above function 
int main() 
{ 
    int num = 26; 
    checkEvenOrNot(num); 
    return 0; 
}
Structs โœ“
struct account {
  int account_number;
  char *first_name;
  char *last_name;
  float balance;
};
Symbol Tables โœ“
// Declare an external function
extern double bar(double x);

// Define a public function
double foo(int count)
{
    double  sum = 0.0;

    // Sum all the values bar(1) to bar(count)
    for (int i = 1;  i <= count;  i++)
        sum += bar((double) i);
    return sum;
}
// Symbol Table:
// Symbol name|Type|Scope
// bar|function, double|extern
// x|double|function parameter
// foo|function, double|global
// count|int|function parameter
// sum|double|block local
// i|int|for-loop statement
Bitwise Operators โœ“
int i = 4; /* bit pattern equivalent is binary 100 */
int j = i << 2; /* makes it binary 10000, which multiplies the original number by 4 i.e. 16 */
Assert Statements โœ“
#include 
int i, a[10];
for (i = 0; i < 10; ++i)
  {
  assert(0 <= i && i < 10);
  a[i] = 10-i;
  }
for (i = 0; i < 10; ++i)
  {
  assert(0 <= i && i < 10);
  assert(0 <= a[i] && a[i] < 10);
  a[a[i]] = a[i];
  }
Ternary operators โœ“
#include 
int main(void) { printf("%d", 1 ? 1 : 0); }
Characters โœ“
char character = 'P';
Booleans โœ“
Enums โœ“
enum Gender {
  Male,
  Female,
};
Case Insensitive Identifiers X
Semantic Indentation X
Operator Overloading X
Garbage Collection X
Fixed Point Numbers X
Exceptions X
Classes X
Access Modifiers X
Templates X
Multiple Inheritance X
Namespaces X
Regular Expression Syntax Sugar X
Variable Substitution Syntax X

Books about Objective-C on goodreads

title author year reviews ratings rating
Programming in Objective C Stephen G. Kochan 1999 21 445 3.96
Programming in Objective-C 2.0 Stephen G. Kochan 2008 16 370 3.85
Objective-C Programming: The Big Nerd Ranch Guide Aaron Hillegass 2011 41 634 4.17
The Objective-C Programming Language Apple Inc. 0 24 3.62

Books about Objective-C from ISBNdb

title authors year publisher
Programming in Objective-C (Developer's Library) Kochan, Stephen G. 2012 Addison-Wesley Professional
Learn Objective-C on the Mac (Learn Series) Knaster, Scott and Dalrymple, Mark 2008 Apress
Objective-C DeVoe, Jiva 2011 Wiley
Learn Objective-C on the Mac: For OS X and iOS Knaster, Scott and Dalrymple, Mark and Malik, Waqar 2012 Apress
Objective-C for Absolute Beginners: iPhone, iPad and Mac Programming Made Easy Bennett, Gary and Fisher, Mitchell and Lees, Brad 2011 Apress
Head First iPhone and iPad Development: A Learner's Guide to Creating Objective-C Applications for the iPhone and iPad Pilone, Dan and Pilone, Tracey 2011 O'Reilly Media
Learn Objective-C for Java Developers (Learn Series) Bucanek, James 2009 Apress
Objective-C for iPhone Developers, A Beginner's Guide Brannan, James 2010 McGraw-Hill Education
Learning the iOS 4 SDK for JavaScript Programmers: Create Native Apps with Objective-C and Xcode Goodman, Danny 2011 O'Reilly Media
Pro Objective-C Design Patterns for iOS Chung, Carlo 2011 Apress
Objective-C Fundamentals Fairbairn, Christopher and Ruffenach, Collin and Fahrenkrug, Johannes 2011 Manning Publications
isbn.html ยท objective-c.html ยท nodejs.html

View source

- Build the next great programming language ยท Search ยท v2023 ยท Day 205 ยท Docs ยท Acknowledgements ยท Traffic ยท Traffic Today ยท Mirrors ยท GitHub ยท feedback@pldb.com