Section 1

Preview this deck

How to create a factory method ?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (19)

Section 1

(19 cards)

How to create a factory method ?

Front

in .h file + (id) person; in .m file + (id) person { return [[self alloc] init]; }

Back

Objects Compare like NSString, NSNumber

Front

1. if ([someDate compare:anotherDate] == NSOrderedAscending) { // someDate is earlier than anotherDate }

Back

How to define Define Instance Variables without Properties ?

Front

@interface SomeClass : NSObject { NSString *_myNonPropertyInstanceVariable; } ... @end @implementation SomeClass { NSString *_anotherCustomInstanceVariable; }

Back

Classes Are also Objects

Front

a class is itself an object with an opaque type called Class. Classes can't have properties defined using the declaration syntax shown earlier for instances, but they can receive messages. The typical use for a class method is as a factory method, which is an alternative to the object allocation and initialization procedure e.g. + (id)string;

Back

Objects Equality

Front

1. if (firstPerson == secondPerson) { // firstPerson is the same object as secondPerson } 2. if ([firstPerson isEqual:secondPerson]) { // firstPerson is identical to secondPerson }

Back

Method Declaration

Front

1. - (void)someMethod; 2. - (void)someMethodWithValue:(SomeType)value; 3. - (void)someMethodWithFirstValue:(SomeType)value1 secondValue:(AnotherType)value2;

Back

Basic Syntax of Implementation File

Front

#import "XYZPerson.h" @implementation XYZPerson @end

Back

@nonatomic keyword

Front

You can use the nonatomic property attribute to specify that synthesized accessors simply set or return a value directly, with no guarantees about what happens if that same value is accessed simultaneously from different threads. For this reason, it's faster to access a nonatomic property than an atomic one

Back

what's readonly keyboard for @property value

Front

Used to not allow change of the value by setter accessor method

Back

How to write custom getter accessor function ?

Front

@property (getter=isFinished) BOOL finished;

Back

Check object is not nil

Front

1. if (somePerson != nil) { // somePerson points to an object } 2. if (somePerson){ }

Back

How to create objects dynamically in objective-c ?

Front

1. make sure enough memory is allocated not only for the properties defined by an object's class, but also the properties defined on each of the superclasses in its inheritance chain. The NSObject root class provides a class method, alloc, which handles this process for you: + (id)alloc; The alloc method has one other important task, which is to clear out the memory allocated for the object's properties by setting them to zero. This avoids the usual problem of memory containing garbage from whatever was stored before, but is not enough to initialize an object completely. 2. init: The init method is used by a class to make sure its properties have suitable initial values at creation

Back

Basic Syntax of Interface

Front

@interface SimpleClass : NSObject @end

Back

@atomic keyword

Front

This means that the synthesized accessors ensure that a value is always fully retrieved by the getter method or fully set via the setter method, even if the accessors are called simultaneously from different threads

Back

What's instance variable ?

Front

An instance variable is a variable that exists and holds its value for the life of the object. The memory used for instance variables is allocated when the object is first created (through alloc), and freed when the object is deallocated. Unless you specify otherwise, the synthesized instance variable has the same name as the property, but with an underscore prefix. For a property called firstName, for example, the synthesized instance variable will be called _firstName.

Back

How to access @property value in Objective-C ?

Front

You access or set an object's properties via accessor methods: NSString *firstName = [somePerson firstName]; [somePerson setFirstName:@"Johnny"];

Back

How to customize Synthesized Instance Variable Names?

Front

@synthesize propertyName = instanceVariableName; Important: If you use @synthesize without specifying an instance variable name, like this: the instance variable will bear the same name as the property. In this example, the instance variable will also be called firstName, without an underscore.

Back

Objective-C is a Dynamic Language

Front

XYZPerson *firstPerson = [[XYZPerson alloc] init]; XYZPerson *secondPerson = [[XYZShoutingPerson alloc] init]; [firstPerson sayHello]; [secondPerson sayHello];

Back

nil in objective-c

Front

A nil value is the safest way to initialize an object pointer if you don't have another value to use, because it's perfectly acceptable in Objective-C to send a message to nil. If you do send a message to nil, obviously nothing happens.

Back