14. Ternary operator
NSInteger value = 5;
result = (value != 0) ? x : y;
int a = 1, b = 2, c = 3, d = 4;
int x = 10, y = 5;
int result = a > b ? x = c > d ? c : d : y;
15. Design Patterns
- are reusable solutions to common problems
in software design.
!
- They’re templates designed to help you write
code that’s easy to understand and reuse.
!
- They also help you create loosely coupled
code so that you can change or replace
components in your code without too much
of a hassle.
23. Façade
• make a software library easier to
use, understand and test, since the
facade has convenient methods for
common tasks;
• make the library more readable, for
the same reason;
• reduce dependencies of outside
code on the inner workings of a
library, since most code uses the
facade, thus allowing more
flexibility in developing the system;
• wrap a poorly designed collection
of APIs with a single well-designed
API (as per task needs).
29. Decorator (Wrapper, Adapter)
is a design pattern that allows behavior to be
added to an individual object, either statically
or dynamically, without affecting the behavior
of other objects from the same class.
31. Delegate
This is an important pattern. Apple uses this approach in most of the UIKit
classes:
UITableView
UITextView
UITextField
UIWebView
UIAlert
UIActionSheet
UICollectionView
UIGestureRecognizer
UIScrollView
UIPickerView
32. Command
is a behavioral design pattern in which an object is used to represent
and encapsulate all the information needed to call a method at a
later time
33. NSInvocation
!
NSMethodSignature * mySignature = [NSMutableArray
instanceMethodSignatureForSelector:@selector(addObject:)];
NSInvocation * myInvocation = [NSInvocation
invocationWithMethodSignature:mySignature];
NSString * myString = @"String";
//Next, you would specify which object to send the message to:
!
[myInvocation setTarget:myArray];
//Specify the message you wish to send to that object:
!
[myInvocation setSelector:@selector(addObject:)];
//And fill in any arguments for that method:
!
[myInvocation setArgument:&myString atIndex:2];
//Note that object arguments must be passed by pointer.
!
//At this point, myInvocation is a complete object, describing a message that can be sent. To
actually send the message, you would call:
!
[myInvocation invoke];
An NSInvocation is an Objective-C message rendered
static, that is, it is an action turned into an object.
!