iOS Development @ FH Kärnten 23.11.2013

Post on 31-Aug-2014

652 views 1 download

Tags:

description

 

Transcript of iOS Development @ FH Kärnten 23.11.2013

iOS DevelopmentBEST PRACTICE

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

Portfolio

Topics

• GIT

• Continuous Integration

• Testing & Deployment

• Xcode - Tips & Tricks

GIT

GIT• Distributed version control system

• Initial release 07.04.2005

• Strong support for non-linear development

• Efficient handling of large projects

• Toolkit-based design

GIT• Pros:

• Speed

• Work offline

• Branching and tagging

• Customizable

GIT• Git objects:

GIT• Setup global git config

!

• Creating aliases

!

• Clone repository

$ git config --global user.name "Christoh Lückler" $ git config --global user.email christoph.lueckler@ut11.net $ 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

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

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"

GIT• Create new branch:

$ git branch testing

GIT• Checkout branch:

$ git checkout testing

GIT• Merge branch:

$ git merge testing

GIT• Pushing new branch:

!

• Deleting remote branch:

!

• Pushing new tag

$ git push <remote> <branch>

$ git push <remote> :<branch>

$ git push <remote> <tag>

GIT• Workflow:

Continuous Integration

Continuous Integration• Extreme Programming (XP)

• Test-Driven Development (TDD)

• Prevent integration problems

• Continuous builds

• Automate distribution

Continuous Integration

Extreme Programming• Short development cycles

• High frequent releases

• Pair programming

• Flat management structure

• Good structured code

Test-Driven Development

Run tests see new failure

Add a test

Write some code Run tests see all pass

Refactor

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

Bots

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

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

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

• Easy installation

• Plugin support

Jenkins

Testing & Deployment

• Unit testing

• Integration testing

• System testing

• Acceptance testing (Beta Tests)

Test levels

Test levels

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

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

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

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

Zoo Keeper Example

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

TestFlight• Free service

• Distributing apps for Adhoc-Testing

• Supports Android, iOS and Windows

• Supervise testers

• Own SDK to monitor app performance

Crittercism• Free service / Subscription plans

• Monitor live app performance

• Collect crashlogs and evaluate them

• Github issue integration

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

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

Xcode - Tips & Tricks

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+.

Behaviors

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

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

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

Build Targets• Build Settings -> Preprocessor Macros

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

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];

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();

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

Documentation

• Human-readable source code comments • Types:

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

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);

Documentation• Create documentation with AppleDoc

CocoaPods• Dependency management tool

• Idea comes from JavaEE (Maven)

• Runs on Ruby

• Save repository space

• Tutorial | Xcode Plugin

CocoaPods• Fix issue with Unit Tests:

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

References

Beginning iOS 6 Development

• Released: 9. Jan 2013

• http://www.iphonedevbook.com

NSnshipster

obscure topicsin cocoa &objective-c

mattt thompson

first edition

NSHipster• Released: 12. Nov. 2013

• http://www.nshipster.com

Stackoverflow

• Question and Answer site for programmers

• Most problems are solved

• Think first, then answer

• Don’t believe everything