SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
UIKonf App Architecture
&
Data Oriented Design
+------------+ +----------------+
| | | |
| Objects | | Data |
+------------+ +----------------+
| Talk | | Title |
| Speaker | | Description |
| Organizer | | StartTime |
| Volunteer | | EndTime |
| Venue | | Name |
| Break | | TwitterHandle |
| Workshop | | PhotoURL |
| ... | | ... |
| | | |
+------------+ +----------------+
Time slot
[
{
"t_id": "startDay1",
"startTime": "18-09-00",
"endTime": "18-10-00",
"description": "Check in first day",
"locations": [
"Heimathafen Neukölln"
]
},
...
Organizer
...
{
"name": "Maxim Zaks",
"twitter": "@iceX33",
"bio": "Software developer with a history in IDE development,
Web development and even Enterprise Java development
(He was young and under bad influence).
Nowadays working as a game developer (preferably iOS).
Regular visitor and occasional speaker at conferences.",
"photo": "http://www.uikonf.com/static/images/maxim-zaks.png",
"organizer": true
},
...
Speaker
...
{
"name": "Graham Lee",
"twitter": "@iwasleeg",
"bio": "Graham Lee works at Facebook, where he helps people make better tests
so they can help people make better software.
In the past he worked with some other people,
and has written books and blogs so he can work
with people he hasn't met too. His blog is at sicpers.info.",
"photo": "http://www.uikonf.com/static/images/Graham-Lee.png"
},
...
Talk
...
{
"title": "World Modeling",
"speaker_name": "Mike Lee",
"t_id": "session1Day1",
"t_index": 1
},
...
Location
...
{
"name": "Heimathafen Neukölln",
"address": "Karl-Marx-Str. 141, 12043 Berlin",
"description": "Conference venue"
},
...
Import Data from JSON Array
for item in jsonArray {
let entity = context.createEntity()
for pair in (item as! NSDictionary) {
let (key,value) = (pair.key as! String,
pair.value as! JsonValue)
let component = converters[key]!(value)
entity.set(component)
}
}
What is a context?
It's a managing data structure
public class Context {
public func createEntity() -> Entity
public func destroyEntity(entity : Entity)
public func entityGroup(matcher : Matcher) -> Group
}
What's an entity?
Bag of components
Entity
public class Entity {
public func set(c:Component, overwrite:Bool = false)
public func get<C:Component>(ct:C.Type) -> C?
public func has<C:Component>(ct:C.Type) -> Bool
public func remove<C:Component>(ct:C.Type)
}
What's a component
It's just data (value object)
Components
struct NameComponent : Component, DebugPrintable {
let name : String
var debugDescription: String{
return "[(name)]"
}
}
What's a component
It also can be just a flag
struct OrganizerComponent : Component {}
Import Data from JSON Array
for item in jsonArray {
let entity = context.createEntity()
for pair in (item as! NSDictionary) {
let (key,value) = (pair.key as! String,
pair.value as! JsonValue)
let component = converters[key]!(value)
entity.set(component)
}
}
Converters dictionary
typealias Converter = (JsonValue) -> Component
let converters : [String : Converter] = [
"t_id" : {
TimeSlotIdComponent(id: $0 as! String)
},
"t_index" : {
TimeSlotIndexComponent(index: $0 as! Int)
},
...
How does it work with
UIKit
override func viewDidLoad() {
super.viewDidLoad()
groupOfEvents = context.entityGroup(
Matcher.Any(StartTimeComponent, EndTimeComponent))
setNavigationTitleFont()
groupOfEvents.addObserver(self)
context.entityGroup(
Matcher.All(RatingComponent)).addObserver(self)
readDataIntoContext(context)
syncData(context)
}
What's a group?
Subset of Entites
Entity
public class Group : SequenceType {
public var count : Int
public var sortedEntities: [Entity]
public func addObserver(observer : GroupObserver)
public func removeObserver(observer : GroupObserver)
}
override func viewDidLoad() {
super.viewDidLoad()
groupOfEvents = context.entityGroup(
Matcher.Any(StartTimeComponent, EndTimeComponent))
setNavigationTitleFont()
groupOfEvents.addObserver(self)
context.entityGroup(
Matcher.All(RatingComponent)).addObserver(self)
readDataIntoContext(context)
syncData(context)
}
extension TimeLineViewController : GroupObserver {
func entityAdded(entity : Entity) {
if entity.has(RatingComponent){
updateSendButton()
} else {
reload()
}
}
func entityRemoved(entity : Entity,
withRemovedComponent removedComponent : Component) {
if removedComponent is RatingComponent {
return
}
reload()
}
}
private lazy var reload :
dispatch_block_t = dispatch_debounce_block(0.1) {
...
}
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let sectionName = sectionNameTable[indexPath.section]()!
let cellIdentifier = cellIdTable[sectionName]!
let cell = tableView.dequeueReusableCellWithIdentifier(
cellIdentifier, forIndexPath: indexPath) as! EntityCell
let cellEntity = cellEntityTable[sectionName]!(indexPath.row)
cell.updateWithEntity(cellEntity, context: context)
return cell as! UITableViewCell
}
protocol EntityCell {
func updateWithEntity(entity : Entity, context : Context)
}
class LocationCell: UITableViewCell, EntityCell {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var descriptionLabel: UITextView!
func updateWithEntity(entity : Entity, context : Context){
nameLabel.text = entity.get(NameComponent)!.name
let descriptionText = entity.get(DescriptionComponent)?.description
let address = entity.get(AddressComponent)!.address
descriptionLabel.text = descriptionText != nil ?
descriptionText! + "n" + address : address
}
}
struct PhotoComponent : Component, DebugPrintable {
let url : NSURL
let image : UIImage
let loaded : Bool
var debugDescription: String{
return "[(url), loaded: (loaded)]"
}
}
Data:
{
...
"photo": "http://www.uikonf.com/static/images/maxim-zaks.png",
...
}
Converter:
"photo" : {
PhotoComponent(url: NSURL(string:$0 as! String)!,
image : UIImage(named:"person-icon")!, loaded: false)
},
func setPhoto() {
let photoComponent = entity!.get(PhotoComponent)!
imageView.image = photoComponent.image
if !photoComponent.loaded {
...
}
}
var detachedPerson = entity!.detach
cancelLoadingPhoto =
dispatch_after_cancellable(
0.5, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0))
{
if let data = NSData(contentsOfURL: photoComponent.url),
let image = UIImage(data: data)
{
let photoComponent = detachedPerson.get(PhotoComponent)!
detachedPerson.set(
PhotoComponent(url: photoComponent.url,
image:image, loaded:true),
overwrite: true
)
detachedPerson.sync()
}
}
What's a detached Entity?
It's an Entity implemented as a struct
with a sync method
var detachedPerson = entity!.detach
cancelLoadingPhoto =
dispatch_after_cancellable(
0.5, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0))
{
if let data = NSData(contentsOfURL: photoComponent.url),
let image = UIImage(data: data)
{
let photoComponent = detachedPerson.get(PhotoComponent)!
detachedPerson.set(
PhotoComponent(url: photoComponent.url,
image:image, loaded:true),
overwrite: true
)
detachedPerson.sync()
}
}
Recap
—Context is a managing Data Structure
—Entity is a bag of components
—Components are just value types
—Groups are subsets on the components
—You can observe groups -> KVO like behavior
—Use detached entity if you want to go on another
queue
Tanks you
Maxim - @iceX33
Links
—UIKonf App on Github
—Blog: Think different about Data Model
—Blog: What is an entity framework
—Book: Data oriented Design (C++ heavy)
—Talk: Data-Oriented Design and C++ (hardcore)

