SlideShare a Scribd company logo
Architecting iOS Project
Massimo Oliviero
Massimo Oliviero
Freelance Software Developer
web http://www.massimooliviero.net
email massimo.oliviero@gmail.com
slide http://www.slideshare.net/MassimoOliviero
twitter @maxoly
Massimo Oliviero
http://pragmamark.org/
La prima community di sviluppatori iOS e Mac OS X in Italia.
https://www.facebook.com/groups/pragmamark/
Agenda
‣ Project, how to design Xcode project
‣ Application, how to design an iOS app
‣ Resources, links, books and videos
Source code
Kimera
A simple iOS application for educational purpose
https://github.com/maxoly/Kimera
Project
Project
‣ Conventions, how to naming file and folders
‣ Structure, how make the foundation of the project
‣ Folders, how to organize files and folders
Conventions
Naming Conventions
‣ First establish a naming convention for all the things
for file names, class names, project names, images, etc.
‣ Use Pascal Case for files, folders and class
start with a capital letter i.e. Controllers, MyClass, BestAppEver, etc.
‣ Use Camel Case for methods, properties & variables
start with a lowercase letter i.e setFirstName:, userPassword, etc.
‣ Avoid using of acronyms and abbreviations
What the hell does it mean“usrPswdLbl”? Yuck!
Coding Conventions
‣ Choose your coding conventions & style
there are ton of conventions out there
‣ K&R Style, or Allman Indent Style
http://en.wikipedia.org/wiki/Indent_style
‣ Also read Coding Guidelines for Cocoa by Apple
http://developer.apple.com/library/mac/#documentation/Cocoa/
Conceptual/CodingGuidelines/CodingGuidelines.html
‣ But most important, choose a convention and respect it
the important thing is always be consistent in your project
Structure
Structure
‣ Create a specific workspace
don’t let Xcode do it for you
‣ Setting up projects with correct name and prefix
use simple word (only alphanumeric) and at least 3 chars for prefix
‣ Create a Build Automation to scripting common tasks
to compiling source code or to deploy artifacts with one command
Structure
‣ Create a AdHoc and AppStore Build Configuration
So you can handle configuration for different destination
‣ Configure Build Settings to improve quality
i.e. you can enable Static Analyzer or Treat Warnings as Errors
‣ Manage third-part libraries with CocoaPods
it reduces headaches of storing/managing 3rd party libraries
Workspace
Project Name & Prefix
‣ Choose a simple Program Name
Only alphanumeric characters, avoid spaces
‣ Choose a right Class Prefix
At least 3 chars, use product name's acronym
‣ Choose your Personal Prefix
Use it in your Library Projects
‣ Use Automatic Reference Counting
If app targets iOS 5.0 or above
Build Automation
‣ It’s the act of automating a wide variety of tasks
you can use build tools like Ant, Maven, Make , CMake or Rake
‣ At least you must automate Compiling and Deploying
compiling and deploying are the most common tasks for developer
‣ You can also automate Testing and Docs generation
they are useful to use in combination with a Continuous Integration
AdHoc & AppStore Configuration
‣ Use different Configurations to specialize the behavior
i.e. Code Signing Identity, Preprocessor Macros, Linker Flags, etc.
‣ Use AdHoc Configuration to deploy testing app
i.e. app for TestFlight with its own Code Signing Identity & Linker Flags
‣ Use AppStore Configuration to deploy on App Store
Duplicate Release Configuration to use the same optimizations
Build Settings
‣ Enable Run Static Analyzer
run the Clang static analysis tool on source files
‣ Enable Treat Warning as Errors
it causes all warnings to be treated as errors
‣ Disable Compress PNG Files
instead use ImageOptim
CocoaPods
‣ Manage third-part libraries with CocoaPods
download from http://cocoapods.org/
‣ CocoaPods manage dependency for you
it download source files, imports headers and configures flags
‣ It’s like Ruby Gem but for Objective-C!
you can search pods, install & update with one command
Folders
Folders
‣ Put things in the right place
...and everything makes sense, unfortunately, Xcode doesn’t help us
‣ Map all Xcode group folder to file system directory
Xcode group folder don’t represent physical folder
‣ Please remove Supporting Files group folder
Who wants“Supporting Files”anymore? yuck!
My folders structure
‣ Application
specific app related stuff like AppDelegate, main.m, .pch etc
‣ Controllers
view (.xib) and view controller stuff put together (obviously)
‣ Library
specific application classes like helpers, base classes, services, etc
My folder structure
‣ Models
application domain models and entities, Core Data model too
‣ Resources
assets like images, fonts, sounds, videos, etc.
‣ Vendors
third part libraries and frameworks
Controllers
‣ Put .xib, .h and .m together in the same folders
‣ One (physical) folder for each view controller
‣ If there are too many, group them into a subfolder
‣ Group them by tab (TabBar) or by functions
Resources
‣ One folder for each type of asset
images, fonts, sounds, videos, strings, plist, samples
‣ One subfolder for each type of image
buttons, backgrounds, logos, shapes, icons, app (splash etc.)
‣ If your app support multiple themes, create a hierarchy
themes > themes name > images, fonts, etc.
‣ Name image files based on state
“button_blue_normal.png”,“button_blue_highlighted.png”, etc.
Application
Application
‣ Design, a quick recap to design principles and patterns
‣ Layers, how to organize your app classes
‣ Compositions, a group of reusable components
‣ Best Practices, a list of useful techniques
Design
Design
‣ Typically an application is divided into layers
A layer is a black box with a contract that define an input and output
‣ To increase the cohesion and decoupling of the software
The layers, if well designed, help to decouple and increase the cohesion
‣ Cohesion indicates strongly related software module
it would be a subroutine, class or library with common responsibilities
‣ Coupling measure the level of dependency
between two software module, such as classes, functions or library
Design Principles
‣ Single Responsibility Principle
A module should have a single responsibility, and that responsibility
should be entirely encapsulated by the module
‣ Open Closed Principle
A module should be open for extension but closed for modifications
‣ Liskov’s Substitution Principle
Derived types must be completely substitutable for their base types
Design Principles
‣ Interface Segregation Principle
Clients should not be forced to depend upon interfaces that they don't
use
‣ Dependency Inversion Principle
High-level modules should not depend on low-level modules. Both
should depend on abstractions. Abstractions should not depend on
details. Details should depend on abstractions
‣ SOLID: the "first five principles"
Single responsibility, Open-closed, Liskov substitution, Interface
segregation and Dependency inversion
From Principles to Patterns
‣ Design Pattern is a general reusable solution
to a commonly occurring problem within a given context
‣ It’s a description or template for how to solve a problem
It’s not a finished design that can be transformed into source code
‣ There are many types of design patterns
Architectural, Algorithm strategy, Computational, Implementation
strategy, Structural, etc.
Most Common Design Patterns
‣ Model View Controller Design Pattern
It’s a fundamental design pattern in Objective-C.
‣ Singleton Design Pattern
For your information the AppDelegate is a singleton
‣ Chain Of Responsibility Design Pattern
Have you ever met the Next Responder or the First Responder?
Layers
Layers
‣ Layer represents a logical section of the system
Layer enforce reusability and testability
‣ A typical client/server app have at least 3 layers
Presentation Layer, Business Layer and Data Access Layer
Layers
Presentation Layer
Data Access Layer
Business Layer
Views
Controllers
Service Layer Domain Model Layer
Persistence Layer Network Layer
Presentation Layer
Presentation Layer
‣ It have 2 components: the UI and the presentation logic
in Cocoa the UI is the View and the presentation logic is the Controller
‣ Cocoa adopt Model View Controller Design Pattern
the Presentation Layer is already in iOS SDK out-of-the-box
‣ Advanced Appearance Customization with Theme
user Appearance Proxy and Theme technique to customize UI.
Theme
‣ Create a @protocol that define a“theme”
‣ Implements @protocol in your theme class
@protocol MGATheme <NSObject>
- (void)themeLabel:(UILabel *)label type:(MGAThemeLabelType)type;
- (void)themeButton:(UIButton *)button type:(MGAThemeButtonType)type;
@end
@interface MGABlueTheme : NSObject<MGATheme>
@end
@interface MGAMetalTheme : NSObject<MGATheme>
@end
Presentation Layer
Presentation Layer - (View Controller)
UIView
UIViewController Theme
Model
Appearance
Business Layer
Business Layer
‣ It holds the specific app Business Logic and Behaviors
It is concerned with the retrieval, processing, transformation, and
management of application data; application of business rules and
policies
‣ The Domain Model is a conceptual model of business
It describes the various entities, their attributes, roles, and relationships,
plus the constraints that govern the problem domain
‣ Business Layer gets data through a Service Layer
Service Layer defines an application's boundary with a layer of services
that establishes a set of available operations and coordinates the
application's response in each operation
Domain Model Layer
‣ Domain Model
An object model of the domain that incorporates both behavior and
data
‣ You can use simple Objective-C objects
A plain old Objective-C object that inheriting from NSObject
‣ Or you can use Core Data objects
you can extend the class NSMangedObject with your Objective-C class
Service Layer
‣ Service Layers is a design pattern
The benefits a Service Layer provides is that it defines a common set of
application operations available to different clients and coordinates the
response in each operation.
‣ Service Layer uses Data Access Layer to access data
Service Layer uses DAL to performs the task of retrieving and storing
data both from server via network and from database
‣ Service Layer is used by ViewController
No more a ton of line of codes in your ViewController, instead few lines
of simple Service Layer calls
Data Access Layer
Data Access Layer
‣ It’s a layer which provides simplified access to data
The data may be stored in a persistent storage like SQLite or in a
backend accessible by network
‣ It may uses a Persistence Layer or Network Layer
Both exposes a simplify contract to access data
Persistence Layer
‣ The persistence layer deals with persisting
The persistence layer is responsible for manipulating the database, and
it is used by the service layer
‣ You can use Core Data as Persistence Layer
Or, in alternative, you can use FMDB for direct access to SQLite
Network Layer
‣ Network Layer is responsible of all networking calls
‣ You can use AFNetworking as Network Layer
AFNetworking is a delightful networking library for iOS and Mac OS X.
It's built on top of NSURLConnection, NSOperation, and other familiar
Foundation technologies
Composition
Composition
‣ It’s a way to combine objects into more complex ones
Compositions are a critical building block of many basic data structures,
including the tagged union, the linked list, and the binary tree, as well
as the object used in object-oriented programming
‣ In a real-world app composition takes an important role
On iOS / OS X App composition is necessary for a good layering and for
a structure UI.
Composition - Custom Views
‣ Custom Views are an example of composition
A custom view is used to manage small portions of the interface in
order to recycle the content and its management
‣ In a real-world iOS/OS App there are many custom views
For example, all views that must be inserted in a scroll view, or all those
portions of the view that occur multiple times in different view and only
with different content.
Best Practices
General Best Practice
‣ Use Automatic Reference Counting
Always use ARC. All new code should be written using ARC, and all
legacy code should be updated to use ARC
‣ Use AppDelegate as Singleton
Create all common and singleton objects in App Delegate and then
expose them by UIResponder Category
Coding Best Practice
‣ Create a property for every ivar and use self to access it
Always create a @property for every data member and use“self.name”
to access it throughout your class implementation
‣ Alway declare“atomic”or“nonatomic”attribute
Always use the“nonatomic”attribute on your properties, unless you are
writing a thread-safe class and actually need access to be atomic
‣ User literals and modern Objective-C syntactic sugar
The source code will be less verbose and more clear.
Presentation Best Practice
‣ Create a base UIViewController
Create a MYBaseViewController from which all the view controllers
inherit. In this way all the controllers can inherit common behavior.
‣ Create a base UIView
Create a MYBaseView from which all the custom views inherit. In this
way all the views can inherit common style and appearance
‣ Create a base UITableViewCell
Create a MYBaseTableViewCell from which all the custom table view
cells inherit. In this way all the cells can inherit common style and
appearance
Code Design Best Practice
‣ API Design
Pay attention to the design of your API. Learn your target platform's
conventions before coding. Define the rules that are in accordance with
the convention of language
‣ Block and Delegation
When should I use blocks instead of delegation for callbacks? Pay
attention to this topic and alway look at Apple docs to see how they
done
Resources
Links
‣ Blocks vs Delegation
http://thejoeconwayblog.wordpress.com/2012/05/29/blocks-or-
delegation/
‣ API Design
http://mattgemmell.com/2012/05/24/api-design/
‣ Modern Objective-C
http://www.slideshare.net/giuseppearici/modern-objectivec-pragma-
night
Links
‣ objc.io - A periodical about best practices and advanced
techniques in Objective-C
http://www.objc.io/
‣ Automatic Reference Counting
http://www.slideshare.net/giuseppearici/pragma-night-
automaticreferencecounting
Videos
‣ Customizing the Appearance of UIKit Controls
Session 114 - WWDC 2011 Session Videos
‣ Advanced Appearance Customization on iOS
Session 216 - WWDC 2012 Session Videos
Books
‣ Cocoa Design Patterns
‣ Erik M. Buck & Donald A. Yacktman
‣ Addison Wesley
Books
‣ Patterns Of Enterprise Application
Architecture
‣ Martin Fowler
‣ Addison-Wesley Professional
‣ updates: http://martinfowler.com/
books/eaa.html
Thank you
Massimo Oliviero
massimo.oliviero@gmail.com
http://www.massimooliviero.net
follow me on twitter @maxoly
http://www.slideshare.net/MassimoOliviero
https://speakerdeck.com/massimooliviero
Ad

