SlideShare a Scribd company logo
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved.
C2M – Best
Practices
iOS
Presented by:
Suyash Gupta
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 2
Agenda
 Design principles in Swift
 Recommended libraries
 Testing
 Continuous Integration
 Localization
 Best practises
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 3
Design principles in
Swift
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 4
Design principles (SOLIDS)
• Single Responsibility Principle
• Open/Closed Principle
• Liskov Substitution Principle : Any child type of a parent
type should be able to stand in for that parent without
things blowing up.
• Interface Segregation Principle: you don't want to force
clients to depend on things they don't actually need.
• Dependency Inversion: entities should depends upon
abstractions rather than upon concrete details.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 5
Single Responsibility Principle
class Handler { // BAD EXAMPLE
func handle() {
let data = requestDataToAPI()
let array = parse(data: data)
saveToDB(array: array)
}
private func requestDataToAPI() -> Data {
// send API request and wait the response
}
private func parse(data: Data) -> [String] {
// parse the data and create the array
}
private func saveToDB(array: [String]) {
// save the array in a database (CoreData/Realm/...)
}
}
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 6
Liskov Substitution Principle
protocol Bird {
var altitudeToFly: Double? {get}
func setLocation(longitude: Double , latitude: Double)
mutating func setAltitude(altitude: Double) //WRONG IMPLEMENTATION
}
class Penguin: Bird {
@override func setAltitude(altitude: Double) {
//Altitude can't be set because penguins can't fly
//throw exception
}
} //If an override method does nothing or just throws an exception, then
you’re probably violating the LSP.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 7
Liskov Substitution Principle
protocol Bird {
var altitudeToFly: Double? {get}
func setLocation(longitude: Double , latitude: Double)
}
protocol Flying {
mutating func setAltitude(altitude: Double)
}
protocol FlyingBird: Bird, Flying {
}
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 8
Liskov Substitution Principle
struct Owl: FlyingBird {
var altitudeToFly: Double?
mutating func setAltitude(altitude: Double) {
altitudeToFly = altitude
}
func setLocation(longitude: Double, latitude: Double) {
//Set location value
}
}
struct Penguin: Bird {
var altitudeToFly: Double?
func setLocation(longitude: Double, latitude: Double) {
//Set location value
}
}
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 9
Dependency Inversion Principle
struct Developer {
func work() {
// ....working
}
}
struct Manager {
let worker: Developer;
init (w: Developer) { //BAD EXAMPLE
worker = w;
}
func manage() {
worker.work();
}
}
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 10
Dependency Inversion Principle
//NEW TYPE
struct Tester {
func work() {
//.... working
}
}
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 11
Dependency Inversion Principle
protocol IEmployee {
func work()
}
struct Developer: IEmployee {
func work() {
print("Developer working...") // Developer working...
}
}
struct Tester: IEmployee {
func work() {
print("Tester working...") // Tester working...
}
}
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 12
Dependency Inversion Principle
struct Management {
let employee: IEmployee;
init (e: IEmployee) {
employee = e;
}
func manage() {
employee.work();
}
}
//Let’s give it a try,
let employee = Developer()
let management = Management(e:employee)
management.manage() // Output - Developer working...
let employer2 = Tester()
let management2 = Management(e:employer2)
management2.manage() // Output - Tester working...
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 13
Design principles in Swift
• Whilst analysing the wireframes, look for View
Controllers that have a common theme.
• Spot repeating elements – and make them as a
reusable widget to the project structure.
• Think long term. This is a project you may have to
deal with in 12 months time. Do yourself a favour
and make the right decisions now.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 14
Facade pattern
• Keeps the API’s normalised
• Hides complexity behind a simple method
• Makes it easier to refactor code
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 15
Facade pattern Demo
class Engine {
func produceEngine() {
print("prodce engine")
}
}
class Body {
func produceBody() {
print("prodce body")
}
}
class Accessories {
func produceAccessories() {
print("prodce accessories")
}
}
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 16
Facade pattern Demo
class FactoryFacade {
let engine = Engine()
let body = Body()
let accessories = Accessories()
func produceCar() {
engine.produceEngine()
body.produceBody()
accessories.produceAccessories()
}
}
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 17
Singleton - Good and Bad
• Ask yourself these questions:
• “Does the object need to be referenced by multiple
other objects at the same time e.g. needs to be ‘Thread
safe’ ?“
• “Does the current ‘state’ need to be always up to date
when referenced ?”
• “Is there a risk that if a duplicate object is created, the
calling object might be pointing at the wrong object?”
• If yes to all of these - USE A SINGLETON!
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 18
Design Patterns
• More Patterns:
https://github.com/ochococo/Design-Patterns-In-
Swift
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 19
Delegate vs Notifications
• Use a delegate pattern if it is only a single object
that cares about the event.
• Use NSNotifications when you need more then one
object to know about the event.
• Remember to use NSNotifications add and remove
callbacks in standard way.
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 20
Recommended Libraries
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 21
Recommended Libraries
# UI Customization
pod 'PureLayout'
pod 'SnapKit'
pod ‘UIColor_Hex_Swift’ // let fillColor = UIColor("#FFCC00DD").CGColor
# Camera / Photo
pod 'TOCropViewController'
pod 'Fusuma’ // Instagram-like photo browser with camera
# Bug Tracking
pod 'Fabric'
pod 'Crashlytics'
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 22
Recommended Libraries
# Analytics
pod 'GoogleAnalytics'
pod 'Appsee'
pod 'FBSDKCoreKit'
pod 'Mixpanel-swift’
# Address Book Data
pod 'APAddressBook/Swift '
pod ' PhoneNumberKit’ // parsing, formatting and validating international phone
numbers
# Network & JSON
pod 'Alamofire’ / pod ‘AFNetworking’
pod ‘SDWebImage'
pod 'SwiftyJSON'
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 23
Recommended Libraries
# AB Testing
pod 'Firebase/Core'
pod 'Firebase/DynamicLinks'
pod 'Firebase/Performance'
pod 'GoogleTagManager’
# Debug
pod 'Dotzu’
# Data Storage
pod ‘RealmSwift'
pod ‘KeychainAccess’
#Quality
Pod ‘SwiftLint’
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 24
Recommended Libraries
# Permission
Pod ‘Permission/Camera’ // unified API to request permissions
# Common
pod ‘DateTools’
# Billing
pod ‘SwiftyStoreKit’ // In App Purchases framework
# Communication With Customers
pod 'Intercom'
# Rate App
pod 'Armchair’
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 25
Testing
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 26
Testing
• You should have one XCTestCase file for every
component you test.
• The key to writing good unit tests is understanding
that you need to break your app into smaller pieces
that you can test.
• Do include inverse behaviors, a.k.a. negative test
cases
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 27
Testing
• A well-architected set of unit tests should function
as documentation.
• Also make use of code-coverage to evaluate the
part of code left to test.
• Integrate it with CI/CD.
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 28
Continuous Integration
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 29
CI and CD
• Continuous Integration (CI) is a development practice
that requires developers to integrate code into a shared
repository several times a day. Each check-in is then
verified by an automated build, allowing teams to
detect problems early.
• Continuous Delivery (CD) is a software engineering
approach in which teams produce software in short
cycles, ensuring that the software can be reliably
released at any time. It aims at building, testing, and
releasing software faster and more frequently.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 30
Continuous Integration
• There are a lot of tools available that can help you with
continuous integration of iOS apps like Xcode Server,
Jenkins and Travis CI.
• Why use Continuous Delivery?
– Save days of preparing app submission, uploading
screenshots and releasing the app
– Colleague on vacation and a critical bugfix needs to be
released? Don’t rely on one person releasing updates
– Increase software quality and reaction time with more
frequent and smaller releases
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 31
Localization
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 32
Localization
• iOS Localization is the process of rendering the
content of your app into multiple languages.
• Users in other countries want to use your app in a
language they understand.
• Using iTunes Connect, you can indicate whether your
app is available in all territories or specific territories.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 33
Localization
DEMO
https://github.com/suyashgupta25/xib-localization
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 34
Best Practices
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 35
Best Practices - Xcode
• Xcode is the IDE of choice for most iOS developers,
and the only one officially supported by Apple.
There are some alternatives, of which AppCode is
arguably the most famous, but unless you're
already a seasoned iOS person, go with Xcode.
Despite its shortcomings, it's actually quite usable
nowadays!
• To install, simply download Xcode on the Mac App
Store.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 36
Best Practices - Xcode
• CoreData: Contains DataModel and Entity Classes.
• Extension: extensions+project class extensions
• Helper: Contain Third Party classes/Frameworks + Bridging
classes (eg. Obj C class in Swift based project)
• Model: The Web Service Response parsing and storing data
is also done here.
• Services: Contain Web Service processes (eg. Login
Verification, HTTP Request/Response)
• View: Contain storyboard, LaunchScreen.xib and View
Classes. Make a sub folder Cells - contain UITableViewCell,
UICollectionViewCell etc.
• Controller: Contain ViewControllers
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 37
Best Practices - Xcode
CocoaPods : it's a standard package manager for iOS
projects.
# It'll eat up 1,5gigs of space (the master repository under
~/.cocoapods), it creates unnecessary things too.
# It's the worst option, but it's the most popular one
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 38
Best Practices - AGILE
• Create ‘user stories’ from the specification
• Be Data driven - Gut feeling will only get you so
far!!!!!
• Be user driven - What do your users want ?
• Be Involved - Don’t be shy, have an opinion, use
your knowledge to advance the idea. Spot flaws
NOW, not 1 month down the line. You will save
yourself time, money and a lot of headaches.
• Iterate - Check, Do, Check, Change
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 39
Best Practices
• D.R.Y - Dont Repeat Yourself
– Don’t write lengthy methods, divide logic into
smaller reusable pieces.
– It will become a natural part of your refactoring
– Don’t do magic to achieve D.R.Y
• Unit Testing
– Try and add unit tests from the beginning of a
project. Retrofitting unit tests can be painful .
– Great UITesting tools in Xcode.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 40
Best Practices
Comments + Verbose method names
• COMMENT YOUR CODE - NO EXCUSES.
• Saves 1000’s of man hours.
• Is just common courtesy.
• Name of method should explain what it does
• Add a comment in the .h advising what the
class does.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 41
Best Practices
• Prototype
– Great to show stakeholders (Storyboards designed
for it)
– Can trust implementation without the ‘noise’ of
existing code
– Can help spot issues earlier.
• Do pair programming - Make it 20% of your weekly
schedule
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 42
Best Practices
• Keep your project organized Git - Commit little and
often
– Don’t be an ‘end of the day’ committer
– Get into the habit even when working solo
– Commit should reflect what was actually done.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 43
HAPPY CODING!!
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 44
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 45
Demo Repository
https://github.com/suyashgupta25/xib-localization

