iOS Development @ FH Kärnten 23.11.2013

57
iOS Development BEST PRACTICE

description

 

Transcript of iOS Development @ FH Kärnten 23.11.2013

Page 1: iOS Development @ FH Kärnten 23.11.2013

iOS DevelopmentBEST PRACTICE

Page 2: iOS Development @ FH Kärnten 23.11.2013

Introduction• Christoph Lückler, BSc

• Software Developer at UP TO ELEVEN

• Specialization on iOS / OSX Development

• http://github.com/OE8CLR

• http://google.com/+ChristophLückler

Page 3: iOS Development @ FH Kärnten 23.11.2013

Portfolio

Page 4: iOS Development @ FH Kärnten 23.11.2013

Topics

• GIT

• Continuous Integration

• Testing & Deployment

• Xcode - Tips & Tricks

Page 5: iOS Development @ FH Kärnten 23.11.2013

GIT

Page 6: iOS Development @ FH Kärnten 23.11.2013

GIT• Distributed version control system

• Initial release 07.04.2005

• Strong support for non-linear development

• Efficient handling of large projects

• Toolkit-based design

Page 7: iOS Development @ FH Kärnten 23.11.2013

GIT• Pros:

• Speed

• Work offline

• Branching and tagging

• Customizable

Page 8: iOS Development @ FH Kärnten 23.11.2013

GIT• Git objects:

Page 9: iOS Development @ FH Kärnten 23.11.2013

GIT• Setup global git config

!

• Creating aliases

!

• Clone repository

$ git config --global user.name "Christoh Lückler" $ git config --global user.email [email protected] $ git config --list

$ git config --global alias.slog "log --oneline --graph" $ git config --global alias.st "status" $ git config --global alias.unstage "reset HEAD"

$ git clone https://github.com/git/git.git OfficialGit

Page 10: iOS Development @ FH Kärnten 23.11.2013

GIT• Creating new repository

$ git init ! ./.git/config ./.git/HEAD ./.git/info/exclude ./.git/description ./.git/hooks/applypatch-msg.sample ./.git/hooks/commit-msg.sample ./.git/hooks/post-update.sample ./.git/hooks/prepare-commit-msg.sample ./.git/hooks/update.sample ./.git/hooks/pre-commit.sample ./.git/hooks/pre-rebase.sample ./.git/hooks/pre-applypatch.sample

Page 11: iOS Development @ FH Kärnten 23.11.2013

GIT• Adding new files

!

• Removing a file

!

• Change a file

$ echo "This is a new file" > file.txt $ git add file.txt $ git commit -m "Added a new file"

$ git rm file.txt $ git commit -m "Removed a file"

$ echo "Changed text" >> file.txt $ git add file.txt $ git commit -m "Changed a file"

Page 12: iOS Development @ FH Kärnten 23.11.2013

GIT• Create new branch:

$ git branch testing

Page 13: iOS Development @ FH Kärnten 23.11.2013

GIT• Checkout branch:

$ git checkout testing

Page 14: iOS Development @ FH Kärnten 23.11.2013

GIT• Merge branch:

$ git merge testing

Page 15: iOS Development @ FH Kärnten 23.11.2013

GIT• Pushing new branch:

!

• Deleting remote branch:

!

• Pushing new tag

$ git push <remote> <branch>

$ git push <remote> :<branch>

$ git push <remote> <tag>

Page 16: iOS Development @ FH Kärnten 23.11.2013

GIT• Workflow:

Page 17: iOS Development @ FH Kärnten 23.11.2013

Continuous Integration

Page 18: iOS Development @ FH Kärnten 23.11.2013

Continuous Integration• Extreme Programming (XP)

• Test-Driven Development (TDD)

• Prevent integration problems

• Continuous builds

• Automate distribution

Page 19: iOS Development @ FH Kärnten 23.11.2013

Continuous Integration

Page 20: iOS Development @ FH Kärnten 23.11.2013

Extreme Programming• Short development cycles

• High frequent releases