More Related Content

What's hot (20)

Support POO Java Deuxième Partie
Support POO Java Deuxième PartieSupport POO Java Deuxième Partie
Support POO Java Deuxième Partie
ENSET, Université Hassan II Casablanca
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
allanh0526
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
Jonathan Simon
 
cours Android.pptx
cours Android.pptxcours Android.pptx
cours Android.pptx
YaminaGh1
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
Diksha Bhargava
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
Mudasir Qazi
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
Mudasir Qazi
 
Intro to vue.js
Intro to vue.jsIntro to vue.js
Intro to vue.js
TechMagic
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
Dareen Alhiyari
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
React hooks
React hooksReact hooks
React hooks
Assaf Gannon
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
Gourav Kumar Saini
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
Bongwon Lee
 
Composite pattern
Composite patternComposite pattern
Composite pattern
Shakil Ahmed
 
Solid principles
Solid principlesSolid principles
Solid principles
Declan Whelan
 
React js
React jsReact js
React js
Rajesh Kolla
 
Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)
Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)
Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)
Derek Lee
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
allanh0526
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
Jonathan Simon
 
cours Android.pptx
cours Android.pptxcours Android.pptx
cours Android.pptx
YaminaGh1
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
Mudasir Qazi
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
Mudasir Qazi
 
Intro to vue.js
Intro to vue.jsIntro to vue.js
Intro to vue.js
TechMagic
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
Dareen Alhiyari
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
Bongwon Lee
 
Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)
Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)
Why I ❤️ Kotlin Multiplatform (and want YOU to also ❤️ Kotlin Multiplatform)
Derek Lee
 