More Related Content

Similar to Best practices iOS meetup - pmd (20)

PDF
Writing idealistic apps (Mobilization 2018)
JoannisOrlandos
 
PDF
Intro to iOS Application Architecture
Make School
 
PDF
Swift Development Strategies for iOS App
panaromicinoftechs
 
PDF
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
dhentyimeng51
 
PDF
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
nhiocou1527
 
PDF
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
ericasapna10
 
PDF
Perfomatix - iOS swift coding standards
Perfomatix Solutions
 
PDF
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
thoramenzab0
 
PDF
Ios 5 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
colffwalbum
 
PPTX
Guide to Destroying Codebases The Demise of Clever Code
Gabor Varadi
 
PDF
Architecting iOS Project
Massimo Oliviero
 
PDF
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
assangkaoua
 
PDF
Programming Ios 5 2nd Edition 2nd Early Release Draft Matt Neuburg
lindzpeccoo
 
PDF
如何提升 iOS 開發速度?
Sean Chen
 
PPTX
Fundamental Design Patterns.pptx
JUNSHIN8
 
PPTX
Hello world ios v1
Teodoro Alonso
 
PDF
Swift rocks! #1
Hackraft
 
PDF
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
matbarnargis59
 
PDF
Deep Dive Into Swift
Sarath C
 
