SlideShare a Scribd company logo
Advanced Realm in Swift
trippiece Inc.
@kitasuke
Table of contents
• Introducing Realm Swift
• How to deal with JSON
Before starting a presentation,
I would like to introduce my new
library
Flexible menu width mode
PagingEnabled mode
Fixed menu width mode
ScrollingEnabled mode
centerItem option
SegmentedControl mode
Usage
let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
viewController.title = "Menu title"
let viewControllers = [viewController]
let options = PagingMenuOptions()
let pagingMenuController = self.childViewControllers.first as! PagingMenuController // there is a containerView having a childViewController in storyboard
pagingMenuController.setup(viewControllers: viewControllers, options: options)
Customization
public class PagingMenuOptions {
public var defaultPage = 0
public var backgroundColor = UIColor.whiteColor()
public var selectedBackgroundColor = UIColor.whiteColor()
public var textColor = UIColor.lightGrayColor()
public var selectedTextColor = UIColor.blackColor()
public var font = UIFont.systemFontOfSize(16)
public var menuHeight: CGFloat = 50
public var menuItemMargin: CGFloat = 20
public var animationDuration: NSTimeInterval = 0.3
public var menuDisplayMode = MenuDisplayMode.FlexibleItemWidth(centerItem: true, scrollingMode: MenuScrollingMode.PagingEnabled)
public var menuItemMode = MenuItemMode.Underline(height: 3.0, color: UIColor.whiteColor(), selectedColor: UIColor.blueColor())
public enum MenuScrollingMode {
case ScrollEnabled
case ScrollEnabledAndBouces
case PagingEnabled
}
public enum MenuDisplayMode {
case FlexibleItemWidth(centerItem: Bool, scrollingMode: MenuScrollingMode)
case FixedItemWidth(width: CGFloat, centerItem: Bool, scrollingMode: MenuScrollingMode)
case SegmentedControl
}
public enum MenuItemMode {
case None
case Underline(height: CGFloat, color: UIColor, selectedColor: UIColor)
case RoundRect
}
}
Welcome your feedback!
https://github.com/kitasuke/PagingMenuController
Back to Realm
Realm Swift released
A full-fledged, Swift-native API
Introducing Realm Swift
Available through Dynamic
Framework, CocoaPods and
Carthage
Documentation for Realm Swift
What's the difference between
Swift bridge from Objective-C
and
purely Swift?
Swift bridge
class Employee: RLMObject {
dynamic var name = "" // you can specify defaults
dynamic var startDate = NSDate()
dynamic var salary = 0.0
dynamic var fullTime = true
}
class Company: RLMObject {
dynamic var name = ""
dynamic var ceo: Employee? // optional to-one relationship
let employees = RLMArray(objectClassName: Employee.className()) // to-many relationship
}
purely Swift
class Employee: Object {
dynamic var name = "" // you can specify defaults
dynamic var startDate = NSDate()
dynamic var salary = 0.0
dynamic var fullTime = true
}
class Company: Object {
dynamic var name = ""
dynamic var ceo: Employee? // optional to-one relationship
let employees = List<Employee>() // generic to-many relationship
}
Swift bridge
let company = Company() // Using Realm Objects
company.name = "Realm Inc."
let realm = RLMRealm.defaultRealm() // Default Realm
realm.transactionWithBlock({ () -> Void in // Transactions
realm.addObject(company)
})
// Queries
let company = Company.allObjects().firstObject() as! Company
company.name // => "Realm Inc." (property access is type-safe)
let ftJacks = Employee.objectsWhere("name = 'Jack'").objectsWhere("fullTime = true") // RLMResults
purely Swift
let company = Company() // Using Realm Objects
company.name = "Realm Inc."
let realm = Realm() // Default Realm
realm.write { // Transactions
realm.add(company)
}
// Queries
let companies = realm.objects(Company) // => Results<Company>
companies[0].name // => "Realm Inc." (property access is type-safe)
// "Jack"s who work full time (lazily loaded & chainable)
let ftJacks = realm.objects(Employee).filter("name = 'Jack'")
.filter("fullTime = true")
Cannot use full Swift features like
enum yet, but it's definitely
better than before
Dealing with JSON in Swift
Not sure exactly what kind of
values server respond
Might be Array, String, Int or nil
However, Realm doesn't accept nil
Make it Optional and Set default values
class Employee: Object {
dynamic var name: String? = ""
dynamic var startDate: NSDate? = NSDate()
dynamic var salary: double? = 0.0
dynamic var fullTime: Bool? = true
}
Use rawValue for enum
class Employee: Object {
dynamic var type: Int = Type.iOS.rawValue
enum Type: Int {
case iOS = 1
case Android = 2
}
}
ignoredProperty could be useful
class Employee: Object {
var number: Int = 0
var name: String { // computed properties are automatically ignored
return "String"
}
override static func ignoredProperties() -> [String] {
return ["number"]
}
}
That's for object mapping so far
Next one is the biggest problem
nil cannot be saved in Realm
If you save nil in Realm,
an exception will be thrown
Ideally, values should be saved,
but nil should be skipped
Use following methods with external data
• createInDefaultRealmWithValue:
• createInRealm: withValue:
• createOrUpdateInDefaultRealmWithValue:
• createOrUpdateInRealm: withValue:
• create(type: T.Type, value: AnyObject = [:],
update: Bool = false) in Realm Swift
if not exists in Realm yet,
default value is used for key,
otherwise it's skipped
Use following methods with realm object
• addObject:
• addObjects:
• addOrUpdateObject:
• addOrUpdateObjectsFromArray:
• add(object: Object, update: Bool = false) in Realm
Swift
• add(objects: S, update: Bool = false) in Realm Swift
Realm might support nil soon,
so keep it mind that
this is just a workaround
Any questions?

