SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
iOS Development
Methodology
Applying Best Practices to the Xcode World
Thursday, July 25, 13
This is a “Guided Exploration”, though I will be talking a lot.
Please feel free to ask questions at any time, I’d like this to be more of a discussion than a
presentation.
the Ruby community has been preaching test-first Agile methodologies for years, even if you don’t entirely buy into what they are
saying, they are pushing
the discussion forward and improving their best practices. Today I want to talk about applying some of these practices to iOS/
Objective-C development in Xcode.
Tom von Schwerdtner
SmartLogic
smartlogic.io
twitter.com/tvon
github.com/tvon
Thursday, July 25, 13
So you understand my perspective...
Developing websites for over 10 years
Ruby for past 2.5 years
iOS for past 1.5 years
What you’re in for
• Xcode’s bad influences
• Organization and Separation of Concerns
• Testing, and in Isolation
Code: https://github.com/smartlogic/ios-best-practices
or http://goo.gl/skgRY
Thursday, July 25, 13
This is what we’re going to talk about
This talk is aimed at beginner to intermediate developers (but hopefully something for
everyone)
Some familiarity with the structure of iOS apps is somewhat necessary.
Xcode’s Bad Influences
Thursday, July 25, 13
Xcode’s Bad Influences
• Lack of Project Structure
• Questionable Templates
Thursday, July 25, 13
Two primary gripes.
Filesystem does not match project organization
Lousy for any non-xcode view of the project (github/bitbucket)
Solutions
• Create Folders for Groups
• Strip Comments
• Avoid UITableViewController
Thursday, July 25, 13
First and foremost you can actually create folders for groups.
Ensures files added to that group will default to that folder.
UItableViewController adds unecessary noise (more on that later)
File comments are redundant in the world of git.
Better Templates
github.com/mneorr/Alcatraz/
Alcatraz - Xcode Plugin Manager
Thursday, July 25, 13
Use Alcatraz.
We have templates that should show up there soon.
Starting with an empty Xcode project is good practice.
It is important to know all the steps required to get to that Master-Detail view example
Better Templates
github.com/mneorr/Alcatraz/
Alcatraz - Xcode Plugin Manager
(or build from scratch, it’s good practice)
Thursday, July 25, 13
Use Alcatraz.
We have templates that should show up there soon.
Starting with an empty Xcode project is good practice.
It is important to know all the steps required to get to that Master-Detail view example
Organization and
Separation of Concerns
Thursday, July 25, 13
What are Concerns?
• Roles within the Application
• View Controllers
• Views
• Services
• Models
• Delegates (protocol implementations)
Thursday, July 25, 13
Concerns are the different components that make up your application.
Controllers generally coordinate other objects (models, views, services and delegates)
The other objects should essentially worry about themselves.
How to Separate?
• Organize into groups/folders
• Keep as isolated as possible
• Stand-alone protocol implementations
Thursday, July 25, 13
Organization is important, just put each in it’s own place
Isolation may take some practice, let’s touch on that real quick.
Data Source Isolation
Thursday, July 25, 13
A DataSource can be extremely simple.
Expose NSMutableArray “items” to be setup externally
Put Cell configuration code in the cell.
Data Source Isolation
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WidgetCell *cell = [tableView dequeueReusableCellWithIdentifier:WidgetCellIdentifier
forIndexPath:indexPath];
[cell configure:[self.items objectAtIndex:indexPath.row]];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
Thursday, July 25, 13
A DataSource can be extremely simple.
Expose NSMutableArray “items” to be setup externally
Put Cell configuration code in the cell.
DataSource Isolation
- (void)viewDidLoad
{
// (minor setup code)
// WidgetCellIdentifier declared in data source header
[self.tableView registerClass:[WidgetCell class]
forCellReuseIdentifier:WidgetCellIdentifier];
self.dataSource = [[WidgetsTableDataSource alloc] init];
self.tableView.dataSource = self.dataSource;
[WidgetAPIService getWidgets:^(NSMutableArray *widgets) {
self.dataSource.items = widgets;
[self.tableView reloadData];
}];
}
Thursday, July 25, 13
The entire UIViewController is basically the viewDidLoad method.
Our service loads items based on an API call.
This gives us a nicely isolated data source.
This is a good lead in to testing in isolation
Testing, and in Isolation
Thursday, July 25, 13
Testing in isolation means testing individual components without relying on external
components.
If you need to be sold on testing, in short it allows you to change and refactor your code and
knowing that doing so doesn’t break anything (or finding it and fixing it).
It reduces the
A Note on Tools
• BDD Tool: Kiwi
• Web Mocking: Nocilla
• (Ditch whatever Xcode gives you)
Thursday, July 25, 13
Hitting the network for every test is just a bad idea.
I like to test against a dev server until tests are greeen, then stub requests.
A Category Test
Testing the parsing of a timestamp string to an
NSDate
Thursday, July 25, 13
This is a good first test. It is isolated by nature (being a category).
This is a legitimate test, whenever you are parsing a string to turn it into something else you
should
test that your parsing works.
A Category Test
describe(@"NSDate+Timestamps", ^{
it(@"Initializes an NSDate from a timestamp string", ^{
NSString *timestamp = @"2010-02-03T04:05:06Z";
NSDate *date = [NSDate dateWithTimestamp:timestamp];
NSUInteger units = NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|
NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit;
NSDateComponents *components = [[NSCalendar currentCalendar]
components:units
fromDate:date];
[[theValue(components.year) should] equal:theValue(2010)];
[[theValue(components.month) should] equal:theValue(2)];
[[theValue(components.day) should] equal:theValue(3)];
[[theValue(components.hour) should] equal:theValue(4)];
[[theValue(components.minute) should] equal:theValue(5)];
[[theValue(components.second) should] equal:theValue(6)];
});
});
Thursday, July 25, 13
Our test. Give it a timestamp string, expect a proper NSDate back.
Implementation
Thursday, July 25, 13
If we TDD this, we should first get a “no known class method with selector...” error.
Implementation
+(id)dateWithTimestamp:(NSString *)string
{
return [NSDate date];
}
Thursday, July 25, 13
Implement the bare minimum to get past that error, and we get an NSDate but all of the
values are wrong.
Implementation
+(id)dateWithTimestamp:(NSString *)string
{
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
return [dateFormatter dateFromString:string];
}
Thursday, July 25, 13
At this point we implement the method and the test should pass.
Testing a Data Source
Thursday, July 25, 13
This is where we test our stand alone data source.
By splitting out the class, we can now test it without involving the view controller (and any
weight that may carry)
Testing a Data Source
describe(@"WidgetsTableDataSource", ^{
it(@"Returns WidgetCell configured with correct Widget", ^{
UITableView *tableView = [[UITableView alloc] init];
WidgetsTableDataSource *dataSource = [[WidgetsTableDataSource alloc] init];
Widget *widgetOne =[[Widget alloc] init];
widgetOne.name = @"First Widget";
Widget *widgetTwo =[[Widget alloc] init];
widgetTwo.name = @"Second Widget";
dataSource.items = [@[widgetOne, widgetTwo] mutableCopy];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *widgetCell = [tableView cellForRowAtIndexPath:indexPath];
[[((WidgetCell *)widgetCell).nameLabel.text should] equal:@"First Widget"];
});
});
Thursday, July 25, 13
Step through.
We initialize a table view (data source methods require it)
We initialize our data source
We add two widgets to the data source items.
We verify that cellForRowAtIndexPath returns the correct cell data.
Note that this somewhat inadvertently tests WidgetCell, but that is not our concern so much
as the verification that the right cell is returned.
Why test something this simple? Well, they say that the two hardest things in computer
science are cache invalidation, naming things and off-by-one errors.
Besides which, your items array could be a more complex collection.
Testing a Data Source
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WidgetCell *cell = [tableView dequeueReusableCellWithIdentifier:WidgetCellIdentifier
forIndexPath:indexPath];
[cell configure:[self.items objectAtIndex:indexPath.row]];
return cell;
}
Thursday, July 25, 13
Once again, the Data Source implementation.
Very simple.
Exercises for the Reader
• Test WidgetCell configuration
• Isolate the Data Source Test (don’t rely on widget cell)
Thursday, July 25, 13
There are improvements that could be made here, if interested.
Questions?
smartlogic.io
twitter.com/smartlogic
github.com/smartlogic
facebook.com/smartlogic
Thursday, July 25, 13
So that’s it. Depending on time left we can discuss testing techniques, organization or even
work on
a particular problem if someone has something they’d like to discuss.

