9. Why should I make a
wrapper around
CLLocationManager?
10. • seamlessly manages permissions
• smoothens out beacon power fluctuations
• doesn’t require all listeners to duplicate single beacon
filtering code and leaving beacon logic
• enable / disable listening
• saves energy (takes care of switching between
monitoring/ranging automatically)
• takes care of background ranging (☠☠☠)
• it’s listeners actually don’t have to care about
anything, only implement code on beacon events.
11. BeaconManager uses
another services/APIs
• CLLocationManager for permissions and
background ranging (updating location)
• Logger (sends critical logs to back-end)
• Data
• SyncManager
• NSNotificationCenter
21. But if Swift is about to be
super-fast and super-safe,
I wouldn’t count on it.
22. Why Obj-C runtime is so
great in testing?
• Effortless and quick mocks/stubs
• No refactoring needed at all. Just jump into
writing tests.
23. Disadvantages of OCMock
way of testing?
• No compile-time protection
• We can forget to stub some important things
• Encourages a bit to write ugly code (inline mocks /
stubs) which could create problems with duplication
later
• No explicit list of dependencies like in dependency
injection
• Still have to write mocks / stubs :(
31. Advantages of SL
• compile-time
• quite quick to implement (actually,
sharedInstance properties could be overwritten
so that they call Service Locator themselves).
• Service protocols are a beautiful way to
investigate app architecture without going too
deep into implementation details
32. Disadvantages of SL
• We need to complicate architecture (is that really
bad thing?)
• We can forget to stub some libs
• No explicit list of dependencies (like in DI)
• Still have to write our stubs :(
39. We could use some
automation for initialising
services.
40. Advantages of DI
• compile-time
• explicit list of dependencies (nice app
architecture guard)
• we won’t forget to stub anything
• service protocols are a beautiful way to
investigate app architecture without going too
deep into implementation details
41. Disadvantages of DI
• Quite not-so-fast to implement
• Architecture gets more complicated (like in SL)
• We still need to write stubs
42. SL vs. DI
• http://www.martinfowler.com/articles/
injection.html
• http://bayou.io/draft/
In_Defense_of_Service_Locator.html
• rest of the Internet
53. Summary
• method / class swizzling is probably not what you want
in Swift
• service locator is quickest way to get legacy code
tested
• typhoon and swinject are 3rd party libs for Swift testing
• swinject seems to be nice
• unfortunately, there are no libraries which out of the
box give developers stubs / mocks for Apple APIs.