More Related Content

What's hot

Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
Florent Pillet
 
Qtp training session IV
Qtp training session IVQtp training session IV
Qtp training session IVAisha Mazhar
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )
Victor Verhaagen
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & Collections
CocoaHeads France
 
Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger
 
Realm Mobile Database - An Introduction
Realm Mobile Database - An IntroductionRealm Mobile Database - An Introduction
Realm Mobile Database - An Introduction
Knoldus Inc.
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
Mindfire Solutions
 
Realm - Phoenix Mobile Festival
Realm - Phoenix Mobile FestivalRealm - Phoenix Mobile Festival
Realm - Phoenix Mobile Festival
DJ Rausch
 
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
Masaki Oshikawa
 
Javascript session 01 - Introduction to Javascript
Javascript session 01 - Introduction to JavascriptJavascript session 01 - Introduction to Javascript
Javascript session 01 - Introduction to Javascript
Livingston Samuel
 
Talk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetTalk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe Converset
CocoaHeads France
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
AWS Java SDK @ scale
AWS Java SDK @ scaleAWS Java SDK @ scale
AWS Java SDK @ scale
Tomasz Kowalczewski
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
Troy Miles
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
Ruslan Shevchenko
 
Forgive me for i have allocated
Forgive me for i have allocatedForgive me for i have allocated
Forgive me for i have allocated
Tomasz Kowalczewski
 
JS
JSJS

What's hot (20)

Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
Qtp training session IV
Qtp training session IVQtp training session IV
Qtp training session IV
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & Collections
 
Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011
 
Realm Mobile Database - An Introduction
Realm Mobile Database - An IntroductionRealm Mobile Database - An Introduction
Realm Mobile Database - An Introduction
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
Realm - Phoenix Mobile Festival
Realm - Phoenix Mobile FestivalRealm - Phoenix Mobile Festival
Realm - Phoenix Mobile Festival
 
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
 
Javascript session 01 - Introduction to Javascript
Javascript session 01 - Introduction to JavascriptJavascript session 01 - Introduction to Javascript
Javascript session 01 - Introduction to Javascript
 
