ios development best practices

24
iOS Development Best Practices Tony Collins - Lead iOS developer Jonathan Winger-Lang - iOS developer

Upload: michal-juhas

Post on 09-Feb-2017

1.092 views

Category:

Technology


4 download

TRANSCRIPT

iOS Development Best PracticesTony Collins - Lead iOS developer Jonathan Winger-Lang - iOS developer

“A bad workman blames his tools”

Before you start coding anything, make sure you have the right tools available!

IDE……… Xcode

API testing/POST/GETPostman - Is handy when collaborating across a few developers as requests can be exported/saved (including header info). Downside - requires Chrome = Memory Beast

CocoaRestClient - Super lightweight, nativeOSX app. Does most things Postman can. My personal choice.

API testing TCP/HTTP Charles - Really powerful HTTP proxy that allows you to actually see the traffic your app is sending/receiving in real time. Possible to spoof your SSL cert in order to see encrypted traffic. Downside - Costs $50 (worth it though)

Wireshark - Allows you to intercept traffic going to/from your app and analyse the packet contents/HTTP headers etc. Globally recognised as the number 1 opensource app for this job.Downside - Requires a fair amount of set up (which can be a little intimidating)

Automation toolsAutomator - Seriously underused/underrated app packaged with every build of OSX

Great to do batch tasks e.g. Change 100 images to a specific size

Visually build complex shell scripts and mix in AppleScript or whatever you need

Fastlane/deliver - Takes the pain out of uploading metadata and screenshots to iTunes connect

What took days now takes 6 minutes!!

SQLite (Looking at your DB)SQLPro - Native OSX app. Most stable and reliable I have found. Downside - costs $10

SQLiteManager - Browser plug in for FireFox Downside - lacks quality of dedicated app

PlanningProper Preparation Prevents Poor Performance

AGILE (Just a few basics)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

Time to start coding (nearly)Get an API spec!

Get the wireframes!!

Get a logic flowchart!!!

Get the designs/assets/brand guidelines!!!!

Research any third party tools!!!!!

Which Design Pattern ?Whilst analysing the wireframes, look for View Controllers that have a common theme.

Spot repeating elements - multiple payment options e.g. Linepay, Alipay, Paypal - can we link them ?

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.

Facade pattern Keeps the API’s normalised

Hides complexity behind a simple method

Makes it easier to refactor code

Facade - Example2 API’s which are used when a payment is made - no

matter what the source (PayPal, Linepay etc)

Facade - ExampleHides this complexity

Singleton - Good and BadAsk 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!

Category pattern Very useful for keeping your code DRY

Easy to change a single method than same method multiple times

Delegate vs NotificationsUse 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

Delegates allow you to have more transparent objects as you can specify @required @optional

NSCoding Allows custom objects to be persisted and retrieved later

Can store custom objects in .bin files or to places such as NSUserDefaults

Daily Coding tipsD.R.Y - Dont Repeat Yourself

The patterns mentioned will naturally force you to be D.R.Y

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 new UITesting tools in Xcode 7

Daily Coding tipsComments + 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

Daily Coding tipsPrototype

Great to show stakeholders (Storyboards designed for it)

Can trust implementation without the ‘noise’ of existing code

Can help spot issues earlier

Use continuous integration tools

Apple Bots - preferred as made by Apple although Travis and Jenkins (free) are good

Daily Coding tipsFinal tips…

Keep your project organised

Git - Commit little and often

Dont be an ‘end of the day’ committer

Get into the habit even when working solo

Commit should reflect what was actually done

Do pair programming - Make it 20% of your weekly schedule

Text

ENJOY CODING!!!

Any questions ?