Mais conteúdo relacionado

Mais procurados

Selenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkSelenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkDavid Rajah Selvaraj
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software TestingSergio Arroyo
 
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programingwahyuseptiansyah
 
Being good at waiting - Using Selenium to test Ajax-intensive pages
Being good at waiting - Using Selenium to test Ajax-intensive pages Being good at waiting - Using Selenium to test Ajax-intensive pages
Being good at waiting - Using Selenium to test Ajax-intensive pages Alexander Tarlinder
 
Some testing - Everything you should know about testing to go with @pedro_g_s...
Some testing - Everything you should know about testing to go with @pedro_g_s...Some testing - Everything you should know about testing to go with @pedro_g_s...
Some testing - Everything you should know about testing to go with @pedro_g_s...Sergio Arroyo
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for ProgrammersDavid Rodenas
 
Maintainable JavaScript 2011
Maintainable JavaScript 2011Maintainable JavaScript 2011
Maintainable JavaScript 2011Nicholas Zakas
 
12advanced Swing
12advanced Swing12advanced Swing
12advanced SwingAdil Jafri
 
NodeJS Spring style Inversifyjs
NodeJS Spring style InversifyjsNodeJS Spring style Inversifyjs
NodeJS Spring style InversifyjsMathieu Breton
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swingNataraj Dg
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS ProgrammersDavid Rodenas
 
