Stats

151 Contributors: 9
2016-11-16
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

Classes and Objects

Download objective-c eBook

Syntax

  • Cat *cat = [[Cat alloc] init]; // Create cat object of type Cat
  • Dog *dog = [[Dog alloc] init]; // Create dog object of type Dog
  • NSObject *someObject = [NSObject alloc]; [someObject init]; // don’t do this
  • XYZObject *object = [XYZObject new]; // Use new to create objects if NO arguments are needed for initialization
  • NSString *someString = @"Hello, World!"; // Creating an NSString with literal syntax
  • NSNumber *myFloat = @3.14f; // Another example to create a NSNumber using literal syntax
  • NSNumber *myInt = @(84 / 2); // Create an object using a boxed expression

Related Examples