Talk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetTalk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe Converset
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
AWS Java SDK @ scale
AWS Java SDK @ scaleAWS Java SDK @ scale
AWS Java SDK @ scale
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
 
Forgive me for i have allocated
Forgive me for i have allocatedForgive me for i have allocated
Forgive me for i have allocated
 
JS
JSJS
JS
 

Similar to Advanced realm in swift

Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
Tarek Yehia
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
Bhavya Siddappa
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)Piyush Katariya
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 
From android/ java to swift (2)
From android/ java to swift (2)From android/ java to swift (2)
From android/ java to swift (2)
allanh0526
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
Andrew Dupont
 
How to React Native
How to React NativeHow to React Native
How to React Native
Dmitry Ulyanov
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Michael Stal
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
Rodica Dada
 
Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testing
smontanari
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Jon Kruger
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design PatternsZohar Arad
 
ES6 Primer
ES6 PrimerES6 Primer
ES6 Primer
roblund
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android development
Adit Lal
 
#pugMi - DDD - Value objects
#pugMi - DDD - Value objects#pugMi - DDD - Value objects
#pugMi - DDD - Value objects
Simone Gentili
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgets
scottw
 

Similar to Advanced realm in swift (20)

Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
 
From android/ java to swift (2)
From android/ java to swift (2)From android/ java to swift (2)
From android/ java to swift (2)
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testing
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
ES6 Primer
ES6 PrimerES6 Primer
ES6 Primer
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android development
 
#pugMi - DDD - Value objects
#pugMi - DDD - Value objects#pugMi - DDD - Value objects
#pugMi - DDD - Value objects
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgets
 

More from Yusuke Kita

Integrating libSyntax into the compiler pipeline
Integrating libSyntax into the compiler pipelineIntegrating libSyntax into the compiler pipeline
Integrating libSyntax into the compiler pipeline
Yusuke Kita
 
Making your own tool using SwiftSyntax
Making your own tool using SwiftSyntaxMaking your own tool using SwiftSyntax
Making your own tool using SwiftSyntax
Yusuke Kita
 