JS Conf 2018 AU Node.js applications diagnostics under the hood
JS Conf 2018 AU Node.js applications diagnostics under the hoodJS Conf 2018 AU Node.js applications diagnostics under the hood
JS Conf 2018 AU Node.js applications diagnostics under the hoodNikolay Matvienko
 
Unit testing in xcode 8 with swift
Unit testing in xcode 8 with swiftUnit testing in xcode 8 with swift
Unit testing in xcode 8 with swiftallanh0526
 
[2019] PAYCO 매거진 서버 Kotlin 적용기
[2019] PAYCO 매거진 서버 Kotlin 적용기[2019] PAYCO 매거진 서버 Kotlin 적용기
[2019] PAYCO 매거진 서버 Kotlin 적용기NHN FORWARD
 
#codemotion2016: Everything you should know about testing to go with @pedro_g...
#codemotion2016: Everything you should know about testing to go with @pedro_g...#codemotion2016: Everything you should know about testing to go with @pedro_g...
#codemotion2016: Everything you should know about testing to go with @pedro_g...Sergio Arroyo
 
Experienced Selenium Interview questions
Experienced Selenium Interview questionsExperienced Selenium Interview questions
Experienced Selenium Interview questionsarchana singh
 

Mais procurados (20)

Java
JavaJava
Java
 
Selenium Webdriver with data driven framework
Selenium Webdriver with data driven frameworkSelenium Webdriver with data driven framework
Selenium Webdriver with data driven framework
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
 
J query
J queryJ query
J query
 
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
 
Clean Test
Clean TestClean Test
Clean Test
 
Being good at waiting - Using Selenium to test Ajax-intensive pages
Being good at waiting - Using Selenium to test Ajax-intensive pages Being good at waiting - Using Selenium to test Ajax-intensive pages
Being good at waiting - Using Selenium to test Ajax-intensive pages
 
Some testing - Everything you should know about testing to go with @pedro_g_s...
Some testing - Everything you should know about testing to go with @pedro_g_s...Some testing - Everything you should know about testing to go with @pedro_g_s...
Some testing - Everything you should know about testing to go with @pedro_g_s...
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for Programmers
 
Maintainable JavaScript 2011
Maintainable JavaScript 2011Maintainable JavaScript 2011
Maintainable JavaScript 2011
 
12advanced Swing
12advanced Swing12advanced Swing
12advanced Swing
 
NodeJS Spring style Inversifyjs
NodeJS Spring style InversifyjsNodeJS Spring style Inversifyjs
NodeJS Spring style Inversifyjs
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
 