Viewers also liked (14)

Domain-driven design - tactical patterns
Domain-driven design - tactical patternsDomain-driven design - tactical patterns
Domain-driven design - tactical patterns
Tom Janssens
 
Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?
VMware Tanzu
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
Steve Barbour
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
Cyrille Martraire
 
Go-jek's Go-Food Chatbot
Go-jek's Go-Food ChatbotGo-jek's Go-Food Chatbot
Go-jek's Go-Food Chatbot
Irwansyah Irwansyah
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVC
Steven Smith
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
Pascal Laurin
 
Beyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO codeBeyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO code
Matthias Noback
 
Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)
IT Arena
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
Irwansyah Irwansyah
 
Domain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsDomain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron Edwards
Hakka Labs
 
Automation of functional tests using JMeter Part II (in Polish)
Automation of functional tests using JMeter Part II (in Polish)Automation of functional tests using JMeter Part II (in Polish)
Automation of functional tests using JMeter Part II (in Polish)
Tieto Corporation
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
Mariam Hakobyan
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
Sam Newman
 
Domain-driven design - tactical patterns
Domain-driven design - tactical patternsDomain-driven design - tactical patterns
Domain-driven design - tactical patterns
Tom Janssens
 
Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?
VMware Tanzu
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
Steve Barbour
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
Cyrille Martraire
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVC
Steven Smith
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
Pascal Laurin
 
Beyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO codeBeyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO code
Matthias Noback
 
Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)
IT Arena
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
Irwansyah Irwansyah
 
Domain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsDomain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron Edwards
Hakka Labs
 
Automation of functional tests using JMeter Part II (in Polish)
Automation of functional tests using JMeter Part II (in Polish)Automation of functional tests using JMeter Part II (in Polish)
Automation of functional tests using JMeter Part II (in Polish)
Tieto Corporation
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
Mariam Hakobyan
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
Sam Newman
 
Ad

Similar to Architecting iOS Project (20)

Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & Architecture
Massimo Oliviero
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
Manoj Ellappan
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
Yuri Visser
 
Managing Phone Dev Projects
Managing Phone Dev ProjectsManaging Phone Dev Projects
Managing Phone Dev Projects
John McKerrell
 
Android crash course
Android crash courseAndroid crash course
Android crash course
Showmax Engineering
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
Prageeth Sandakalum
 
Getting Started in Custom Programming for Talent Sourcing
Getting Started in Custom Programming for Talent SourcingGetting Started in Custom Programming for Talent Sourcing
Getting Started in Custom Programming for Talent Sourcing
Glenn Gutmacher
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the information
Toushik Paul
 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patterns
Corey Oordt
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Steven Smith
 
FLossEd-BK Tequila Framework3.2.1
FLossEd-BK Tequila Framework3.2.1FLossEd-BK Tequila Framework3.2.1
FLossEd-BK Tequila Framework3.2.1
Siwawong Wuttipongprasert
 
