Tutorial by Examples

#import <Foundation/Foundation.h> @interface Car:NSObject { NSString *CarMotorCode; NSString *CarChassisCode; } - (instancetype)initWithMotorValue:(NSString *) motorCode andChassisValue:(NSInteger)chassisCode; - (void) startCar; - (void) stopCar; @end @implementation Car...
What is a Singleton Class? A singleton class returns the same instance no matter how many times an application requests it. Unlike a regular class, A singleton object provides a global point of access to the resources of its class. When to Use Singleton Classes? Singletons are used in situations ...
Objective-C supports a special type called `instancetype that can only be used as type returned by a method. It evaluates to the class of the receiving object. Consider the following class hierarchy: @interface Foo : NSObject - (instancetype)initWithString:(NSString *)string; @end @interf...
You can enhance your own classes with generics just like NSArray or NSDictionary. @interface MyClass<__covariant T> @property (nonnull, nonatomic, strong, readonly) NSArray<T>* allObjects; - (void) addObject:(nonnull T)obj; @end
In most object oriented languages, allocating memory for an object and initializing it is an atomic operation: // Both allocates memory and calls the constructor MyClass object = new MyClass(); In Objective-C, these are separate operations. The class methods alloc (and its historic sibling allo...

Page 1 of 1