JS Conf 2018 AU Node.js applications diagnostics under the hood
JS Conf 2018 AU Node.js applications diagnostics under the hoodJS Conf 2018 AU Node.js applications diagnostics under the hood
JS Conf 2018 AU Node.js applications diagnostics under the hood
 
Unit testing in xcode 8 with swift
Unit testing in xcode 8 with swiftUnit testing in xcode 8 with swift
Unit testing in xcode 8 with swift
 
[2019] PAYCO 매거진 서버 Kotlin 적용기
[2019] PAYCO 매거진 서버 Kotlin 적용기[2019] PAYCO 매거진 서버 Kotlin 적용기
[2019] PAYCO 매거진 서버 Kotlin 적용기
 
#codemotion2016: Everything you should know about testing to go with @pedro_g...
#codemotion2016: Everything you should know about testing to go with @pedro_g...#codemotion2016: Everything you should know about testing to go with @pedro_g...
#codemotion2016: Everything you should know about testing to go with @pedro_g...
 
JS and patterns
JS and patternsJS and patterns
JS and patterns
 
Experienced Selenium Interview questions
Experienced Selenium Interview questionsExperienced Selenium Interview questions
Experienced Selenium Interview questions
 

Semelhante a iOS Development Methodology

Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileKonstantin Loginov
 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Buşra Deniz, CSM
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e bigAndy Peterson
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentVu Tran Lam
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It'sJim Lynch
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testingpleeps
 
Testing iOS Apps
Testing iOS AppsTesting iOS Apps
Testing iOS AppsC4Media
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonbeITconference
 
10 tips for a reusable architecture
10 tips for a reusable architecture10 tips for a reusable architecture
10 tips for a reusable architectureJorge Ortiz
 
Sitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testingSitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testingnonlinear creations
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsYura Nosenko
 
Unit and functional testing with Siesta
Unit and functional testing with SiestaUnit and functional testing with Siesta
Unit and functional testing with SiestaGrgur Grisogono
 
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Carl Brown
 
FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023Matthew Groves
 

Semelhante a iOS Development Methodology (20)

Mini training - Moving to xUnit.net
Mini training - Moving to xUnit.netMini training - Moving to xUnit.net
Mini training - Moving to xUnit.net
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve Mobile
 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone Development
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Testing iOS Apps
Testing iOS AppsTesting iOS Apps
Testing iOS Apps
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
 
10 tips for a reusable architecture
10 tips for a reusable architecture10 tips for a reusable architecture
10 tips for a reusable architecture
 
Sitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testingSitecore 7: A developers quest to mastering unit testing
Sitecore 7: A developers quest to mastering unit testing
 
Frontend training
Frontend trainingFrontend training
Frontend training
 
Fewd week6 slides
Fewd week6 slidesFewd week6 slides
Fewd week6 slides
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
 
Unit and functional testing with Siesta
Unit and functional testing with SiestaUnit and functional testing with Siesta
Unit and functional testing with Siesta
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
 
Unit Testing in iOS
Unit Testing in iOSUnit Testing in iOS
Unit Testing in iOS
 
FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023
 

Mais de SmartLogic

Writing Game Servers with Elixir
Writing Game Servers with ElixirWriting Game Servers with Elixir
Writing Game Servers with ElixirSmartLogic
 
All Aboard The Stateful Train
All Aboard The Stateful TrainAll Aboard The Stateful Train
All Aboard The Stateful TrainSmartLogic
 
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan IvovichDC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan IvovichSmartLogic
 
Monitoring Your Elixir Application with Prometheus
Monitoring Your Elixir Application with PrometheusMonitoring Your Elixir Application with Prometheus
Monitoring Your Elixir Application with PrometheusSmartLogic
 
Going Multi-Node
Going Multi-NodeGoing Multi-Node
Going Multi-NodeSmartLogic
 
Kubernetes and docker
Kubernetes and dockerKubernetes and docker
Kubernetes and dockerSmartLogic
 
Serializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara HacopianSerializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara HacopianSmartLogic
 
