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

PPTX
New Things in C# 6.0
PDF
Swagger for-your-api
PDF
apidays LIVE Hong Kong 2021 - Less Data is More by Damir Svrtan, Netflix
PDF
Integration Testing for Polyglot Ecosystems
PPT
Swift Introduction
PDF
Kotlin & arrow: the functional way
PDF
20 Facts about Swift programming language
PPTX
Rest API with Swagger and NodeJS
New Things in C# 6.0
Swagger for-your-api
apidays LIVE Hong Kong 2021 - Less Data is More by Damir Svrtan, Netflix
Integration Testing for Polyglot Ecosystems
Swift Introduction
Kotlin & arrow: the functional way
20 Facts about Swift programming language
Rest API with Swagger and NodeJS

What's hot (20)

PPTX
WordCamp Pune 2017- WordPress Coding standards
PDF
Implement Web API with Swagger
PDF
To SDK or not to SDK?
PPTX
Coding Standard And Code Review
PPTX
Entity Framework Today (May 2012)
PPTX
Swagger APIs for Humans and Robots (Gluecon)
PDF
Kotlin & Arrow the functional way
PPTX
Introduction of lambda expression and predicate builder
PDF
Streamlining API with Swagger.io
PDF
Specification-driven API Design with OpenAPI
PDF
Quick run in with Swagger
PPTX
Kotlin For Android (at DevFest İzmir 2016)
PPTX
Swift Aims
PDF
Pair programming
PDF
Better Swift from the Foundation up #tryswiftnyc17 09-06
PPTX
EF6 or EF Core? How Do I Choose?
PPT
Jug dynamic languages_in_jvm
PDF
Swift should I switch?
PPTX
C# 4.0 and .NET 4.0
PDF
Разработка документации для RESTful API: как убить трёх зайцев одним. Moscow....
WordCamp Pune 2017- WordPress Coding standards
Implement Web API with Swagger
To SDK or not to SDK?
Coding Standard And Code Review
Entity Framework Today (May 2012)
Swagger APIs for Humans and Robots (Gluecon)
Kotlin & Arrow the functional way
Introduction of lambda expression and predicate builder
Streamlining API with Swagger.io
Specification-driven API Design with OpenAPI
Quick run in with Swagger
Kotlin For Android (at DevFest İzmir 2016)
Swift Aims
Pair programming
Better Swift from the Foundation up #tryswiftnyc17 09-06
EF6 or EF Core? How Do I Choose?
Jug dynamic languages_in_jvm
Swift should I switch?
C# 4.0 and .NET 4.0
Разработка документации для RESTful API: как убить трёх зайцев одним. Moscow....
Ad

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

PPTX
Weekly Session with the local .NET Developer Community
PPTX
APIs at Scale with TypeSpec by Mandy Whaley, Microsoft
PDF
NetWork - 15.10.2011 - Applied code generation in .NET
PDF
Facilitating Idiomatic Swift with Objective-C
PPTX
Ch-4 Middleware Architectures.pptx
PDF
The Python in the Apple
DOCX
Event Driven Programming in C#.docx
PDF
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
PPTX
Cursor - AI Code Editor: Revolutionizing Coding with AI-Powered Tools
PPTX
AngularConf2015
PPTX
The advantage of developing with TypeScript
DOCX
Get Codeigniter Developement Services From Us
PPTX
TypeScript and Angular2 (Love at first sight)
PPTX
Managing modular software for your nu get, c++ and java development
PPTX
Enhance Your Code Quality with Code Contracts
PPTX
Advance C# Programming Part 1.pptx
PPTX
Funky serverless features at aws
PPTX
Angular2.0@Shanghai0319
PPTX
Swagger for startups
Weekly Session with the local .NET Developer Community
APIs at Scale with TypeSpec by Mandy Whaley, Microsoft
NetWork - 15.10.2011 - Applied code generation in .NET
Facilitating Idiomatic Swift with Objective-C
Ch-4 Middleware Architectures.pptx
The Python in the Apple
Event Driven Programming in C#.docx
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
Cursor - AI Code Editor: Revolutionizing Coding with AI-Powered Tools
AngularConf2015
The advantage of developing with TypeScript
Get Codeigniter Developement Services From Us
TypeScript and Angular2 (Love at first sight)
Managing modular software for your nu get, c++ and java development
Enhance Your Code Quality with Code Contracts
Advance C# Programming Part 1.pptx
Funky serverless features at aws
Angular2.0@Shanghai0319
Swagger for startups
Ad

More from MongoDB (20)

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

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
cuic standard and advanced reporting.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Big Data Technologies - Introduction.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Machine Learning_overview_presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Programs and apps: productivity, graphics, security and other tools
A comparative analysis of optical character recognition models for extracting...
sap open course for s4hana steps from ECC to s4
cuic standard and advanced reporting.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
The AUB Centre for AI in Media Proposal.docx
Machine Learning_overview_presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
NewMind AI Weekly Chronicles - August'25-Week II

MongoDB World 2018: A Swift Introduction to Swift