Blocks are specified by the Language Specification for Blocks for C, Objective-C, C++ and Objective-C++.
Additionally, the Blocks ABI is defined by the Block Implementation Specification.
To avoid method name clashes, it is recommended to use prefixes (like xyz_
in the example). If methods with the same name exist, it is undefined which one will be used in the runtime.
For logging various types of objects and data-types refer to: Objective-C, Format Specifiers
For nesting various types of objects and data-types into NSStrings refer to: Objective-C, Format Specifiers
The NSDictionary class declares the programmatic interface to objects that manage immutable associations of keys and values. Use this class or its subclass NSMutableDictionary when you need a convenient and efficient way to retrieve data associated with an arbitrary key. NSDictionary creates static dictionaries, and NSMutableDictionary creates dynamic dictionaries. (For convenience, the term dictionary refers to any instance of one of these classes without specifying its exact class membership.)
A key-value pair within a dictionary is called an entry. Each entry consists of one object that represents the key and a second object that is that key’s value. Within a dictionary, the keys are unique. That is, no two keys in a single dictionary are equal (as determined by isEqual:). In general, a key can be any object (provided that it conforms to the NSCopying protocol—see below), but note that when using key-value coding the key must be a string (see Key-Value Coding Fundamentals). Neither a key nor a value can be nil; if you need to represent a null value in a dictionary, you should use NSNull.
NSDictionary is “toll-free bridged” with its Core Foundation counterpart, CFDictionaryRef. See Toll-Free Bridging for more information on toll-free bridging.
In order to use the Objective-C runtime, you need to import it.
#import <objc/objc.h>
NSDate
is a very simple value type, representing one exact moment in universal time. It does not contain information about time zones, daylight saving time, calendars, or locale.
NSDate
is really only an immutable wrapper around an NSTimeInterval
which is a double
. There is no mutable subclass, as with some other value types in Foundation.
For more details read NSPredicate in Apple documentation
NSJSONSerialization is Available in iOS 5.0 and later An object that may be converted to JSON must have the following properties:
The top level object is an NSArray or NSDictionary.
All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
All dictionary keys are instances of NSString.
Numbers are not NaN or infinity.
In Objective C, you should almost always use an object instead of a struct. However, there are still cases where using a struct is better, such as:
- Structs are faster to create and use because when calling a method on an object, the method has to be determined at runtime
- Structs take up less size because objects have an extra property
isa
, which holds their class
CGSize
; it has 2 floats which are 4 bytes each, so it can take up 8 bytes), and is going to be used a lot (ties in with the first point)type *
in place of the C-array type[]
)Dependencies:
Get brushed up before starting:
All test classes have two methods in common setUp & tearDown.
setUp runs before every testcase & tearDown after every testcase.
Test cases runs alphabetically.
In Test Driven Development, it is good to create dummy test data first.
Test case methods starts with "test" keyword.
Test methods accept no parameters & return no value.
Appendix:
There are several other methods for comparing the expected result & actual result out of an operation. Some of those methods are listed below:
NSTextAttachment
objects are used by the NSAttributedString
class cluster as the values for attachment attributes. The objects you create with this class are referred to as text attachment objects, or when no confusion will result, as text attachments or merely attachments.
Protocols and Delegates are two related but different concept:
A Protocol is a interface a class can conforms to, meaning that class implements the listed methods.
A Delegate is typically an anonymous object that conforms to a protocol.
The application of Delegate called Delegation is a design pattern.
At one end we have the concept of Inheritance which creates a tight coupling between the subclass and its superclass whereas Delegation design pattern provides an alternative to avoid this tight coupling using which we can create a much looser relationship based on anonymous Delegate objects.
Due to the nature of format-specifiers, if you wish to include the percentage symbol (%) in your string, you must escape it using a second percentage symbol.
Example:
int progress = 45;//percent
NSString *progressString = [NSString stringWithFormat:@"Progress: %i%%", (int)progress];
NSLog(progressString);//logs "Progress: 45%"
No Format Specifier for BOOL-type exists.
Common-use solutions include:
BOOL myBool = YES;
NSString *boolState = [NSString stringWithFormat:@"BOOL state: %@", myBool?@"true":@"false"];
NSLog(boolState);//logs "true"
Which utilizes a ternary operator for casting a string-equivalent.
BOOL myBool = YES;
NSString *boolState = [NSString stringWithFormat:@"BOOL state: %i", myBool];
NSLog(boolState);//logs "1" (binary)
Which utilizes an (int) cast for implanting a binary-equivalent.