SlideShare a Scribd company logo
A Swift Introduction to Swift
Kaitlin Mahar
What makes Swift Swift?
Kaitlin Mahar
Drivers Engineer @ MongoDB
What is a MongoDB driver?
app driver MongoDB
… !!
BSON
00101...
Why build a Swift driver?
Perfect
MongoDB
Mobile
Swift web
frameworks
What is Swift, anyway?
What is Swift?
• released in 2014, open-sourced in 2015
• up to version 4.1.2
Why did Apple create Swift?
“Objective-C without the C”
So why do people still use Objective-C?
young language
small community
breaking changes
So why should I use Swift?
Swift makes working with
C libraries easy.
The Swift driver wraps the C driver.
Swift
app
MongoDB
Swift driver
C driver
Swift can run in the same program as C.
C Objective-C
Descriptive Pointer Types
OpaquePointer
• Points to a C type that
can’t be represented in
Swift because we can’t
access its internals
• Can’t be dereferenced
UnsafePointer<T>
• Points to a C type, T,
that we can access
internals of
• Can be deferenced using
its .pointee property
Descriptive Pointer Types
UnsafePointer<T>
UnsafeMutablePointer<T>
UnsafeBufferPointer<T>
UnsafeMutableBufferPointer<T>
UnsafeRawPointer
UnsafeMutableRawPointer
UnsafeRawBufferPointer
UnsafeMutableRawBufferPointer
<T> or Raw
Mutable (or not)
Buffer (or not)
Using OpaquePointers in MongoSwift
Using UnsafePointers in MongoSwift
Generated Swift interfaces
Generated Swift interfaces
Generated Swift interfaces
Challenges of C interoperation
Swift has a powerful
type system.
Built-in Optional
Support
What is an optional?
What is an optional?
A typed value that is optionally set
Optional Chaining
Using Optionals in MongoSwift
Using Optionals in MongoSwift
Using Optionals in MongoSwift
Extensions
Extensions
Add new functionality to existing types
Protocol-oriented
programming
Protocols
• Similar to an interface in other languages -
specify a required set of properties and methods
• In order to conform to a protocol, a type must
implement its requirements
ExpressibleByDictionaryLiteral
ExpressibleByDictionaryLiteral
ExpressibleByDictionaryLiteral
How to represent BSON values?
Double String
Document Array
Binary ObjectId
Boolean Date
Regex CodeWithScope
Int32 Timestamp
Int64 Decimal128
MinKey MaxKey
How to represent BSON values?
Double String
Document Array
Binary ObjectId
Boolean Date
Regex CodeWithScope
Int32 Timestamp
Int64 Decimal128
MinKey MaxKey
Custom protocols
Custom types can conform to protocols
Native types can be extended to conform to protocols
Protocols can be used as types
Protocols can be used as types
Generics
Generics
Generics
Generics With Constraints
Using Generics in MongoSwift
Challenges of Swift’s type system
• Lacking some desired features
• Auto-generated Equatable
Equatable protocol
Challenges of Swift’s type system
• Lacking some desired features
• Auto-generated Equatable, Hashable
• Default type parameters
Default Type Parameters
maybe someday:
now:
What’s next for the driver?
• Implement the full MongoDB CRUD API
• Support for MongoDB 4.0 features
• Support for more complex DB configurations
• Integration with Swift web frameworks
• Replace libbson usage with native Swift
In summary…
• Swift is new and exciting!
• Swift has a powerful type system: protocols,
extensions, generics, optionals, and more.
• Swift interoperates easily with C.
• You should try writing Swift!
Want to learn more?
Today:
3:30pm MongoDB Mobile talk
On your own:
The Swift Programming Language (by Apple, free)
objc.io videos and books
Swift by Sundell (blog)
Kaitlin Mahar
Drivers Engineer @ MongoDB
@k__mahar @kmahar

More Related Content

What's hot (20)

PPTX
WordCamp Pune 2017- WordPress Coding standards
Swapnil Patil
 
PDF
Implement Web API with Swagger
Jiang Wu
 
PDF
To SDK or not to SDK?
Lukas Leander Rosenstock
 
PPTX
Coding Standard And Code Review
Milan Vukoje
 
PPTX
Entity Framework Today (May 2012)
Julie Lerman
 
PPTX
Swagger APIs for Humans and Robots (Gluecon)
Tony Tam
 
PDF
Kotlin & Arrow the functional way
Thoughtworks
 
PPTX
Introduction of lambda expression and predicate builder
LearningTech
 
PDF
Streamlining API with Swagger.io
Victor Augusteo
 
PDF
Specification-driven API Design with OpenAPI
Lukas Leander Rosenstock
 