[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline
Yusuke Kita
 
Creating your own Bitrise step
Creating your own Bitrise stepCreating your own Bitrise step
Creating your own Bitrise step
Yusuke Kita
 
Introducing swift-format
Introducing swift-formatIntroducing swift-format
Introducing swift-format
Yusuke Kita
 
Unidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUIUnidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUI
Yusuke Kita
 
Open Source Swift Workshop
Open Source Swift WorkshopOpen Source Swift Workshop
Open Source Swift Workshop
Yusuke Kita
 
Contributing to Swift Compiler
Contributing to Swift CompilerContributing to Swift Compiler
Contributing to Swift Compiler
Yusuke Kita
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
Yusuke Kita
 
Writing an interpreter in swift
Writing an interpreter in swiftWriting an interpreter in swift
Writing an interpreter in swift
Yusuke Kita
 
SIL Optimizations - AllocBoxToStack
SIL Optimizations - AllocBoxToStackSIL Optimizations - AllocBoxToStack
SIL Optimizations - AllocBoxToStack
Yusuke Kita
 
SIL for First Time Learners
SIL for First Time LearnersSIL for First Time Learners
SIL for First Time Learners
Yusuke Kita
 
var, let in SIL
var, let in SILvar, let in SIL
var, let in SIL
Yusuke Kita
 
SIL for First Time Leaners LT
SIL for First Time Leaners LTSIL for First Time Leaners LT
SIL for First Time Leaners LT
Yusuke Kita
 
How to try! Swift
How to try! SwiftHow to try! Swift
How to try! Swift
Yusuke Kita
 
SIL for the first time
SIL for the first timeSIL for the first time
SIL for the first time
Yusuke Kita
 
Introducing protobuf in Swift
Introducing protobuf in SwiftIntroducing protobuf in Swift
Introducing protobuf in Swift
Yusuke Kita
 
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConfType-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
Yusuke Kita
 
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSConType-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
Yusuke Kita
 
Swift core
Swift coreSwift core
Swift core
Yusuke Kita
 

More from Yusuke Kita (20)

Integrating libSyntax into the compiler pipeline
Integrating libSyntax into the compiler pipelineIntegrating libSyntax into the compiler pipeline
Integrating libSyntax into the compiler pipeline
 
Making your own tool using SwiftSyntax
Making your own tool using SwiftSyntaxMaking your own tool using SwiftSyntax
Making your own tool using SwiftSyntax
 
[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline
 
Creating your own Bitrise step
Creating your own Bitrise stepCreating your own Bitrise step
Creating your own Bitrise step
 
Introducing swift-format
Introducing swift-formatIntroducing swift-format
Introducing swift-format
 
Unidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUIUnidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUI
 
Open Source Swift Workshop
Open Source Swift WorkshopOpen Source Swift Workshop
Open Source Swift Workshop
 
Contributing to Swift Compiler
Contributing to Swift CompilerContributing to Swift Compiler
Contributing to Swift Compiler
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
Writing an interpreter in swift
Writing an interpreter in swiftWriting an interpreter in swift
Writing an interpreter in swift
 
SIL Optimizations - AllocBoxToStack
SIL Optimizations - AllocBoxToStackSIL Optimizations - AllocBoxToStack
SIL Optimizations - AllocBoxToStack
 
SIL for First Time Learners
SIL for First Time LearnersSIL for First Time Learners
SIL for First Time Learners
 
var, let in SIL
var, let in SILvar, let in SIL
var, let in SIL
 
SIL for First Time Leaners LT
SIL for First Time Leaners LTSIL for First Time Leaners LT
SIL for First Time Leaners LT
 
How to try! Swift
How to try! SwiftHow to try! Swift
How to try! Swift
 
SIL for the first time
SIL for the first timeSIL for the first time
SIL for the first time
 
Introducing protobuf in Swift
Introducing protobuf in SwiftIntroducing protobuf in Swift
Introducing protobuf in Swift
 
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConfType-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
 
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSConType-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
 
Swift core
Swift coreSwift core
Swift core
 

Recently uploaded

Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
nikitacareer3
 

Recently uploaded (20)

Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
 

Advanced realm in swift

  • 1. Advanced Realm in Swift trippiece Inc. @kitasuke
  • 2. Table of contents • Introducing Realm Swift • How to deal with JSON
  • 3. Before starting a presentation, I would like to introduce my new library
  • 4.
  • 5. Flexible menu width mode PagingEnabled mode
  • 6. Fixed menu width mode ScrollingEnabled mode centerItem option
  • 8. Usage let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController viewController.title = "Menu title" let viewControllers = [viewController] let options = PagingMenuOptions() let pagingMenuController = self.childViewControllers.first as! PagingMenuController // there is a containerView having a childViewController in storyboard pagingMenuController.setup(viewControllers: viewControllers, options: options)
  • 9. Customization public class PagingMenuOptions { public var defaultPage = 0 public var backgroundColor = UIColor.whiteColor() public var selectedBackgroundColor = UIColor.whiteColor() public var textColor = UIColor.lightGrayColor() public var selectedTextColor = UIColor.blackColor() public var font = UIFont.systemFontOfSize(16) public var menuHeight: CGFloat = 50 public var menuItemMargin: CGFloat = 20 public var animationDuration: NSTimeInterval = 0.3 public var menuDisplayMode = MenuDisplayMode.FlexibleItemWidth(centerItem: true, scrollingMode: MenuScrollingMode.PagingEnabled) public var menuItemMode = MenuItemMode.Underline(height: 3.0, color: UIColor.whiteColor(), selectedColor: UIColor.blueColor()) public enum MenuScrollingMode { case ScrollEnabled case ScrollEnabledAndBouces case PagingEnabled } public enum MenuDisplayMode { case FlexibleItemWidth(centerItem: Bool, scrollingMode: MenuScrollingMode) case FixedItemWidth(width: CGFloat, centerItem: Bool, scrollingMode: MenuScrollingMode) case SegmentedControl } public enum MenuItemMode { case None case Underline(height: CGFloat, color: UIColor, selectedColor: UIColor) case RoundRect } }
  • 12. Realm Swift released A full-fledged, Swift-native API Introducing Realm Swift
  • 13. Available through Dynamic Framework, CocoaPods and Carthage Documentation for Realm Swift
  • 14. What's the difference between Swift bridge from Objective-C and purely Swift?
  • 15. Swift bridge class Employee: RLMObject { dynamic var name = "" // you can specify defaults dynamic var startDate = NSDate() dynamic var salary = 0.0 dynamic var fullTime = true } class Company: RLMObject { dynamic var name = "" dynamic var ceo: Employee? // optional to-one relationship let employees = RLMArray(objectClassName: Employee.className()) // to-many relationship } purely Swift class Employee: Object { dynamic var name = "" // you can specify defaults dynamic var startDate = NSDate() dynamic var salary = 0.0 dynamic var fullTime = true } class Company: Object { dynamic var name = "" dynamic var ceo: Employee? // optional to-one relationship let employees = List<Employee>() // generic to-many relationship }
  • 16. Swift bridge let company = Company() // Using Realm Objects company.name = "Realm Inc." let realm = RLMRealm.defaultRealm() // Default Realm realm.transactionWithBlock({ () -> Void in // Transactions realm.addObject(company) }) // Queries let company = Company.allObjects().firstObject() as! Company company.name // => "Realm Inc." (property access is type-safe) let ftJacks = Employee.objectsWhere("name = 'Jack'").objectsWhere("fullTime = true") // RLMResults purely Swift let company = Company() // Using Realm Objects company.name = "Realm Inc." let realm = Realm() // Default Realm realm.write { // Transactions realm.add(company) } // Queries let companies = realm.objects(Company) // => Results<Company> companies[0].name // => "Realm Inc." (property access is type-safe) // "Jack"s who work full time (lazily loaded & chainable) let ftJacks = realm.objects(Employee).filter("name = 'Jack'") .filter("fullTime = true")
  • 17. Cannot use full Swift features like enum yet, but it's definitely better than before
  • 18. Dealing with JSON in Swift
  • 19. Not sure exactly what kind of values server respond
  • 20. Might be Array, String, Int or nil
  • 22. Make it Optional and Set default values class Employee: Object { dynamic var name: String? = "" dynamic var startDate: NSDate? = NSDate() dynamic var salary: double? = 0.0 dynamic var fullTime: Bool? = true }
  • 23. Use rawValue for enum class Employee: Object { dynamic var type: Int = Type.iOS.rawValue enum Type: Int { case iOS = 1 case Android = 2 } }
  • 24. ignoredProperty could be useful class Employee: Object { var number: Int = 0 var name: String { // computed properties are automatically ignored return "String" } override static func ignoredProperties() -> [String] { return ["number"] } }
  • 25. That's for object mapping so far
  • 26. Next one is the biggest problem
  • 27. nil cannot be saved in Realm
  • 28. If you save nil in Realm, an exception will be thrown
  • 29. Ideally, values should be saved, but nil should be skipped
  • 30. Use following methods with external data • createInDefaultRealmWithValue: • createInRealm: withValue: • createOrUpdateInDefaultRealmWithValue: • createOrUpdateInRealm: withValue: • create(type: T.Type, value: AnyObject = [:], update: Bool = false) in Realm Swift
  • 31. if not exists in Realm yet, default value is used for key, otherwise it's skipped
  • 32. Use following methods with realm object • addObject: • addObjects: • addOrUpdateObject: • addOrUpdateObjectsFromArray: • add(object: Object, update: Bool = false) in Realm Swift • add(objects: S, update: Bool = false) in Realm Swift
  • 33. Realm might support nil soon, so keep it mind that this is just a workaround