Guide to food foraging by SmartLogic's Kei Ellerbrock
Guide to food foraging by SmartLogic's Kei EllerbrockGuide to food foraging by SmartLogic's Kei Ellerbrock
Guide to food foraging by SmartLogic's Kei EllerbrockSmartLogic
 
Introduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogicIntroduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogicSmartLogic
 
How SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichHow SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichSmartLogic
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageSmartLogic
 
Effective ActiveRecord
Effective ActiveRecordEffective ActiveRecord
Effective ActiveRecordSmartLogic
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive CocoaSmartLogic
 
CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!SmartLogic
 
Deploying Rails Apps with Chef and Capistrano
 Deploying Rails Apps with Chef and Capistrano Deploying Rails Apps with Chef and Capistrano
Deploying Rails Apps with Chef and CapistranoSmartLogic
 
From Slacker to Hacker, Practical Tips for Learning to Code
From Slacker to Hacker, Practical Tips for Learning to CodeFrom Slacker to Hacker, Practical Tips for Learning to Code
From Slacker to Hacker, Practical Tips for Learning to CodeSmartLogic
 
The Language of Abstraction in Software Development
The Language of Abstraction in Software DevelopmentThe Language of Abstraction in Software Development
The Language of Abstraction in Software DevelopmentSmartLogic
 
Android Testing: An Overview
Android Testing: An OverviewAndroid Testing: An Overview
Android Testing: An OverviewSmartLogic
 
Intro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS DevelopmentIntro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS DevelopmentSmartLogic
 
Logstash: Get to know your logs
Logstash: Get to know your logsLogstash: Get to know your logs
Logstash: Get to know your logsSmartLogic
 

Mais de SmartLogic (20)

Writing Game Servers with Elixir
Writing Game Servers with ElixirWriting Game Servers with Elixir
Writing Game Servers with Elixir
 
All Aboard The Stateful Train
All Aboard The Stateful TrainAll Aboard The Stateful Train
All Aboard The Stateful Train
 
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan IvovichDC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
 
Monitoring Your Elixir Application with Prometheus
Monitoring Your Elixir Application with PrometheusMonitoring Your Elixir Application with Prometheus
Monitoring Your Elixir Application with Prometheus
 
Going Multi-Node
Going Multi-NodeGoing Multi-Node
Going Multi-Node
 
Kubernetes and docker
Kubernetes and dockerKubernetes and docker
Kubernetes and docker
 
Serializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara HacopianSerializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara Hacopian
 
Guide to food foraging by SmartLogic's Kei Ellerbrock
Guide to food foraging by SmartLogic's Kei EllerbrockGuide to food foraging by SmartLogic's Kei Ellerbrock
Guide to food foraging by SmartLogic's Kei Ellerbrock
 
Introduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogicIntroduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogic
 
How SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichHow SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan Ivovich
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
 
Effective ActiveRecord
Effective ActiveRecordEffective ActiveRecord
Effective ActiveRecord
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!
 
Deploying Rails Apps with Chef and Capistrano
 Deploying Rails Apps with Chef and Capistrano Deploying Rails Apps with Chef and Capistrano
Deploying Rails Apps with Chef and Capistrano
 
From Slacker to Hacker, Practical Tips for Learning to Code
From Slacker to Hacker, Practical Tips for Learning to CodeFrom Slacker to Hacker, Practical Tips for Learning to Code
From Slacker to Hacker, Practical Tips for Learning to Code
 
The Language of Abstraction in Software Development
The Language of Abstraction in Software DevelopmentThe Language of Abstraction in Software Development
The Language of Abstraction in Software Development
 
Android Testing: An Overview
Android Testing: An OverviewAndroid Testing: An Overview
Android Testing: An Overview
 
Intro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS DevelopmentIntro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS Development
 
Logstash: Get to know your logs
Logstash: Get to know your logsLogstash: Get to know your logs
Logstash: Get to know your logs
 

Último

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

