3. #pragma mark
iOS & OSX Developers Community
We organize the #PragmaConference, an event
dedicated to iOS and OS X development
!
http://www.pragmamark.org
http://www.facebook.com/groups/pragmamark
@pragmamarkorg
14. Literals
‣ The new object literals significantly reduce the
verbosity of code
15. Literals
‣ The new object literals significantly reduce the
verbosity of code
‣ All objects made via literal (such an array or a
dictionary) are immutable
16. Literals
‣ The new object literals significantly reduce the
verbosity of code
‣ All objects made via literal (such an array or a
dictionary) are immutable
‣ Remember that @(expr) dynamically evaluates the
boxed expression and returns the appropriate object
literal based on its value
23. Object Subscripting
‣ Subscripting syntax can significantly reduce the
verbosity of code that deals heavily with arrays and
dictionaries
24. Object Subscripting
‣ Subscripting syntax can significantly reduce the
verbosity of code that deals heavily with arrays and
dictionaries
‣ Syntax similar to that found in common scripting
languages
25. Object Subscripting
‣ Subscripting syntax can significantly reduce the
verbosity of code that deals heavily with arrays and
dictionaries
‣ Syntax similar to that found in common scripting
languages
‣ You can extend your own classes with subscripting
support
26. use new @import declaration
@import is the new compiler directive introduced by Modules
30. @import
‣ Modules provide an alternative, simpler way to use
software libraries that provides better compile-time
scalability and eliminates many of the problems
inherent to using the C preprocessor to access the API
of a library
31. @import
‣ Modules provide an alternative, simpler way to use
software libraries that provides better compile-time
scalability and eliminates many of the problems
inherent to using the C preprocessor to access the API
of a library
‣ Modules link frameworks automatically (no more
need to link framework from Build Phases)
32. @import
‣ Modules provide an alternative, simpler way to use
software libraries that provides better compile-time
scalability and eliminates many of the problems
inherent to using the C preprocessor to access the API
of a library
‣ Modules link frameworks automatically (no more
need to link framework from Build Phases)
‣ At this time, modules are only available for Apple’s
frameworks and have been implicitly disabled for C++
33. use new type instancetype
instancetype is a contextual keyword that can be used as a result type to signal that a
method returns a related result type, you can use it as return type of an init method or
a (convenient)constructor
38. instancetype
‣ With instancetype, the compiler will correctly infer
that the result of convenient constructor is an
instance of a MGACustomer
39. instancetype
‣ With instancetype, the compiler will correctly infer
that the result of convenient constructor is an
instance of a MGACustomer
‣ Instancetype, unlike id, can only be used as the result
type in a method declaration
40. instancetype
‣ With instancetype, the compiler will correctly infer
that the result of convenient constructor is an
instance of a MGACustomer
‣ Instancetype, unlike id, can only be used as the result
type in a method declaration
‣ Init method should also use instancetype instead of
id, instancetype is more explicit and therefore better
than id
41. use auto property synthesis
synthesize not necessary for @property since Xcode 4.4
45. auto property synthesis
‣ Clang provides support for autosynthesis of declared
properties. Using this feature, clang provides default
synthesis of those properties not declared @dynamic
and not having user provided backing getter and
setter methods.
46. auto property synthesis
‣ Clang provides support for autosynthesis of declared
properties. Using this feature, clang provides default
synthesis of those properties not declared @dynamic
and not having user provided backing getter and
setter methods.
‣ Auto-synthesis is not support for properties defined in
a protocol
47. auto property synthesis
‣ Clang provides support for autosynthesis of declared
properties. Using this feature, clang provides default
synthesis of those properties not declared @dynamic
and not having user provided backing getter and
setter methods.
‣ Auto-synthesis is not support for properties defined in
a protocol
‣ The compiler will add the ivar for you (with underscore
prefix) when it adds the required accessor methods
48. use copy for any immutable class
for attributes whose type is an immutable value class that conforms to the
NSCopying protocol (e.g.. NSDate, NSNumber, NSArray, NSSet), you almost always
should specify copy in your @property declaration
52. copy attribute
‣ The reason of copy is that it is possible to have a
property that is declared as an immutable type (such
as NSString) yet pass it a mutable type (such as
NSMutableString). In which case it is possible to
change the property from outside the class
53. copy attribute
‣ The reason of copy is that it is possible to have a
property that is declared as an immutable type (such
as NSString) yet pass it a mutable type (such as
NSMutableString). In which case it is possible to
change the property from outside the class
‣ using copy is recommended, because it behaves
sensibly with class clusters, sending copy to a mutable
class returns an immutable copy of the object
54. NS_ENUM & NS_OPTIONS macro
these macros are the new, preferred way to declare enum types.
60. NS_ENUM & NS_OPTIONS
‣ The new macros combines the best of all ways to
declare an enum or an option, and even provide hints
to the compiler for type-checking and switch
statement completeness.
61. NS_ENUM & NS_OPTIONS
‣ The new macros combines the best of all ways to
declare an enum or an option, and even provide hints
to the compiler for type-checking and switch
statement completeness.
‣ If the compiler is operating in C++11 or Objective-C+
+11 mode, the macros behave slightly differently in
order to make the code compatible with the mixed
mode
62. use extern const not #define
the best way to define a globally accessible constant is extern const
68. extern const
‣ It ensures that the compiler do a static type
checking and emit a warning if you try to use it
somewhere where it isn't expecting
69. extern const
‣ It ensures that the compiler do a static type
checking and emit a warning if you try to use it
somewhere where it isn't expecting
‣ One benefit is that changing the value of a constant
does not cause a rebuild of your entire program.
70. extern const
‣ It ensures that the compiler do a static type
checking and emit a warning if you try to use it
somewhere where it isn't expecting
‣ One benefit is that changing the value of a constant
does not cause a rebuild of your entire program.
‣ Use FOUNDATION_EXPORT macro instead of extern
if your code will be used in mixed C/C++
environments or on other platforms
71. use Foundation Data Types
if you are unsure, the Foundation Data Types (like NSInterger or CGFloat) are the best
choice because they are architecture safe versions of the corresponding C types
73. Foundation Data Types
‣ The Fondation Data Types were introduced to make it
easier to write code that works on both 32-bit and 64-
bit without modification
74. Foundation Data Types
‣ The Fondation Data Types were introduced to make it
easier to write code that works on both 32-bit and 64-
bit without modification
‣ You usually want to use Foundation Data Types when
you don't know what kind of processor architecture
your code might run on
75. Foundation Data Types
‣ The Fondation Data Types were introduced to make it
easier to write code that works on both 32-bit and 64-
bit without modification
‣ You usually want to use Foundation Data Types when
you don't know what kind of processor architecture
your code might run on
‣ However, if you need to take control on memory
footprint you can use native types
76. Use Class Extensions to Hide Private Data
Class extensions are often used to extend the public interface with additional private
methods, properties or ivars for use within the implementation of the class itself
83. Class Extensions
‣ A class extension bears some similarity to a category,
but it can only be added to a class for which you have
the source code at compile time. The methods
declared by a class extension are implemented in the
@implementation block for the original class
84. Class Extensions
‣ A class extension bears some similarity to a category,
but it can only be added to a class for which you have
the source code at compile time. The methods
declared by a class extension are implemented in the
@implementation block for the original class
‣ By declaring the class extension inside the source code
file for the class implementation, the information stays
private to the class; the header files in theory should
only expose public interface for your classes
86. Class Extensions
‣ It’s possible to use a class extension to add custom
instance variables. These are declared inside braces in
the class extension interface
87. Class Extensions
‣ It’s possible to use a class extension to add custom
instance variables. These are declared inside braces in
the class extension interface
‣ It’s also common, for example, to define a property as
readonly in the interface, but as readwrite in a class
extension declared above the implementation, in order
that the internal methods of the class can change the
property value directly
88. Class Extensions
‣ It’s possible to use a class extension to add custom
instance variables. These are declared inside braces in
the class extension interface
‣ It’s also common, for example, to define a property as
readonly in the interface, but as readwrite in a class
extension declared above the implementation, in order
that the internal methods of the class can change the
property value directly
‣ It’s also possible to declare an ivar in the
@implemetation block
94. use prefixes on all classes
‣ Choose a prefix with at least 3 uppercase chars that are
significant for the project
95. use prefixes on all classes
‣ Choose a prefix with at least 3 uppercase chars that are
significant for the project
‣ Two-letter prefixes are reserved by Apple for use in
framework classes, so you must use 3 (or more)
96. use prefixes on all classes
‣ Choose a prefix with at least 3 uppercase chars that are
significant for the project
‣ Two-letter prefixes are reserved by Apple for use in
framework classes, so you must use 3 (or more)
‣ Objective-C classes must be named uniquely not only within
the code that you’re writing in a project, but also across any
frameworks or bundles you might be including. As an
example, you should avoid using generic class names like
ViewController or TextParser because it’s possible a
framework you include in your app may fail to follow
conventions and create classes with the same names.
97. use a prefix for method names in categories
in a category you should include a prefix on the method name to avoid clashes
101. prefix category methods
‣ If the name of a method declared in a category is the same as a
method in the original class, or a method in another category
on the same class (or even a superclass), the behavior is
undefined as to which method implementation is used at
runtime.
102. prefix category methods
‣ If the name of a method declared in a category is the same as a
method in the original class, or a method in another category
on the same class (or even a superclass), the behavior is
undefined as to which method implementation is used at
runtime.
‣ In order to avoid undefined behavior, it’s best practice to add a
prefix to method names in categories on framework classes, just
like you should add a prefix to the names of your own classes.
You might choose to use the same three letters you use for your
class prefixes, but lowercase to follow the usual convention for
method names, then an underscore, before the rest of the
method name
103. properly define BOOL property
for Boolean properties the getter method should start with is
110. use ~iphone and ~ipad
‣ Adding ~iphone and ~ipad to xib file name, the
runtime will automatically infer the correct xib to load
(e.g. MGAHomeViewController~iphone.xib and
MGAHomeViewController~ipad.xib)
111. use ~iphone and ~ipad
‣ Adding ~iphone and ~ipad to xib file name, the
runtime will automatically infer the correct xib to load
(e.g. MGAHomeViewController~iphone.xib and
MGAHomeViewController~ipad.xib)
‣ note, it’s case sensitive so iPhone and iPad, with a
capital P, do not work
123. #pragma mark
‣ Use #pragma mark in your @implementation to divide
code into logical sections
124. #pragma mark
‣ Use #pragma mark in your @implementation to divide
code into logical sections
‣ It is also a way to organize your methods in the
method list pop up view in Xcode
130. don’t #import in header file
‣ Rather than adding #import statements for each class,
it's good practice to use forward class declarations in
the header, and import them in the implementation
131. don’t #import in header file
‣ Rather than adding #import statements for each class,
it's good practice to use forward class declarations in
the header, and import them in the implementation
‣ It reduce compile times and cyclical references
132. don’t #import in header file
‣ Rather than adding #import statements for each class,
it's good practice to use forward class declarations in
the header, and import them in the implementation
‣ It reduce compile times and cyclical references
‣ The one real exception is when subclassing another
custom class, you'll need to #import its header.
133. use typedef to simplify Block syntax
If you need to define more than one block with the same signature, you might like to
define your own type for that signature
140. create types for blocks
‣ types improve readability and clean up your method
definitions, life will be easier and It’s highly
recommend making use of them as much as possible
141. create types for blocks
‣ types improve readability and clean up your method
definitions, life will be easier and It’s highly
recommend making use of them as much as possible
‣ If you have to change the block signature, it is much
easier to change the typedef. The compiler, being a
nice fellow, will then tell you all the places the block
signature doesn’t match
145. how to access ivars
‣ Direct access bypasses the property’s memory-
management semantics defined by the setter
146. how to access ivars
‣ Direct access bypasses the property’s memory-
management semantics defined by the setter
‣ KVO notifications would not be fired when accessing
the instance variables directly
147. how to access ivars
‣ Direct access bypasses the property’s memory-
management semantics defined by the setter
‣ KVO notifications would not be fired when accessing
the instance variables directly
‣ In init methods you should use direct instance variable
access, because subclasses could override the setter
148. how to access ivars
‣ Direct access bypasses the property’s memory-
management semantics defined by the setter
‣ KVO notifications would not be fired when accessing
the instance variables directly
‣ In init methods you should use direct instance variable
access, because subclasses could override the setter
‣ On the other part of class read/write data through
properties
155. declare atomic/nonatomic
‣ By default, synthesized accessors include locking to
make them atomic
‣ If you not need locking on property use nonatomic on
iOS, since performance is severely impacted if atomic
is used
161. use read-only properties
‣ expose object data with read-only properties, unless
you really need to allow access to internal data
through a public setter
162. use read-only properties
‣ expose object data with read-only properties, unless
you really need to allow access to internal data
through a public setter
‣ for read-only properties, you should defined a public
getter but a private setter in class extension
163. use weak to avoid retain cycles
a wrong memory management involves in memory leaks
180. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
181. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
182. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
183. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
184. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
185. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
186. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
187. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
188. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
189. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
190. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
191. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
192. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
193. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
194. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
195. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
Using SDWebImage (3.5.4)
196. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
Using SDWebImage (3.5.4)
Using SDWebImage-ProgressView (0.3.1)
197. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
Using SDWebImage (3.5.4)
Using SDWebImage-ProgressView (0.3.1)
Using SOCKit (1.1)
198. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
Using SDWebImage (3.5.4)
Using SDWebImage-ProgressView (0.3.1)
Using SOCKit (1.1)
Using TransitionKit (2.0.0)
199. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
Using SDWebImage (3.5.4)
Using SDWebImage-ProgressView (0.3.1)
Using SOCKit (1.1)
Using TransitionKit (2.0.0)
Generating Pods project
200. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
Using SDWebImage (3.5.4)
Using SDWebImage-ProgressView (0.3.1)
Using SOCKit (1.1)
Using TransitionKit (2.0.0)
Generating Pods project
Integrating client project
201. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
Using SDWebImage (3.5.4)
Using SDWebImage-ProgressView (0.3.1)
Using SOCKit (1.1)
Using TransitionKit (2.0.0)
Generating Pods project
Integrating client project
202. Cocoapods
$ sudo gem install cocoapods
$ cd MyGreatApp
$ pod init
$ edit Podfile
platform :ios, '6.1'
pod 'RestKit', '~> 0.22.0'
pod 'FXKeychain', '~> 1.5'
pod 'SDWebImage', '~> 3.5.2'
pod 'SDWebImage-ProgressView', '~> 0.3.0'
pod 'RHAddressBook', '~> 1.1.1'
pod 'FormatterKit', '~> 1.4.2'
$ pod install
Analyzing dependencies
Downloading dependencies
Using AFNetworking (1.3.3)
Using FXKeychain (1.5)
Using FormatterKit (1.4.2)
Using ISO8601DateFormatterValueTransformer (0.5.0)
Using RHAddressBook (1.1.1)
Using RKValueTransformers (1.0.1)
Using RestKit (0.22.0)
Using SDWebImage (3.5.4)
Using SDWebImage-ProgressView (0.3.1)
Using SOCKit (1.1)
Using TransitionKit (2.0.0)
Generating Pods project
Integrating client project
$
204. Cocoapods
‣ CocoaPods manage dependency for you, it download
source files, imports headers and configures flags
205. Cocoapods
‣ CocoaPods manage dependency for you, it download
source files, imports headers and configures flags
‣ CocoaPods is strongly inspired by a combination of
the Ruby projects RubyGems and Bundler
206. Cocoapods
‣ CocoaPods manage dependency for you, it download
source files, imports headers and configures flags
‣ CocoaPods is strongly inspired by a combination of
the Ruby projects RubyGems and Bundler
‣ CocoaPods focuses on source-based distribution of
third party code and automatic integration into Xcode
projects
207. Cocoapods
‣ CocoaPods manage dependency for you, it download
source files, imports headers and configures flags
‣ CocoaPods is strongly inspired by a combination of
the Ruby projects RubyGems and Bundler
‣ CocoaPods focuses on source-based distribution of
third party code and automatic integration into Xcode
projects
‣ CocoaPods runs from the command line
213. Key-Value Coding
‣ Key-value coding is a mechanism for accessing an
object’s properties indirectly, using strings to identify
properties
214. Key-Value Coding
‣ Key-value coding is a mechanism for accessing an
object’s properties indirectly, using strings to identify
properties
‣ You can get the value of any method with no
parameter
215. Key-Value Coding
‣ Key-value coding is a mechanism for accessing an
object’s properties indirectly, using strings to identify
properties
‣ You can get the value of any method with no
parameter
‣ Key-Value Coding automatically boxes and unboxes
values into their object representation.
220. KVC Collection Operators
‣ Collection operators allow actions to be performed on
the items of a collection using key path notation and
an action operator
221. KVC Collection Operators
‣ Collection operators allow actions to be performed on
the items of a collection using key path notation and
an action operator
‣ Collection operators are specialized key paths that are
passed as the parameter to the valueForKeyPath:
method
222. KVC Collection Operators
‣ Collection operators allow actions to be performed on
the items of a collection using key path notation and
an action operator
‣ Collection operators are specialized key paths that are
passed as the parameter to the valueForKeyPath:
method
‣ The operator is specified by a string preceded by an at
sign (@)
245. NSBlockOperation
‣ NSBlockOperation is a concrete subclass that wraps
block in operations
‣ You can use this object to execute several blocks at
once without having to create separate operation
objects for each
246. NSBlockOperation
‣ NSBlockOperation is a concrete subclass that wraps
block in operations
‣ You can use this object to execute several blocks at
once without having to create separate operation
objects for each
‣ When executing more than one block, the operation
itself is considered finished only when all blocks have
finished executing
255. NSError
‣ An NSError object encapsulates richer and more
extensible error information than is possible using
only an error code or error string
256. NSError
‣ An NSError object encapsulates richer and more
extensible error information than is possible using
only an error code or error string
‣ The core attributes of an NSError object are an error
domain, a domain-specific error code and a user info
dictionary containing application specific information.
257. NSError
‣ An NSError object encapsulates richer and more
extensible error information than is possible using
only an error code or error string
‣ The core attributes of an NSError object are an error
domain, a domain-specific error code and a user info
dictionary containing application specific information.
‣ Domain-specific error codes are generally defined by
constants in an enum.
258. use NSCache
It’s a collection-like container, or cache, that stores key-value pairs, similar to the
NSMutableDictionary class.
260. NSCache
NSCache *cache = [[NSCache alloc] init];
!
!
// Sets the maximum number of objects that the cache can hold.
!
// This limit is not a strict limit, and if the cache goes over the limit,
// an object in the cache could be evicted instantly, later, or possibly never,
// all depending on the implementation details of the cache.
[cache setCountLimit:50];
!
!
// Sets the maximum total cost that the cache can have before it starts evicting objects
!
// If adding this object to the cache causes the cache’s total cost to rise above
// totalCostLimit, the cache could automatically evict some of its objects until its
// total cost falls below totalCostLimit. The order in which the cache evicts objects is
// not guaranteed. This limit is not a strict limit, and if the cache goes over the
// limit, an object in the cache could be evicted instantly, at a later point in time,
// or possibly never, all depending on the implementation details of the cache.
[cache setTotalCostLimit:5000];
!
!
// Add object to cache with cost
[cache setObject:customer1 forKey:@"c1" cost:10];
!
!
// Add object to cache without cost
[cache setObject:customer2 forKey:@"c2"];
262. NSCache
‣ NSCache is basically just an NSMutableDictionary that
automatically evicts objects in order to free up space
in memory as needed
263. NSCache
‣ NSCache is basically just an NSMutableDictionary that
automatically evicts objects in order to free up space
in memory as needed
‣ The NSCache class incorporates various auto-removal
policies, which ensure that it does not use too much of
the system’s memory. The system automatically carries
out these policies if memory is needed by other
applications. When invoked, these policies remove
some items from the cache, minimizing its memory
footprint.
266. NSCache
‣ It is guaranteed to be thread-safe.
‣ It is much slower to access.
267. NSCache
‣ It is guaranteed to be thread-safe.
‣ It is much slower to access.
‣ It may throw out objects from time to time. You can set
costs and limits, but they're not guaranteed to be followed.
268. NSCache
‣ It is guaranteed to be thread-safe.
‣ It is much slower to access.
‣ It may throw out objects from time to time. You can set
costs and limits, but they're not guaranteed to be followed.
‣ It is not toll-free bridged to anything in CoreFoundation.
269. NSCache
‣ It is guaranteed to be thread-safe.
‣ It is much slower to access.
‣ It may throw out objects from time to time. You can set
costs and limits, but they're not guaranteed to be followed.
‣ It is not toll-free bridged to anything in CoreFoundation.
‣ You can't query the number of objects that are in the
cache.
270. NSCache
‣ It is guaranteed to be thread-safe.
‣ It is much slower to access.
‣ It may throw out objects from time to time. You can set
costs and limits, but they're not guaranteed to be followed.
‣ It is not toll-free bridged to anything in CoreFoundation.
‣ You can't query the number of objects that are in the
cache.
‣ You can't enumerate a cache.
274. NSValue
NSMutableArray *items = [@[] mutableCopy];
[items addObject:[NSValue valueWithCGSize:CGSizeMake(200.0f, 300.0f)]];
NSValue *sizeValue = items[0];
CGSize size = [sizeValue CGSizeValue];
// define new struct
typedef struct MGAColor
{
float red, blue, green;
}
MGAColor;
MGAColor color = { 255.0, 0.0f, 34.0 };
[items addObject:[NSValue valueWithBytes:&color objCType:@encode(MGAColor)]];
MGAUser *user = [[MGAUser alloc] init]; // it not conforms to <NSCopying>
NSMutableDictionary *items = [@{} mutableCopy];
// e.g. I want to store num of login attempts of a user
// because my custom class MGAUser does not conform to <NSCopying>
// I can’t use it as key value. The workaround is to box user instance
// into NSValue object with valueWithNonretainedObject:
[items setObject:numLogin forKey:[NSValue valueWithNonretainedObject:user]];
276. NSValue
‣ It can hold scalars and value types, as well as pointers
and object IDs.
277. NSValue
‣ It can hold scalars and value types, as well as pointers
and object IDs.
‣ NSValue uses type encoding to create the necessary
data structures to represent values internally
278. NSValue
‣ It can hold scalars and value types, as well as pointers
and object IDs.
‣ NSValue uses type encoding to create the necessary
data structures to represent values internally
‣ valueWithNonretainedObject: allows objects to be
added to a collection, without the need for satisfying
<NSCopying> protocol