9. Forgive me, because
I am going to sin
★ The following are tips, not rules.
★ They might not apply to your code.
★But I would, at least, think about them.
13. Don’t start with reusable
code
★ Start with the right idea
★But don’t need the perfect code
★ You can always refactor
★ Shipped is better than perfect
16. Commit reusable code
★Do the Right Thing™ before committing to
the development branch or any shared
branches.
★Be a good boy scout: If you revisit the
code and it can be improved, do so.
24. Presentation logic
★ It isn’t business logic, but “UI logic”
★ In the VC, it could be inconsistent, better
“centralized”.
★ It shouldn’t be in the model.
★ It can contain UI dependent information
(colors, fonts,…).
25. Instead of
// Set label to “3 days left”
- (void) displayRemainingTime {
self.remainingLabel.text =
[self.task remainingTime];
}
26. do
// Set label to “3 days left”
- (void) displayRemainingTime {
TaskPresenter *tp =
[[TaskPresenter alloc]
initWithTask:self.task];
self.remainingLabel.text = [tp
remainingTime];
}
28. Put the network
closer to the
model (instead of
View Controller)
29. Network code
★ The view controller is responsible for responding events:
• lifecycle
• UI generated
★Controlling networking is OK
★ Doing networking is wrong
★ In the model or a category:
• Provide business logic with network functionality
• Handle concurrency
37. DataSource & Delegate
responsibilities
★Metadata: How many rows, sections…
★ Act on data: add or delete row
★ Provide views, view info and present data
★ Act on selections
38. Use a delegate
numberOfSectionInTableView:
tableView:numberOfRowsInSection:
tableView:cellForRowAtIndexPath:
MyVC MyDataSrc
displayObject:inCell
45. Test your view controllers
(2)
- (void)
testOnViewDidLoadTitleIsSetToChecklistName {
[sut view];
XCTAssertTrue([sut.title
isEqualToString:sut.checklist.name],
@"View controller title must be
set to the checklist name");
}
49. Workflows
★Huge Storyboards:
• Teams get conflicts in the Storyboards often
• Difficult to maintain
★Better Storyboards:
• One per workflow (sign in/sign up, statistics,
preferences)
• Even combine with XIB (useful for cells)
53. Modular code
★ iOS support
• Until iOS 8: only static libraries (no
resources, separated headers)
• iOS 8: frameworks
★Cocoapods: allow to share open source
code
54. Create a pod
★ Isolate the code (use pod-template)
★Create .podspec & LICENSE
★ pod lib create coolpod
★ In your Podfile:
• pod ‘coolpod', :git => 'https://
server/repoURL/coolpod.git'