PDF
The iOS technical interview: get your dream job as an iOS developer
Juan C Catalan
 
Writing idealistic apps (Mobilization 2018)
JoannisOrlandos
 
Intro to iOS Application Architecture
Make School
 
Swift Development Strategies for iOS App
panaromicinoftechs
 
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
dhentyimeng51
 
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
nhiocou1527
 
iOS 5 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch ...
ericasapna10
 
Perfomatix - iOS swift coding standards
Perfomatix Solutions
 
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
thoramenzab0
 
Ios 5 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
colffwalbum
 
Guide to Destroying Codebases The Demise of Clever Code
Gabor Varadi
 
Architecting iOS Project
Massimo Oliviero
 
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
assangkaoua
 
Programming Ios 5 2nd Edition 2nd Early Release Draft Matt Neuburg
lindzpeccoo
 
如何提升 iOS 開發速度?
Sean Chen
 
Fundamental Design Patterns.pptx
JUNSHIN8
 
Hello world ios v1
Teodoro Alonso
 
Swift rocks! #1
Hackraft
 
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
matbarnargis59
 
Deep Dive Into Swift
Sarath C
 
The iOS technical interview: get your dream job as an iOS developer
Juan C Catalan
 

Recently uploaded (20)

PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PPTX
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
PowerISO Crack 2025 – Free Download Full Version with Serial Key [Latest](1)....
HyperPc soft
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Human Resources Information System (HRIS)
Amity University, Patna
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PowerISO Crack 2025 – Free Download Full Version with Serial Key [Latest](1)....
HyperPc soft
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Ad

