3. About me - Tales Pinheiro de Andrade
!@talesp, tales.andrade@concrete.com.br
!MSc Computer Science
!iOS Chapter Leader at Concrete
!CocoaHeads São Paulo Chapter Leader, CocoaHeads Brasil supporter
!C developer since 2003
!iOS since 2010
!Objective-C developer since 2007, Swift since 2015
11. So what is a coordinator?
A coordinator is an object that bosses one or more view
controllers around. Taking all of the driving logic out of
your view controllers, and moving that stuff one layer
up is gonna make your life a lot more awesome.
Coordinators Redux
(Soroush Khanlou)
12. So what is a coordinator?
The Coordinator is a PONSO, like all great objects. For
something like Instagram’s photo creation flow, we could
have a PhotoCreationCoordinator. The app
coordinator could spawn a new one, and pass it the
root view controller so that it could present the first
view controller in the flow.
The Coordinator
(Soroush Khanlou)
15. Delegation
Delegation is a way to make composition as powerful for reuse
as inheritance. In delegation, two objects are involved in
handling a request: a receiving object delegates operations to
its delegate. This is analogous to subclasses deferring requests
to parent classes. But with inheritance, an inherited operation
can always refer to the receiving object through the this
member variable in C++ and self in Smalltalk. To achieve the
same effect with delegation, the receiver passes itself to the
delegate to let the delegated operation refer to the receiver.
16. Delegation: Knight Rider & RoboCop
Let’s start with a story: Once upon a time, there was a man with no name.
Knight Industries decided that if this man were given guns and wheels and
booster rockets, he would be the perfect crime-fighting tool. First they
thought, “Let’s subclass him and override everything we need to add the
guns and wheels and booster rockets.” The problem was that to subclass
Michael Knight, they needed to wire his insides to the guns, wheels, and
booster rockets – a time-consuming task requiring lots of specialized
knowledge. So instead, Knight Industries created a helper object, the
Knight Industries 2000, or “KITT,” a well-equipped car designed to assist
Michael Knight in a variety of crime- fighting situations.
17. Delegation: Super Máquina e RoboCop
While approaching the perimeter of an arms dealer’s compound, Michael
Knight would say, “KITT, I need to get to the other side of that wall.” KITT
would then blast a big hole in the wall with a small rocket. After destroying
the wall, KITT would return control to Michael, who would charge through
the rubble and capture the arms dealer.
Note how creating a helper object is different from the RoboCop
approach. RoboCop was a man subclassed and extended. The RoboCop
project involved dozens of surgeons who extended the man into a fighting
machine. This is the approach taken by many object-oriented frameworks.
18. Delegation: Super Máquina e RoboCop
In the Cocoa framework, many objects are extended in the Knight
Industries way – by supplying them with helper objects. In this section, you
are going to provide the speech synthesizer with a type of helper object
called a delegate.
From Cocoa Programming for OS X: The Big Nerd Ranch Guide
19.
20. MVC-C · Injecting
Coordinator pattern in
UIKit
Taking the first step towards clean and minimal
app architecture in iOS app means freeing your
view controllers from the burden of dealing with
other controllers.
21. Implementation
Responder objects—that is, instances of UIResponder—
constitute the event-handling backbone of a UIKit app.
Many key objects are also responders, including the
UIApplication object, UIViewController objects, and all
UIView objects (which includes UIWindow). As events
occur, UIKit dispatches them to your app's responder
objects for handling.
UIResponder
Documentation
UIEvent
UIResponder children
View Controller
22. Implementação
In addition to handling events, UIKit responders also
manage the forwarding of unhandled events to other
parts of your app. If a given responder does not
handle an event, it forwards that event to the next
event in the responder chain. UIKit manages the
responder chain dynamically, using predefined rules to
determine which object should be next to receive an
event. For example, a view forwards events to its
superview, and the root view of a hierarchy forwards
events to its view controller.
UIResponder
Documentation
UIEvent
UIResponder children
View Controller
28. UIResponder children
open class UIView : UIResponder
open class UIViewController : UIResponder
open class UIWindow : UIView
class AppDelegate : UIResponder
open class UIApplication : UIResponder
31. Chain-of-Responsibility
In object-oriented design, the chain-of-responsibility pattern is a
design pattern consisting of a source of command objects and a
series of processing objects. Each processing object contains logic
that defines the types of command objects that it can handle; the rest
are passed to the next processing object in the chain. A mechanism
also exists for adding new processing objects to the end of this chain.
Thus, the chain of responsibility is an object oriented version of the
if ... else if ... else if ....... else ... endif idiom, with the benefit that the
condition–action blocks can be dynamically rearranged and
reconfigured at runtime.
33. There are several kinds of events, including touch
events, motion events, remote-control events, and
press events. To handle a specific type of event, a
responder must override the corresponding
methods. For example, to handle touch events, a
responder implements the touchesBegan(_:with:),
touchesMoved(_:with:), touchesEnded(_:with:), and
touchesCancelled(_:with:) methods. In the case of
touches, the responder uses the event information
provided by UIKit to track changes to those touches
and to update the app's interface appropriately.
Remembering
Events
Defining Events
Protocol
Base implementation
Child management
Event handling
34. Defining Events
protocol AppEventType { }
protocol AppEventSubType { }
protocol AppEvent {
var type: AppEventType { get }
var subtype: AppEventSubType? { get }
}
46. N Ó S M O V E M O S O M U N D O .
RIO SÃO PAULO BH RECIFE
Centro
Av. Presidente Wilson, 231
29º andar
(21) 2240-2030
Cidade Monções
Av. Nações Unidas, 11.541
3º andar
(11) 4119-0449
Savassi
Av. Getúlio Vargas, 671
Sala 800 - 8º andar
(31) 3360-8900
Ilha do Leite
Rua Sen. José Henrique, 199
2º andar
(81) 3018-6299
W W W. C O N C R E T E . C O M . B R