iOS Development Methodology

  • 1. iOS Development Methodology Applying Best Practices to the Xcode World Thursday, July 25, 13 This is a “Guided Exploration”, though I will be talking a lot. Please feel free to ask questions at any time, I’d like this to be more of a discussion than a presentation. the Ruby community has been preaching test-first Agile methodologies for years, even if you don’t entirely buy into what they are saying, they are pushing the discussion forward and improving their best practices. Today I want to talk about applying some of these practices to iOS/ Objective-C development in Xcode.
  • 2. Tom von Schwerdtner SmartLogic smartlogic.io twitter.com/tvon github.com/tvon Thursday, July 25, 13 So you understand my perspective... Developing websites for over 10 years Ruby for past 2.5 years iOS for past 1.5 years
  • 3. What you’re in for • Xcode’s bad influences • Organization and Separation of Concerns • Testing, and in Isolation Code: https://github.com/smartlogic/ios-best-practices or http://goo.gl/skgRY Thursday, July 25, 13 This is what we’re going to talk about This talk is aimed at beginner to intermediate developers (but hopefully something for everyone) Some familiarity with the structure of iOS apps is somewhat necessary.
  • 5. Xcode’s Bad Influences • Lack of Project Structure • Questionable Templates Thursday, July 25, 13 Two primary gripes. Filesystem does not match project organization Lousy for any non-xcode view of the project (github/bitbucket)
  • 6. Solutions • Create Folders for Groups • Strip Comments • Avoid UITableViewController Thursday, July 25, 13 First and foremost you can actually create folders for groups. Ensures files added to that group will default to that folder. UItableViewController adds unecessary noise (more on that later) File comments are redundant in the world of git.
  • 7. Better Templates github.com/mneorr/Alcatraz/ Alcatraz - Xcode Plugin Manager Thursday, July 25, 13 Use Alcatraz. We have templates that should show up there soon. Starting with an empty Xcode project is good practice. It is important to know all the steps required to get to that Master-Detail view example
  • 8. Better Templates github.com/mneorr/Alcatraz/ Alcatraz - Xcode Plugin Manager (or build from scratch, it’s good practice) Thursday, July 25, 13 Use Alcatraz. We have templates that should show up there soon. Starting with an empty Xcode project is good practice. It is important to know all the steps required to get to that Master-Detail view example
  • 9. Organization and Separation of Concerns Thursday, July 25, 13
  • 10. What are Concerns? • Roles within the Application • View Controllers • Views • Services • Models • Delegates (protocol implementations) Thursday, July 25, 13 Concerns are the different components that make up your application. Controllers generally coordinate other objects (models, views, services and delegates) The other objects should essentially worry about themselves.
  • 11. How to Separate? • Organize into groups/folders • Keep as isolated as possible • Stand-alone protocol implementations Thursday, July 25, 13 Organization is important, just put each in it’s own place Isolation may take some practice, let’s touch on that real quick.
  • 12. Data Source Isolation Thursday, July 25, 13 A DataSource can be extremely simple. Expose NSMutableArray “items” to be setup externally Put Cell configuration code in the cell.
  • 13. Data Source Isolation - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WidgetCell *cell = [tableView dequeueReusableCellWithIdentifier:WidgetCellIdentifier forIndexPath:indexPath]; [cell configure:[self.items objectAtIndex:indexPath.row]]; return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.items count]; } Thursday, July 25, 13 A DataSource can be extremely simple. Expose NSMutableArray “items” to be setup externally Put Cell configuration code in the cell.
  • 14. DataSource Isolation - (void)viewDidLoad { // (minor setup code) // WidgetCellIdentifier declared in data source header [self.tableView registerClass:[WidgetCell class] forCellReuseIdentifier:WidgetCellIdentifier]; self.dataSource = [[WidgetsTableDataSource alloc] init]; self.tableView.dataSource = self.dataSource; [WidgetAPIService getWidgets:^(NSMutableArray *widgets) { self.dataSource.items = widgets; [self.tableView reloadData]; }]; } Thursday, July 25, 13 The entire UIViewController is basically the viewDidLoad method. Our service loads items based on an API call. This gives us a nicely isolated data source. This is a good lead in to testing in isolation
  • 15. Testing, and in Isolation Thursday, July 25, 13 Testing in isolation means testing individual components without relying on external components. If you need to be sold on testing, in short it allows you to change and refactor your code and knowing that doing so doesn’t break anything (or finding it and fixing it). It reduces the
  • 16. A Note on Tools • BDD Tool: Kiwi • Web Mocking: Nocilla • (Ditch whatever Xcode gives you) Thursday, July 25, 13 Hitting the network for every test is just a bad idea. I like to test against a dev server until tests are greeen, then stub requests.
  • 17. A Category Test Testing the parsing of a timestamp string to an NSDate Thursday, July 25, 13 This is a good first test. It is isolated by nature (being a category). This is a legitimate test, whenever you are parsing a string to turn it into something else you should test that your parsing works.
  • 18. A Category Test describe(@"NSDate+Timestamps", ^{ it(@"Initializes an NSDate from a timestamp string", ^{ NSString *timestamp = @"2010-02-03T04:05:06Z"; NSDate *date = [NSDate dateWithTimestamp:timestamp]; NSUInteger units = NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit| NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit; NSDateComponents *components = [[NSCalendar currentCalendar] components:units fromDate:date]; [[theValue(components.year) should] equal:theValue(2010)]; [[theValue(components.month) should] equal:theValue(2)]; [[theValue(components.day) should] equal:theValue(3)]; [[theValue(components.hour) should] equal:theValue(4)]; [[theValue(components.minute) should] equal:theValue(5)]; [[theValue(components.second) should] equal:theValue(6)]; }); }); Thursday, July 25, 13 Our test. Give it a timestamp string, expect a proper NSDate back.
  • 19. Implementation Thursday, July 25, 13 If we TDD this, we should first get a “no known class method with selector...” error.
  • 20. Implementation +(id)dateWithTimestamp:(NSString *)string { return [NSDate date]; } Thursday, July 25, 13 Implement the bare minimum to get past that error, and we get an NSDate but all of the values are wrong.
  • 21. Implementation +(id)dateWithTimestamp:(NSString *)string { NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]; return [dateFormatter dateFromString:string]; } Thursday, July 25, 13 At this point we implement the method and the test should pass.
  • 22. Testing a Data Source Thursday, July 25, 13 This is where we test our stand alone data source. By splitting out the class, we can now test it without involving the view controller (and any weight that may carry)
  • 23. Testing a Data Source describe(@"WidgetsTableDataSource", ^{ it(@"Returns WidgetCell configured with correct Widget", ^{ UITableView *tableView = [[UITableView alloc] init]; WidgetsTableDataSource *dataSource = [[WidgetsTableDataSource alloc] init]; Widget *widgetOne =[[Widget alloc] init]; widgetOne.name = @"First Widget"; Widget *widgetTwo =[[Widget alloc] init]; widgetTwo.name = @"Second Widget"; dataSource.items = [@[widgetOne, widgetTwo] mutableCopy]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; UITableViewCell *widgetCell = [tableView cellForRowAtIndexPath:indexPath]; [[((WidgetCell *)widgetCell).nameLabel.text should] equal:@"First Widget"]; }); }); Thursday, July 25, 13 Step through. We initialize a table view (data source methods require it) We initialize our data source We add two widgets to the data source items. We verify that cellForRowAtIndexPath returns the correct cell data. Note that this somewhat inadvertently tests WidgetCell, but that is not our concern so much as the verification that the right cell is returned. Why test something this simple? Well, they say that the two hardest things in computer science are cache invalidation, naming things and off-by-one errors. Besides which, your items array could be a more complex collection.
  • 24. Testing a Data Source - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WidgetCell *cell = [tableView dequeueReusableCellWithIdentifier:WidgetCellIdentifier forIndexPath:indexPath]; [cell configure:[self.items objectAtIndex:indexPath.row]]; return cell; } Thursday, July 25, 13 Once again, the Data Source implementation. Very simple.
  • 25. Exercises for the Reader • Test WidgetCell configuration • Isolate the Data Source Test (don’t rely on widget cell) Thursday, July 25, 13 There are improvements that could be made here, if interested.
  • 26. Questions? smartlogic.io twitter.com/smartlogic github.com/smartlogic facebook.com/smartlogic Thursday, July 25, 13 So that’s it. Depending on time left we can discuss testing techniques, organization or even work on a particular problem if someone has something they’d like to discuss.