Appsody
AppsodyAppsody
Appsody
Khawar Nehal [email protected]
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
Sam Nasr, MCSA, MVP
 
Design pattern
Design patternDesign pattern
Design pattern
Shreyance Jain
 
Vipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentationVipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentation
Vipul Divyanshu
 
Developing sites with Magnolia 4 / STK
Developing sites with Magnolia 4 / STKDeveloping sites with Magnolia 4 / STK
Developing sites with Magnolia 4 / STK
guest0afb3
 
Reusable Apps
Reusable AppsReusable Apps
Reusable Apps
DjangoCon2008
 
slides oif mlsa oigf fhdhd cgdgd gggd bdg.pptx
slides oif mlsa oigf fhdhd cgdgd gggd  bdg.pptxslides oif mlsa oigf fhdhd cgdgd gggd  bdg.pptx
slides oif mlsa oigf fhdhd cgdgd gggd bdg.pptx
PRINCEOJHA11
 
Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & Architecture
Massimo Oliviero
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
Manoj Ellappan
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
Yuri Visser
 
Managing Phone Dev Projects
Managing Phone Dev ProjectsManaging Phone Dev Projects
Managing Phone Dev Projects
John McKerrell
 
Getting Started in Custom Programming for Talent Sourcing
Getting Started in Custom Programming for Talent SourcingGetting Started in Custom Programming for Talent Sourcing
Getting Started in Custom Programming for Talent Sourcing
Glenn Gutmacher
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the information
Toushik Paul
 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patterns
Corey Oordt
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Steven Smith
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
Sam Nasr, MCSA, MVP
 
Vipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentationVipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentation
Vipul Divyanshu
 
Developing sites with Magnolia 4 / STK
Developing sites with Magnolia 4 / STKDeveloping sites with Magnolia 4 / STK
Developing sites with Magnolia 4 / STK
guest0afb3
 
slides oif mlsa oigf fhdhd cgdgd gggd bdg.pptx
slides oif mlsa oigf fhdhd cgdgd gggd  bdg.pptxslides oif mlsa oigf fhdhd cgdgd gggd  bdg.pptx
slides oif mlsa oigf fhdhd cgdgd gggd bdg.pptx
PRINCEOJHA11
 
Ad

More from Massimo Oliviero (7)

Modernize your Objective-C
Modernize your Objective-CModernize your Objective-C
Modernize your Objective-C
Massimo Oliviero
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)
Massimo Oliviero
 
Presentazione Community Pragma Mark
Presentazione Community Pragma MarkPresentazione Community Pragma Mark
Presentazione Community Pragma Mark
Massimo Oliviero
 
iOS Programming
iOS ProgrammingiOS Programming
iOS Programming
Massimo Oliviero
 
iOS - Getting Started
iOS - Getting StartediOS - Getting Started
iOS - Getting Started
Massimo Oliviero
 
iOS Ecosystem
iOS EcosystemiOS Ecosystem
iOS Ecosystem
Massimo Oliviero
 
iOS Api Client: soluzioni a confronto
iOS Api Client: soluzioni a confrontoiOS Api Client: soluzioni a confronto
iOS Api Client: soluzioni a confronto
Massimo Oliviero
 

Recently uploaded (20)

Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 