Best practices iOS meetup - pmd

  • 1. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. C2M – Best Practices iOS Presented by: Suyash Gupta
  • 2. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 2 Agenda  Design principles in Swift  Recommended libraries  Testing  Continuous Integration  Localization  Best practises
  • 3. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 3 Design principles in Swift
  • 4. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 4 Design principles (SOLIDS) • Single Responsibility Principle • Open/Closed Principle • Liskov Substitution Principle : Any child type of a parent type should be able to stand in for that parent without things blowing up. • Interface Segregation Principle: you don't want to force clients to depend on things they don't actually need. • Dependency Inversion: entities should depends upon abstractions rather than upon concrete details.
  • 5. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 5 Single Responsibility Principle class Handler { // BAD EXAMPLE func handle() { let data = requestDataToAPI() let array = parse(data: data) saveToDB(array: array) } private func requestDataToAPI() -> Data { // send API request and wait the response } private func parse(data: Data) -> [String] { // parse the data and create the array } private func saveToDB(array: [String]) { // save the array in a database (CoreData/Realm/...) } }
  • 6. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 6 Liskov Substitution Principle protocol Bird { var altitudeToFly: Double? {get} func setLocation(longitude: Double , latitude: Double) mutating func setAltitude(altitude: Double) //WRONG IMPLEMENTATION } class Penguin: Bird { @override func setAltitude(altitude: Double) { //Altitude can't be set because penguins can't fly //throw exception } } //If an override method does nothing or just throws an exception, then you’re probably violating the LSP.
  • 7. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 7 Liskov Substitution Principle protocol Bird { var altitudeToFly: Double? {get} func setLocation(longitude: Double , latitude: Double) } protocol Flying { mutating func setAltitude(altitude: Double) } protocol FlyingBird: Bird, Flying { }
  • 8. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 8 Liskov Substitution Principle struct Owl: FlyingBird { var altitudeToFly: Double? mutating func setAltitude(altitude: Double) { altitudeToFly = altitude } func setLocation(longitude: Double, latitude: Double) { //Set location value } } struct Penguin: Bird { var altitudeToFly: Double? func setLocation(longitude: Double, latitude: Double) { //Set location value } }
  • 9. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 9 Dependency Inversion Principle struct Developer { func work() { // ....working } } struct Manager { let worker: Developer; init (w: Developer) { //BAD EXAMPLE worker = w; } func manage() { worker.work(); } }
  • 10. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 10 Dependency Inversion Principle //NEW TYPE struct Tester { func work() { //.... working } }
  • 11. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 11 Dependency Inversion Principle protocol IEmployee { func work() } struct Developer: IEmployee { func work() { print("Developer working...") // Developer working... } } struct Tester: IEmployee { func work() { print("Tester working...") // Tester working... } }
  • 12. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 12 Dependency Inversion Principle struct Management { let employee: IEmployee; init (e: IEmployee) { employee = e; } func manage() { employee.work(); } } //Let’s give it a try, let employee = Developer() let management = Management(e:employee) management.manage() // Output - Developer working... let employer2 = Tester() let management2 = Management(e:employer2) management2.manage() // Output - Tester working...
  • 13. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 13 Design principles in Swift • Whilst analysing the wireframes, look for View Controllers that have a common theme. • Spot repeating elements – and make them as a reusable widget to the project structure. • Think long term. This is a project you may have to deal with in 12 months time. Do yourself a favour and make the right decisions now.
  • 14. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 14 Facade pattern • Keeps the API’s normalised • Hides complexity behind a simple method • Makes it easier to refactor code
  • 15. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 15 Facade pattern Demo class Engine { func produceEngine() { print("prodce engine") } } class Body { func produceBody() { print("prodce body") } } class Accessories { func produceAccessories() { print("prodce accessories") } }
  • 16. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 16 Facade pattern Demo class FactoryFacade { let engine = Engine() let body = Body() let accessories = Accessories() func produceCar() { engine.produceEngine() body.produceBody() accessories.produceAccessories() } }
  • 17. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 17 Singleton - Good and Bad • Ask yourself these questions: • “Does the object need to be referenced by multiple other objects at the same time e.g. needs to be ‘Thread safe’ ?“ • “Does the current ‘state’ need to be always up to date when referenced ?” • “Is there a risk that if a duplicate object is created, the calling object might be pointing at the wrong object?” • If yes to all of these - USE A SINGLETON!
  • 18. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 18 Design Patterns • More Patterns: https://github.com/ochococo/Design-Patterns-In- Swift
  • 19. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 19 Delegate vs Notifications • Use a delegate pattern if it is only a single object that cares about the event. • Use NSNotifications when you need more then one object to know about the event. • Remember to use NSNotifications add and remove callbacks in standard way.
  • 20. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 20 Recommended Libraries
  • 21. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 21 Recommended Libraries # UI Customization pod 'PureLayout' pod 'SnapKit' pod ‘UIColor_Hex_Swift’ // let fillColor = UIColor("#FFCC00DD").CGColor # Camera / Photo pod 'TOCropViewController' pod 'Fusuma’ // Instagram-like photo browser with camera # Bug Tracking pod 'Fabric' pod 'Crashlytics'
  • 22. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 22 Recommended Libraries # Analytics pod 'GoogleAnalytics' pod 'Appsee' pod 'FBSDKCoreKit' pod 'Mixpanel-swift’ # Address Book Data pod 'APAddressBook/Swift ' pod ' PhoneNumberKit’ // parsing, formatting and validating international phone numbers # Network & JSON pod 'Alamofire’ / pod ‘AFNetworking’ pod ‘SDWebImage' pod 'SwiftyJSON'
  • 23. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 23 Recommended Libraries # AB Testing pod 'Firebase/Core' pod 'Firebase/DynamicLinks' pod 'Firebase/Performance' pod 'GoogleTagManager’ # Debug pod 'Dotzu’ # Data Storage pod ‘RealmSwift' pod ‘KeychainAccess’ #Quality Pod ‘SwiftLint’
  • 24. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 24 Recommended Libraries # Permission Pod ‘Permission/Camera’ // unified API to request permissions # Common pod ‘DateTools’ # Billing pod ‘SwiftyStoreKit’ // In App Purchases framework # Communication With Customers pod 'Intercom' # Rate App pod 'Armchair’
  • 25. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 25 Testing
  • 26. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 26 Testing • You should have one XCTestCase file for every component you test. • The key to writing good unit tests is understanding that you need to break your app into smaller pieces that you can test. • Do include inverse behaviors, a.k.a. negative test cases
  • 27. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 27 Testing • A well-architected set of unit tests should function as documentation. • Also make use of code-coverage to evaluate the part of code left to test. • Integrate it with CI/CD.
  • 28. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 28 Continuous Integration
  • 29. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 29 CI and CD • Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early. • Continuous Delivery (CD) is a software engineering approach in which teams produce software in short cycles, ensuring that the software can be reliably released at any time. It aims at building, testing, and releasing software faster and more frequently.
  • 30. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 30 Continuous Integration • There are a lot of tools available that can help you with continuous integration of iOS apps like Xcode Server, Jenkins and Travis CI. • Why use Continuous Delivery? – Save days of preparing app submission, uploading screenshots and releasing the app – Colleague on vacation and a critical bugfix needs to be released? Don’t rely on one person releasing updates – Increase software quality and reaction time with more frequent and smaller releases
  • 31. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 31 Localization
  • 32. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 32 Localization • iOS Localization is the process of rendering the content of your app into multiple languages. • Users in other countries want to use your app in a language they understand. • Using iTunes Connect, you can indicate whether your app is available in all territories or specific territories.
  • 33. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 33 Localization DEMO https://github.com/suyashgupta25/xib-localization
  • 34. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 34 Best Practices
  • 35. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 35 Best Practices - Xcode • Xcode is the IDE of choice for most iOS developers, and the only one officially supported by Apple. There are some alternatives, of which AppCode is arguably the most famous, but unless you're already a seasoned iOS person, go with Xcode. Despite its shortcomings, it's actually quite usable nowadays! • To install, simply download Xcode on the Mac App Store.
  • 36. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 36 Best Practices - Xcode • CoreData: Contains DataModel and Entity Classes. • Extension: extensions+project class extensions • Helper: Contain Third Party classes/Frameworks + Bridging classes (eg. Obj C class in Swift based project) • Model: The Web Service Response parsing and storing data is also done here. • Services: Contain Web Service processes (eg. Login Verification, HTTP Request/Response) • View: Contain storyboard, LaunchScreen.xib and View Classes. Make a sub folder Cells - contain UITableViewCell, UICollectionViewCell etc. • Controller: Contain ViewControllers
  • 37. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 37 Best Practices - Xcode CocoaPods : it's a standard package manager for iOS projects. # It'll eat up 1,5gigs of space (the master repository under ~/.cocoapods), it creates unnecessary things too. # It's the worst option, but it's the most popular one
  • 38. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 38 Best Practices - AGILE • Create ‘user stories’ from the specification • Be Data driven - Gut feeling will only get you so far!!!!! • Be user driven - What do your users want ? • Be Involved - Don’t be shy, have an opinion, use your knowledge to advance the idea. Spot flaws NOW, not 1 month down the line. You will save yourself time, money and a lot of headaches. • Iterate - Check, Do, Check, Change
  • 39. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 39 Best Practices • D.R.Y - Dont Repeat Yourself – Don’t write lengthy methods, divide logic into smaller reusable pieces. – It will become a natural part of your refactoring – Don’t do magic to achieve D.R.Y • Unit Testing – Try and add unit tests from the beginning of a project. Retrofitting unit tests can be painful . – Great UITesting tools in Xcode.
  • 40. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 40 Best Practices Comments + Verbose method names • COMMENT YOUR CODE - NO EXCUSES. • Saves 1000’s of man hours. • Is just common courtesy. • Name of method should explain what it does • Add a comment in the .h advising what the class does.
  • 41. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 41 Best Practices • Prototype – Great to show stakeholders (Storyboards designed for it) – Can trust implementation without the ‘noise’ of existing code – Can help spot issues earlier. • Do pair programming - Make it 20% of your weekly schedule
  • 42. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 42 Best Practices • Keep your project organized Git - Commit little and often – Don’t be an ‘end of the day’ committer – Get into the habit even when working solo – Commit should reflect what was actually done.
  • 43. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 43 HAPPY CODING!!
  • 44. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 44
  • 45. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 45 Demo Repository https://github.com/suyashgupta25/xib-localization

Editor's Notes

  • #2: Intro, welcome and other PMD things
  • #5: ISP: Clients should not be forced to implement interfaces they don’t use.