• Pair programming

• Flat management structure

• Good structured code

Page 21: iOS Development @ FH Kärnten 23.11.2013

Test-Driven Development

Run tests see new failure

Add a test

Write some code Run tests see all pass

Refactor

Page 22: iOS Development @ FH Kärnten 23.11.2013

Bots• Build, analyze and test apps

• Need OSX Server 10.9 (XCode Service)

• GIT & SVN support

• Build & test statistics (GUI)

• Manage Bots via Log Navigator or Web Browser

Page 23: iOS Development @ FH Kärnten 23.11.2013

Bots

Page 24: iOS Development @ FH Kärnten 23.11.2013

Jenkins• Open Source (http://jenkins-ci.org)

• Supports several build tools (Maven, LLMV, …)

• Used in organizations (Facebook, Yahoo, Dell, …)

• Easy installation

• Plugin support

Page 25: iOS Development @ FH Kärnten 23.11.2013

Jenkins

Page 26: iOS Development @ FH Kärnten 23.11.2013

Testing & Deployment

Page 27: iOS Development @ FH Kärnten 23.11.2013

• Unit testing

• Integration testing

• System testing

• Acceptance testing (Beta Tests)

Test levels

Page 28: iOS Development @ FH Kärnten 23.11.2013

Test levels

Page 29: iOS Development @ FH Kärnten 23.11.2013

Unit Tests

• Test the result not the implementation (Compare result with specification)

• White-Box-Test

• n * functions == n * tests

• Method could contain bugs

• Prevent new issues

Page 30: iOS Development @ FH Kärnten 23.11.2013

Zoo Keeper Examplehttps://github.com/OE8CLR/CLZooKeeper.git

Page 31: iOS Development @ FH Kärnten 23.11.2013

Zoo Keeper Example

• Develop a simple iOS Application that can store and display animals in one zoo

• Every animal has a firstname, lastname, nickname and birthday

• The user should be able to add and remove animals from the zoo

Page 32: iOS Development @ FH Kärnten 23.11.2013

Zoo Keeper Example

Zoo!! Array *animals; ! - (void)addAnimal: - (void)removeAnimal: - (int)countOfAnimals

Animal!! String *firstName; String *lastName; String *nickName; NSDate *birthdate; ! - (NSString)name - (int)age

Page 33: iOS Development @ FH Kärnten 23.11.2013

Zoo Keeper Example

Page 34: iOS Development @ FH Kärnten 23.11.2013

Alpha & Beta Testing• Alpha Testing:

• Internal user acceptance test

• Tested by potential users or test team

• Should be done before beta testing

• Beta Testing:

• External user acceptance test

Page 35: iOS Development @ FH Kärnten 23.11.2013

TestFlight• Free service

• Distributing apps for Adhoc-Testing

• Supports Android, iOS and Windows

• Supervise testers

• Own SDK to monitor app performance

Page 36: iOS Development @ FH Kärnten 23.11.2013

Crittercism• Free service / Subscription plans

• Monitor live app performance

• Collect crashlogs and evaluate them

• Github issue integration

Page 37: iOS Development @ FH Kärnten 23.11.2013

Google Analytics• Live statistics from where the app is running

• Track usage to optimize further releases

• Gather device information

• Custom variables available

• Can track crashes and exceptions

Page 38: iOS Development @ FH Kärnten 23.11.2013

Google AnalyticsKärnten Card iOS App, 19.06. - 30.09.2013

Page 39: iOS Development @ FH Kärnten 23.11.2013

Xcode - Tips & Tricks

Page 40: iOS Development @ FH Kärnten 23.11.2013

Shortcuts• Chose open location: Shift+OPT

• Open Quickly: CMD+Shift+O

• Shift between *.m and *.h: CTRL+CMD+↑!

• Comment current line: CMD+Shift+7!

• Move focus: CMD+J!

• CMD+U | CMD+B | CMD+R | CMD+.

Page 41: iOS Development @ FH Kärnten 23.11.2013

Behaviors

Page 42: iOS Development @ FH Kärnten 23.11.2013

Snippets• Write code: NSLog(@"<#string#>"); • Drag and drop into „Code Snippet pane“ • Edit snippet properties

Page 43: iOS Development @ FH Kärnten 23.11.2013

Interface Builder

• Select overlapping elements: CTRL+Shift+Click

• Reuse customized objects (Drag & Drop in Library)

• Jumping to class: CMD+DoubleClick!

• Autolayout: Don’t think too difficult

Page 44: iOS Development @ FH Kärnten 23.11.2013

Debugger• Set Breakpoint and write into Debugger Log:

• Print object description: expr -o -- [ObjectName]

• Get variables: frame variable

• Thread list: thread list

• Hover to object in code to get details in GUI

Page 45: iOS Development @ FH Kärnten 23.11.2013

Build Targets• Build Settings -> Preprocessor Macros

// Initialize Crittercism for crash logging when app is not in debugging mode #ifndef DEBUG [Crittercism enableWithAppID:@“ABC0815”]; #endif

Page 46: iOS Development @ FH Kärnten 23.11.2013

NSNotificationCenter• Broadcast notifications within a program

• Register objects to receive NSNotifications

• Attach objects or information to notification

• Every cocoa program has it’s own defaultCenter [[NSNotificationCenter defaultCenter] postNotificationName: @"sentPinResponseRecieved" object: bop.response]; ! [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(pinSentNotification:) name: @"sentPinResponseRecieved" object: nil];

Page 47: iOS Development @ FH Kärnten 23.11.2013

Blocks• Apple extension to the C language

• Encapsulate code like a function

void (^helloWorldBlock)(void) = ^{ NSLog(@"Hello World"); }; helloWorldBlock();

int (^returnNumberBlock)(void) = ^{ return 42; }; int value = returnNumberBlock();

Page 48: iOS Development @ FH Kärnten 23.11.2013

Multithreading• Grand Central Dispatch introduced with iOS 4.0

• After iOS 6.0 automatically retain and release

• GCD is a C level API -> No exception handling

• Queuing tasks for dispatch (Multithreading)

• 3 Queue-Types

Page 49: iOS Development @ FH Kärnten 23.11.2013

Documentation

• Human-readable source code comments • Types:

• @param [param] [Description] • @return [Description] • @see [selector] • @warning [Description]

Page 50: iOS Development @ FH Kärnten 23.11.2013

Documentation /** * Verifies a given pin on the CCMP. * * @warning Can throw CCMPException * * @param msisdn MSISDN, for example: 436766688000 * @param pin PIN, for example: 1234 */ - (void)verifyMsisdn:(NSNumber *)msisdn withPin:(NSString *)pin NS_AVAILABLE_IOS(6_0);

Page 51: iOS Development @ FH Kärnten 23.11.2013

Documentation• Create documentation with AppleDoc

Page 52: iOS Development @ FH Kärnten 23.11.2013

CocoaPods• Dependency management tool

• Idea comes from JavaEE (Maven)

• Runs on Ruby

• Save repository space

• Tutorial | Xcode Plugin

Page 53: iOS Development @ FH Kärnten 23.11.2013

CocoaPods• Fix issue with Unit Tests:

• Project > Info > Configuration • Change Base on Configuration File to Pods

Page 54: iOS Development @ FH Kärnten 23.11.2013

References

Page 55: iOS Development @ FH Kärnten 23.11.2013

Beginning iOS 6 Development

• Released: 9. Jan 2013

• http://www.iphonedevbook.com

Page 56: iOS Development @ FH Kärnten 23.11.2013

NSnshipster

obscure topicsin cocoa &objective-c

mattt thompson

first edition

NSHipster• Released: 12. Nov. 2013

• http://www.nshipster.com

Page 57: iOS Development @ FH Kärnten 23.11.2013

Stackoverflow

• Question and Answer site for programmers

• Most problems are solved

• Think first, then answer

• Don’t believe everything