Architecting iOS Project

  • 2. Massimo Oliviero Freelance Software Developer web http://www.massimooliviero.net email [email protected] slide http://www.slideshare.net/MassimoOliviero twitter @maxoly
  • 3. Massimo Oliviero http://pragmamark.org/ La prima community di sviluppatori iOS e Mac OS X in Italia. https://www.facebook.com/groups/pragmamark/
  • 4. Agenda ‣ Project, how to design Xcode project ‣ Application, how to design an iOS app ‣ Resources, links, books and videos
  • 5. Source code Kimera A simple iOS application for educational purpose https://github.com/maxoly/Kimera
  • 7. Project ‣ Conventions, how to naming file and folders ‣ Structure, how make the foundation of the project ‣ Folders, how to organize files and folders
  • 9. Naming Conventions ‣ First establish a naming convention for all the things for file names, class names, project names, images, etc. ‣ Use Pascal Case for files, folders and class start with a capital letter i.e. Controllers, MyClass, BestAppEver, etc. ‣ Use Camel Case for methods, properties & variables start with a lowercase letter i.e setFirstName:, userPassword, etc. ‣ Avoid using of acronyms and abbreviations What the hell does it mean“usrPswdLbl”? Yuck!
  • 10. Coding Conventions ‣ Choose your coding conventions & style there are ton of conventions out there ‣ K&R Style, or Allman Indent Style http://en.wikipedia.org/wiki/Indent_style ‣ Also read Coding Guidelines for Cocoa by Apple http://developer.apple.com/library/mac/#documentation/Cocoa/ Conceptual/CodingGuidelines/CodingGuidelines.html ‣ But most important, choose a convention and respect it the important thing is always be consistent in your project
  • 12. Structure ‣ Create a specific workspace don’t let Xcode do it for you ‣ Setting up projects with correct name and prefix use simple word (only alphanumeric) and at least 3 chars for prefix ‣ Create a Build Automation to scripting common tasks to compiling source code or to deploy artifacts with one command
  • 13. Structure ‣ Create a AdHoc and AppStore Build Configuration So you can handle configuration for different destination ‣ Configure Build Settings to improve quality i.e. you can enable Static Analyzer or Treat Warnings as Errors ‣ Manage third-part libraries with CocoaPods it reduces headaches of storing/managing 3rd party libraries
  • 15. Project Name & Prefix ‣ Choose a simple Program Name Only alphanumeric characters, avoid spaces ‣ Choose a right Class Prefix At least 3 chars, use product name's acronym ‣ Choose your Personal Prefix Use it in your Library Projects ‣ Use Automatic Reference Counting If app targets iOS 5.0 or above
  • 16. Build Automation ‣ It’s the act of automating a wide variety of tasks you can use build tools like Ant, Maven, Make , CMake or Rake ‣ At least you must automate Compiling and Deploying compiling and deploying are the most common tasks for developer ‣ You can also automate Testing and Docs generation they are useful to use in combination with a Continuous Integration
  • 17. AdHoc & AppStore Configuration ‣ Use different Configurations to specialize the behavior i.e. Code Signing Identity, Preprocessor Macros, Linker Flags, etc. ‣ Use AdHoc Configuration to deploy testing app i.e. app for TestFlight with its own Code Signing Identity & Linker Flags ‣ Use AppStore Configuration to deploy on App Store Duplicate Release Configuration to use the same optimizations
  • 18. Build Settings ‣ Enable Run Static Analyzer run the Clang static analysis tool on source files ‣ Enable Treat Warning as Errors it causes all warnings to be treated as errors ‣ Disable Compress PNG Files instead use ImageOptim
  • 19. CocoaPods ‣ Manage third-part libraries with CocoaPods download from http://cocoapods.org/ ‣ CocoaPods manage dependency for you it download source files, imports headers and configures flags ‣ It’s like Ruby Gem but for Objective-C! you can search pods, install & update with one command
  • 21. Folders ‣ Put things in the right place ...and everything makes sense, unfortunately, Xcode doesn’t help us ‣ Map all Xcode group folder to file system directory Xcode group folder don’t represent physical folder ‣ Please remove Supporting Files group folder Who wants“Supporting Files”anymore? yuck!
  • 22. My folders structure ‣ Application specific app related stuff like AppDelegate, main.m, .pch etc ‣ Controllers view (.xib) and view controller stuff put together (obviously) ‣ Library specific application classes like helpers, base classes, services, etc
  • 23. My folder structure ‣ Models application domain models and entities, Core Data model too ‣ Resources assets like images, fonts, sounds, videos, etc. ‣ Vendors third part libraries and frameworks
  • 24. Controllers ‣ Put .xib, .h and .m together in the same folders ‣ One (physical) folder for each view controller ‣ If there are too many, group them into a subfolder ‣ Group them by tab (TabBar) or by functions
  • 25. Resources ‣ One folder for each type of asset images, fonts, sounds, videos, strings, plist, samples ‣ One subfolder for each type of image buttons, backgrounds, logos, shapes, icons, app (splash etc.) ‣ If your app support multiple themes, create a hierarchy themes > themes name > images, fonts, etc. ‣ Name image files based on state “button_blue_normal.png”,“button_blue_highlighted.png”, etc.
  • 27. Application ‣ Design, a quick recap to design principles and patterns ‣ Layers, how to organize your app classes ‣ Compositions, a group of reusable components ‣ Best Practices, a list of useful techniques
  • 29. Design ‣ Typically an application is divided into layers A layer is a black box with a contract that define an input and output ‣ To increase the cohesion and decoupling of the software The layers, if well designed, help to decouple and increase the cohesion ‣ Cohesion indicates strongly related software module it would be a subroutine, class or library with common responsibilities ‣ Coupling measure the level of dependency between two software module, such as classes, functions or library
  • 30. Design Principles ‣ Single Responsibility Principle A module should have a single responsibility, and that responsibility should be entirely encapsulated by the module ‣ Open Closed Principle A module should be open for extension but closed for modifications ‣ Liskov’s Substitution Principle Derived types must be completely substitutable for their base types
  • 31. Design Principles ‣ Interface Segregation Principle Clients should not be forced to depend upon interfaces that they don't use ‣ Dependency Inversion Principle High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions ‣ SOLID: the "first five principles" Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion
  • 32. From Principles to Patterns ‣ Design Pattern is a general reusable solution to a commonly occurring problem within a given context ‣ It’s a description or template for how to solve a problem It’s not a finished design that can be transformed into source code ‣ There are many types of design patterns Architectural, Algorithm strategy, Computational, Implementation strategy, Structural, etc.
  • 33. Most Common Design Patterns ‣ Model View Controller Design Pattern It’s a fundamental design pattern in Objective-C. ‣ Singleton Design Pattern For your information the AppDelegate is a singleton ‣ Chain Of Responsibility Design Pattern Have you ever met the Next Responder or the First Responder?
  • 35. Layers ‣ Layer represents a logical section of the system Layer enforce reusability and testability ‣ A typical client/server app have at least 3 layers Presentation Layer, Business Layer and Data Access Layer
  • 36. Layers Presentation Layer Data Access Layer Business Layer Views Controllers Service Layer Domain Model Layer Persistence Layer Network Layer
  • 38. Presentation Layer ‣ It have 2 components: the UI and the presentation logic in Cocoa the UI is the View and the presentation logic is the Controller ‣ Cocoa adopt Model View Controller Design Pattern the Presentation Layer is already in iOS SDK out-of-the-box ‣ Advanced Appearance Customization with Theme user Appearance Proxy and Theme technique to customize UI.
  • 39. Theme ‣ Create a @protocol that define a“theme” ‣ Implements @protocol in your theme class @protocol MGATheme <NSObject> - (void)themeLabel:(UILabel *)label type:(MGAThemeLabelType)type; - (void)themeButton:(UIButton *)button type:(MGAThemeButtonType)type; @end @interface MGABlueTheme : NSObject<MGATheme> @end @interface MGAMetalTheme : NSObject<MGATheme> @end
  • 40. Presentation Layer Presentation Layer - (View Controller) UIView UIViewController Theme Model Appearance
  • 42. Business Layer ‣ It holds the specific app Business Logic and Behaviors It is concerned with the retrieval, processing, transformation, and management of application data; application of business rules and policies ‣ The Domain Model is a conceptual model of business It describes the various entities, their attributes, roles, and relationships, plus the constraints that govern the problem domain ‣ Business Layer gets data through a Service Layer Service Layer defines an application's boundary with a layer of services that establishes a set of available operations and coordinates the application's response in each operation
  • 43. Domain Model Layer ‣ Domain Model An object model of the domain that incorporates both behavior and data ‣ You can use simple Objective-C objects A plain old Objective-C object that inheriting from NSObject ‣ Or you can use Core Data objects you can extend the class NSMangedObject with your Objective-C class
  • 44. Service Layer ‣ Service Layers is a design pattern The benefits a Service Layer provides is that it defines a common set of application operations available to different clients and coordinates the response in each operation. ‣ Service Layer uses Data Access Layer to access data Service Layer uses DAL to performs the task of retrieving and storing data both from server via network and from database ‣ Service Layer is used by ViewController No more a ton of line of codes in your ViewController, instead few lines of simple Service Layer calls
  • 46. Data Access Layer ‣ It’s a layer which provides simplified access to data The data may be stored in a persistent storage like SQLite or in a backend accessible by network ‣ It may uses a Persistence Layer or Network Layer Both exposes a simplify contract to access data
  • 47. Persistence Layer ‣ The persistence layer deals with persisting The persistence layer is responsible for manipulating the database, and it is used by the service layer ‣ You can use Core Data as Persistence Layer Or, in alternative, you can use FMDB for direct access to SQLite
  • 48. Network Layer ‣ Network Layer is responsible of all networking calls ‣ You can use AFNetworking as Network Layer AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of NSURLConnection, NSOperation, and other familiar Foundation technologies
  • 50. Composition ‣ It’s a way to combine objects into more complex ones Compositions are a critical building block of many basic data structures, including the tagged union, the linked list, and the binary tree, as well as the object used in object-oriented programming ‣ In a real-world app composition takes an important role On iOS / OS X App composition is necessary for a good layering and for a structure UI.
  • 51. Composition - Custom Views ‣ Custom Views are an example of composition A custom view is used to manage small portions of the interface in order to recycle the content and its management ‣ In a real-world iOS/OS App there are many custom views For example, all views that must be inserted in a scroll view, or all those portions of the view that occur multiple times in different view and only with different content.
  • 53. General Best Practice ‣ Use Automatic Reference Counting Always use ARC. All new code should be written using ARC, and all legacy code should be updated to use ARC ‣ Use AppDelegate as Singleton Create all common and singleton objects in App Delegate and then expose them by UIResponder Category
  • 54. Coding Best Practice ‣ Create a property for every ivar and use self to access it Always create a @property for every data member and use“self.name” to access it throughout your class implementation ‣ Alway declare“atomic”or“nonatomic”attribute Always use the“nonatomic”attribute on your properties, unless you are writing a thread-safe class and actually need access to be atomic ‣ User literals and modern Objective-C syntactic sugar The source code will be less verbose and more clear.
  • 55. Presentation Best Practice ‣ Create a base UIViewController Create a MYBaseViewController from which all the view controllers inherit. In this way all the controllers can inherit common behavior. ‣ Create a base UIView Create a MYBaseView from which all the custom views inherit. In this way all the views can inherit common style and appearance ‣ Create a base UITableViewCell Create a MYBaseTableViewCell from which all the custom table view cells inherit. In this way all the cells can inherit common style and appearance
  • 56. Code Design Best Practice ‣ API Design Pay attention to the design of your API. Learn your target platform's conventions before coding. Define the rules that are in accordance with the convention of language ‣ Block and Delegation When should I use blocks instead of delegation for callbacks? Pay attention to this topic and alway look at Apple docs to see how they done
  • 58. Links ‣ Blocks vs Delegation http://thejoeconwayblog.wordpress.com/2012/05/29/blocks-or- delegation/ ‣ API Design http://mattgemmell.com/2012/05/24/api-design/ ‣ Modern Objective-C http://www.slideshare.net/giuseppearici/modern-objectivec-pragma- night
  • 59. Links ‣ objc.io - A periodical about best practices and advanced techniques in Objective-C http://www.objc.io/ ‣ Automatic Reference Counting http://www.slideshare.net/giuseppearici/pragma-night- automaticreferencecounting
  • 60. Videos ‣ Customizing the Appearance of UIKit Controls Session 114 - WWDC 2011 Session Videos ‣ Advanced Appearance Customization on iOS Session 216 - WWDC 2012 Session Videos
  • 61. Books ‣ Cocoa Design Patterns ‣ Erik M. Buck & Donald A. Yacktman ‣ Addison Wesley
  • 62. Books ‣ Patterns Of Enterprise Application Architecture ‣ Martin Fowler ‣ Addison-Wesley Professional ‣ updates: http://martinfowler.com/ books/eaa.html
  • 63. Thank you Massimo Oliviero [email protected] http://www.massimooliviero.net follow me on twitter @maxoly http://www.slideshare.net/MassimoOliviero https://speakerdeck.com/massimooliviero