Weitere ähnliche Inhalte

Was ist angesagt?

Data visualization by Kenneth Odoh
Data visualization by Kenneth OdohData visualization by Kenneth Odoh
Data visualization by Kenneth Odohpyconfi
 
Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介dena_genom
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveEugene Zharkov
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2Mouna Guru
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheetDr. Volkan OBAN
 
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin WayTDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Waytdc-globalcode
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with goEleanor McHugh
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montageKris Kowal
 
The Ring programming language version 1.5.4 book - Part 42 of 185
The Ring programming language version 1.5.4 book - Part 42 of 185The Ring programming language version 1.5.4 book - Part 42 of 185
The Ring programming language version 1.5.4 book - Part 42 of 185Mahmoud Samir Fayed
 
Martin Fowler's Refactoring Techniques Quick Reference
Martin Fowler's Refactoring Techniques Quick ReferenceMartin Fowler's Refactoring Techniques Quick Reference
Martin Fowler's Refactoring Techniques Quick ReferenceSeung-Bum Lee
 
Compositional I/O Stream in Scala
Compositional I/O Stream in ScalaCompositional I/O Stream in Scala
Compositional I/O Stream in ScalaC4Media
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickHermann Hueck
 

Was ist angesagt? (20)

Data visualization by Kenneth Odoh
Data visualization by Kenneth OdohData visualization by Kenneth Odoh
Data visualization by Kenneth Odoh
 