PDF
Quick run in with Swagger
Mesh Korea
 
PPTX
Kotlin For Android (at DevFest İzmir 2016)
Semih Bozdemir
 
PPTX
Swift Aims
Selecto
 
PDF
Pair programming
Frank Sons
 
PDF
Better Swift from the Foundation up #tryswiftnyc17 09-06
Carl Brown
 
PPTX
EF6 or EF Core? How Do I Choose?
Julie Lerman
 
PPT
Jug dynamic languages_in_jvm
Dmitry Buzdin
 
PDF
Swift should I switch?
wulfgeng
 
PPTX
C# 4.0 and .NET 4.0
Buu Nguyen
 
PDF
Разработка документации для RESTful API: как убить трёх зайцев одним. Moscow....
Moscow.pm
 
WordCamp Pune 2017- WordPress Coding standards
Swapnil Patil
 
Implement Web API with Swagger
Jiang Wu
 
To SDK or not to SDK?
Lukas Leander Rosenstock
 
Coding Standard And Code Review
Milan Vukoje
 
Entity Framework Today (May 2012)
Julie Lerman
 
Swagger APIs for Humans and Robots (Gluecon)
Tony Tam
 
Kotlin & Arrow the functional way
Thoughtworks
 
Introduction of lambda expression and predicate builder
LearningTech
 
Streamlining API with Swagger.io
Victor Augusteo
 
Specification-driven API Design with OpenAPI
Lukas Leander Rosenstock
 
Quick run in with Swagger
Mesh Korea
 
Kotlin For Android (at DevFest İzmir 2016)
Semih Bozdemir
 
Swift Aims
Selecto
 
Pair programming
Frank Sons
 
Better Swift from the Foundation up #tryswiftnyc17 09-06
Carl Brown
 
EF6 or EF Core? How Do I Choose?
Julie Lerman
 
Jug dynamic languages_in_jvm
Dmitry Buzdin
 
Swift should I switch?
wulfgeng
 
C# 4.0 and .NET 4.0
Buu Nguyen
 
Разработка документации для RESTful API: как убить трёх зайцев одним. Moscow....
Moscow.pm
 

Similar to MongoDB World 2018: A Swift Introduction to Swift (20)

PDF
Swift, swiftly
Jack Nutting
 
PPTX
Tech breakfast 18
James Leone
 
PDF
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum
 
PDF
Advanced Swift Updated For Swift 5 Chris Eidhof
jksjzdl5949
 
PDF
Cocoa Design Patterns in Swift
Michele Titolo
 
PDF
Intro toswift1
Jordan Morgan
 
PDF
Swift, a quick overview
Julian Król
 
PDF
Introduction to Swift
Matteo Battaglio
 
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
Jonathan Engelsma
 
PPTX
Developer’s viewpoint on swift programming language
Azilen Technologies Pvt. Ltd.
 
PDF
iOS NSAgora #3: Objective-C vs. Swift
Alex Cristea
 
PDF
Swift Tutorial Part 2. The complete guide for Swift programming language
Hossam Ghareeb
 
PDF
The Swift Compiler and Standard Library
Santosh Rajan
 
PDF
Swift Programming
Codemotion
 
PDF
Swift Introduction
Giuseppe Arici
 
PDF
Taller Swift - iCon
iCon
 
PDF
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
PDF
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Aniruddha Chakrabarti
 
PDF
Generics programming in Swift
Vijaya Prakash Kandel
 
Swift, swiftly
Jack Nutting
 
Tech breakfast 18
James Leone
 
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum
 
Advanced Swift Updated For Swift 5 Chris Eidhof
jksjzdl5949
 
Cocoa Design Patterns in Swift
Michele Titolo
 
Intro toswift1
Jordan Morgan
 
Swift, a quick overview
Julian Król
 
Introduction to Swift
Matteo Battaglio
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
Jonathan Engelsma
 
Developer’s viewpoint on swift programming language
Azilen Technologies Pvt. Ltd.
 
iOS NSAgora #3: Objective-C vs. Swift
Alex Cristea
 
Swift Tutorial Part 2. The complete guide for Swift programming language
Hossam Ghareeb
 
The Swift Compiler and Standard Library
Santosh Rajan
 
Swift Programming
Codemotion
 
Swift Introduction
Giuseppe Arici
 
Taller Swift - iCon
iCon
 
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Aniruddha Chakrabarti
 
Generics programming in Swift
Vijaya Prakash Kandel
 
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
Ad

Recently uploaded (20)

PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Python basic programing language for automation
DanialHabibi2
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 

MongoDB World 2018: A Swift Introduction to Swift