Java programs
Java programsJava programs
Java programs
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheet
 
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin WayTDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
2 a networkflow
2 a networkflow2 a networkflow
2 a networkflow
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with go
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
The Ring programming language version 1.5.4 book - Part 42 of 185
The Ring programming language version 1.5.4 book - Part 42 of 185The Ring programming language version 1.5.4 book - Part 42 of 185
The Ring programming language version 1.5.4 book - Part 42 of 185
 
mobl
moblmobl
mobl
 
Martin Fowler's Refactoring Techniques Quick Reference
Martin Fowler's Refactoring Techniques Quick ReferenceMartin Fowler's Refactoring Techniques Quick Reference
Martin Fowler's Refactoring Techniques Quick Reference
 
Compositional I/O Stream in Scala
Compositional I/O Stream in ScalaCompositional I/O Stream in Scala
Compositional I/O Stream in Scala
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with Slick
 

Ähnlich wie UIKonf App & Data Driven Design @swift.berlin

Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using RoomNelson Glauber Leal
 
Improving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfImproving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfIain Hull
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicBadoo Development
 
Александр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия SwiftАлександр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия SwiftCocoaHeads
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfShaiAlmog1
 
Improving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinImproving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinIain Hull
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptSaadAsim11
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for KotlinTechMagic
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Codemotion
 
Design for succcess with react and storybook.js
Design for succcess with react and storybook.jsDesign for succcess with react and storybook.js
Design for succcess with react and storybook.jsChris Saylor
 
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the AirAvitoTech
 
Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"Fwdays
 

Ähnlich wie UIKonf App & Data Driven Design @swift.berlin (20)

Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
resume_Alexey_Zaytsev
resume_Alexey_Zaytsevresume_Alexey_Zaytsev
resume_Alexey_Zaytsev
 
Improving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfImproving Correctness with Types Kats Conf
Improving Correctness with Types Kats Conf
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magic
 
Александр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия SwiftАлександр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия Swift
 
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
 
mobl
moblmobl
mobl
 
IT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notesIT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notes
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
 
Improving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinImproving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con Berlin
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .ppt
 
Arrays
ArraysArrays
Arrays
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
 
Design for succcess with react and storybook.js
Design for succcess with react and storybook.jsDesign for succcess with react and storybook.js
Design for succcess with react and storybook.js
 
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
 
Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"
 

Mehr von Maxim Zaks

Entity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentEntity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentMaxim Zaks
 
Nitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationNitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationMaxim Zaks
 
Wind of change
Wind of changeWind of change
Wind of changeMaxim Zaks
 
Data model mal anders
Data model mal andersData model mal anders
Data model mal andersMaxim Zaks
 
Talk Binary to Me
Talk Binary to MeTalk Binary to Me
Talk Binary to MeMaxim Zaks
 
Entity Component System - for App developers
Entity Component System - for App developersEntity Component System - for App developers
Entity Component System - for App developersMaxim Zaks
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersBeyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersMaxim Zaks
 
Beyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawBeyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawMaxim Zaks
 
Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Maxim Zaks
 
Beyond JSON with FlatBuffers
Beyond JSON with FlatBuffersBeyond JSON with FlatBuffers
Beyond JSON with FlatBuffersMaxim Zaks
 
Basics of Computer Science
Basics of Computer ScienceBasics of Computer Science
Basics of Computer ScienceMaxim Zaks
 
Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Maxim Zaks
 
Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit partsMaxim Zaks
 
Currying in Swift
Currying in SwiftCurrying in Swift
Currying in SwiftMaxim Zaks
 
Promise of an API
Promise of an APIPromise of an API
Promise of an APIMaxim Zaks
 
96% macoun 2013
96% macoun 201396% macoun 2013
96% macoun 2013Maxim Zaks
 
Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Maxim Zaks
 
Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Maxim Zaks
 
Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Maxim Zaks
 
Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Maxim Zaks
 

Mehr von Maxim Zaks (20)

Entity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentEntity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app development
 
Nitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationNitty Gritty of Data Serialisation
Nitty Gritty of Data Serialisation
 
Wind of change
Wind of changeWind of change
Wind of change
 
Data model mal anders
Data model mal andersData model mal anders
Data model mal anders
 
Talk Binary to Me
Talk Binary to MeTalk Binary to Me
Talk Binary to Me
 
Entity Component System - for App developers
Entity Component System - for App developersEntity Component System - for App developers
Entity Component System - for App developers
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersBeyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffers
 
Beyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawBeyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.Warsaw
 
Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016
 
Beyond JSON with FlatBuffers
Beyond JSON with FlatBuffersBeyond JSON with FlatBuffers
Beyond JSON with FlatBuffers
 
Basics of Computer Science
Basics of Computer ScienceBasics of Computer Science
Basics of Computer Science
 
Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015
 
Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit parts
 
Currying in Swift
Currying in SwiftCurrying in Swift
Currying in Swift
 
Promise of an API
Promise of an APIPromise of an API
Promise of an API
 
96% macoun 2013
96% macoun 201396% macoun 2013
96% macoun 2013
 
Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013
 
Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013
 
Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013
 
Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013
 

Kürzlich hochgeladen

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 

Kürzlich hochgeladen (20)

University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 

UIKonf App & Data Driven Design @swift.berlin

  • 2.
  • 3. +------------+ +----------------+ | | | | | Objects | | Data | +------------+ +----------------+ | Talk | | Title | | Speaker | | Description | | Organizer | | StartTime | | Volunteer | | EndTime | | Venue | | Name | | Break | | TwitterHandle | | Workshop | | PhotoURL | | ... | | ... | | | | | +------------+ +----------------+
  • 4.
  • 5. Time slot [ { "t_id": "startDay1", "startTime": "18-09-00", "endTime": "18-10-00", "description": "Check in first day", "locations": [ "Heimathafen Neukölln" ] }, ...
  • 6. Organizer ... { "name": "Maxim Zaks", "twitter": "@iceX33", "bio": "Software developer with a history in IDE development, Web development and even Enterprise Java development (He was young and under bad influence). Nowadays working as a game developer (preferably iOS). Regular visitor and occasional speaker at conferences.", "photo": "http://www.uikonf.com/static/images/maxim-zaks.png", "organizer": true }, ...
  • 7. Speaker ... { "name": "Graham Lee", "twitter": "@iwasleeg", "bio": "Graham Lee works at Facebook, where he helps people make better tests so they can help people make better software. In the past he worked with some other people, and has written books and blogs so he can work with people he hasn't met too. His blog is at sicpers.info.", "photo": "http://www.uikonf.com/static/images/Graham-Lee.png" }, ...
  • 8. Talk ... { "title": "World Modeling", "speaker_name": "Mike Lee", "t_id": "session1Day1", "t_index": 1 }, ...
  • 9. Location ... { "name": "Heimathafen Neukölln", "address": "Karl-Marx-Str. 141, 12043 Berlin", "description": "Conference venue" }, ...
  • 10. Import Data from JSON Array for item in jsonArray { let entity = context.createEntity() for pair in (item as! NSDictionary) { let (key,value) = (pair.key as! String, pair.value as! JsonValue) let component = converters[key]!(value) entity.set(component) } }
  • 11. What is a context? It's a managing data structure
  • 12. public class Context { public func createEntity() -> Entity public func destroyEntity(entity : Entity) public func entityGroup(matcher : Matcher) -> Group }
  • 13. What's an entity? Bag of components
  • 14. Entity public class Entity { public func set(c:Component, overwrite:Bool = false) public func get<C:Component>(ct:C.Type) -> C? public func has<C:Component>(ct:C.Type) -> Bool public func remove<C:Component>(ct:C.Type) }
  • 15. What's a component It's just data (value object)
  • 16. Components struct NameComponent : Component, DebugPrintable { let name : String var debugDescription: String{ return "[(name)]" } }
  • 17. What's a component It also can be just a flag
  • 19.
  • 20. Import Data from JSON Array for item in jsonArray { let entity = context.createEntity() for pair in (item as! NSDictionary) { let (key,value) = (pair.key as! String, pair.value as! JsonValue) let component = converters[key]!(value) entity.set(component) } }
  • 21. Converters dictionary typealias Converter = (JsonValue) -> Component let converters : [String : Converter] = [ "t_id" : { TimeSlotIdComponent(id: $0 as! String) }, "t_index" : { TimeSlotIndexComponent(index: $0 as! Int) }, ...
  • 22. How does it work with UIKit
  • 23.
  • 24. override func viewDidLoad() { super.viewDidLoad() groupOfEvents = context.entityGroup( Matcher.Any(StartTimeComponent, EndTimeComponent)) setNavigationTitleFont() groupOfEvents.addObserver(self) context.entityGroup( Matcher.All(RatingComponent)).addObserver(self) readDataIntoContext(context) syncData(context) }
  • 26. Entity public class Group : SequenceType { public var count : Int public var sortedEntities: [Entity] public func addObserver(observer : GroupObserver) public func removeObserver(observer : GroupObserver) }
  • 27.
  • 28. override func viewDidLoad() { super.viewDidLoad() groupOfEvents = context.entityGroup( Matcher.Any(StartTimeComponent, EndTimeComponent)) setNavigationTitleFont() groupOfEvents.addObserver(self) context.entityGroup( Matcher.All(RatingComponent)).addObserver(self) readDataIntoContext(context) syncData(context) }
  • 29.
  • 30. extension TimeLineViewController : GroupObserver { func entityAdded(entity : Entity) { if entity.has(RatingComponent){ updateSendButton() } else { reload() } } func entityRemoved(entity : Entity, withRemovedComponent removedComponent : Component) { if removedComponent is RatingComponent { return } reload() } }
  • 31. private lazy var reload : dispatch_block_t = dispatch_debounce_block(0.1) { ... }
  • 32.
  • 33.
  • 34. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let sectionName = sectionNameTable[indexPath.section]()! let cellIdentifier = cellIdTable[sectionName]! let cell = tableView.dequeueReusableCellWithIdentifier( cellIdentifier, forIndexPath: indexPath) as! EntityCell let cellEntity = cellEntityTable[sectionName]!(indexPath.row) cell.updateWithEntity(cellEntity, context: context) return cell as! UITableViewCell }
  • 35. protocol EntityCell { func updateWithEntity(entity : Entity, context : Context) } class LocationCell: UITableViewCell, EntityCell { @IBOutlet weak var nameLabel: UILabel! @IBOutlet weak var descriptionLabel: UITextView! func updateWithEntity(entity : Entity, context : Context){ nameLabel.text = entity.get(NameComponent)!.name let descriptionText = entity.get(DescriptionComponent)?.description let address = entity.get(AddressComponent)!.address descriptionLabel.text = descriptionText != nil ? descriptionText! + "n" + address : address } }
  • 36.
  • 37. struct PhotoComponent : Component, DebugPrintable { let url : NSURL let image : UIImage let loaded : Bool var debugDescription: String{ return "[(url), loaded: (loaded)]" } }
  • 38. Data: { ... "photo": "http://www.uikonf.com/static/images/maxim-zaks.png", ... } Converter: "photo" : { PhotoComponent(url: NSURL(string:$0 as! String)!, image : UIImage(named:"person-icon")!, loaded: false) },
  • 39. func setPhoto() { let photoComponent = entity!.get(PhotoComponent)! imageView.image = photoComponent.image if !photoComponent.loaded { ... } }
  • 40. var detachedPerson = entity!.detach cancelLoadingPhoto = dispatch_after_cancellable( 0.5, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)) { if let data = NSData(contentsOfURL: photoComponent.url), let image = UIImage(data: data) { let photoComponent = detachedPerson.get(PhotoComponent)! detachedPerson.set( PhotoComponent(url: photoComponent.url, image:image, loaded:true), overwrite: true ) detachedPerson.sync() } }
  • 41. What's a detached Entity? It's an Entity implemented as a struct with a sync method
  • 42. var detachedPerson = entity!.detach cancelLoadingPhoto = dispatch_after_cancellable( 0.5, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)) { if let data = NSData(contentsOfURL: photoComponent.url), let image = UIImage(data: data) { let photoComponent = detachedPerson.get(PhotoComponent)! detachedPerson.set( PhotoComponent(url: photoComponent.url, image:image, loaded:true), overwrite: true ) detachedPerson.sync() } }
  • 43. Recap —Context is a managing Data Structure —Entity is a bag of components —Components are just value types —Groups are subsets on the components —You can observe groups -> KVO like behavior —Use detached entity if you want to go on another queue
  • 44. Tanks you Maxim - @iceX33
  • 45. Links —UIKonf App on Github —Blog: Think different about Data Model —Blog: What is an entity framework —Book: Data oriented Design (C++ heavy) —Talk: Data-Oriented Design and C++ (hardcore)