SlideShare a Scribd company logo
Nikmesoft Ltd
Data Storage
Linh NGUYEN
Lecture 5
Nikmesoft Ltd
Contents
2
Overview1
Working with Files2
Store user’s settings3
Core Data4
Exercise 55
Nikmesoft Ltd
Data Storage
Overview
3
Nikmesoft Ltd
Overview
4
iPhone
LacaApp
(.ipa)
Install
Nikmesoft Ltd
Overview
5
iPhone
LacaApp
iPhone
Document
Library
tmp
Lacap.app
Cache
Others
Nikmesoft Ltd
Overview
 Document: will be synced with iCloud
 Library: will not be synced
 Lacap.app: read only
6
Nikmesoft Ltd
Data Storage
Working with Files
7
Nikmesoft Ltd
Working with Files
 The Foundation Framework provides three classes that are
indispensable when it comes to working with files and
directories:
 NSFileManager: The NSFileManager class can be used to
perform basic file and directory operations such as creating,
moving, reading and writing files and reading and setting file
attributes
8
Nikmesoft Ltd
Working with Files
 The Foundation Framework provides three classes that are
indispensable when it comes to working with files and
directories:
 NSFileHandle: The NSFileHandle class is provided for performing
lower level operations on files, such as seeking to a specific
position in a file and reading and writing a file's contents by a
specified number of byte chunks and appending data to an
existing file.
 NSData: The NSData class provides a useful storage buffer into
which the contents of a file may be read, or from which data may
be written to a file.
9
Nikmesoft Ltd
Working with Files
 Playing with Directory
10
Nikmesoft Ltd
Working with Files
11
Nikmesoft Ltd
Working with Files
 Playing with Directory
12
Nikmesoft Ltd
Working with Files
13
Nikmesoft Ltd
Working with Files
14
Nikmesoft Ltd
Data Storage
Store User’s Settings
15
Nikmesoft Ltd
Store User’s Settings
 Saving and retrieving different types of data using
the NSUserDefaults object. Saving this way is great for
when you want to save small amounts of data such as High
Scores, Login Information, and program state.
 Saving to the NSUserDefaults is great because it does not
require any special database knowledge.
16
Nikmesoft Ltd
Store User’s Settings
17
Nikmesoft Ltd
Store User’s Settings
18
Nikmesoft Ltd
Data Storage
Core Data
19
Nikmesoft Ltd
Core Data
 SQLite
20
App launch Check iPhone
Db.sqlite
LacaApp
Not
exist
Copy
Db.sql
ite
Nikmesoft Ltd
Core Data
 Why Should You Use Core Data?
 One of the simplest metrics is that, with Core Data, the amount of
code you write to support the model layer of your application is
typically 50% to 70% smaller as measured by lines of code.
 Core Data has a mature code base whose quality is maintained
through unit tests, and is used daily by millions of customers in a
wide variety of applications. The framework has been highly
optimized over several releases.
21
Nikmesoft Ltd
Core Data
 Why Should You Use Core Data?
 You don’t have to implement yourself
 You don’t have to test yourself
 You don’t have to optimize yourself.
22
Nikmesoft Ltd
Core Data
 What Core Data Is Not
 Core Data is not a relational database or a relational database
management system (RDBMS).
 Core Data is not a silver bullet. Core Data does not remove the
need to write code. Although it is possible to create a
sophisticated application solely using the Xcode data modeling
tool and Interface Builder, for more real-world applications you will
still have to write code.
23
Nikmesoft Ltd
Core Data
 What Core Data Is Not
 Core Data is not a relational database or a relational database
management system (RDBMS).
 Core Data is not a silver bullet. Core Data does not remove the
need to write code. Although it is possible to create a
sophisticated application solely using the Xcode data modeling
tool and Interface Builder, for more real-world applications you will
still have to write code.
24
Nikmesoft Ltd
Core Data
 What Core Data Is Not
 Core Data is not a relational database or a relational database
management system (RDBMS).
 Core Data is not a silver bullet. Core Data does not remove the
need to write code. Although it is possible to create a
sophisticated application solely using the Xcode data modeling
tool and Interface Builder, for more real-world applications you will
still have to write code.
25
Nikmesoft Ltd
Core Data
26
Overview
Nikmesoft Ltd
Core Data
27
Managed
Object
Context
Managed
Object
Context
Managed
Object
Context
Managed
Object
Context
Managed
Object A
Managed
Object B
Managed
Object B
Managed
Object B
Managed
Object A
Managed
Object
Context
Nikmesoft Ltd
Core Data
28
Fetch
Request
Nikmesoft Ltd
Core Data
29
Persistent
Store
Coordinator
Nikmesoft Ltd
Core Data
 Managed Object Models
 Much of Core Data's functionality depends on the schema you
create to describe your application's entities, their properties, and
the relationships between them. The schema is represented by a
managed object model—an instance of NSManagedObjectModel
 Features of a Managed Object Model
30
Nikmesoft Ltd
Core Data
 Managed Object Models
 Features of a Managed Object Model
• Entities
• Entity Inheritance
• Abstract Entities
• Properties
• An entity's properties are its attributes and
relationships, including its fetched properties
(if it has any). Amongst other features, each
property has a name and a type. Attributes
may also have a default value.
31
Nikmesoft Ltd
Core Data
 Managed Object Models
 Features of a Managed Object Model
• Attributes: Core Data natively supports a variety of attribute types, such as
string, date, and integer (represented as instances of NSString, NSDate,
and NSNumber respectively). If you want to use an attribute type that is not
natively supported, you can use one of the techniques described in “Non-
Standard Persistent Attributes.”
• You can specify that an attribute is optional—that is, it is not required to
have a value. In general, however, you are discouraged from doing so—
especially for numeric values (typically you can get better results using a
mandatory attribute with a default value—in the model—of 0).
32
Nikmesoft Ltd
Core Data
 Managed Object Models
 Features of a Managed Object Model
• Relationships: Core Data supports to-one and to-many relationships,
and fetched properties.
• Inverse Relationships
• Relationship Delete Rules
33
Name
Employee
List
Name
Department
Nikmesoft Ltd
Core Data
 Deny
 If there is at least one object at the relationship destination, then
the source object cannot be deleted.
 For example, if you want to remove a department, you must
ensure that all the employees in that department are first
transferred elsewhere (or fired!) otherwise the department
cannot be deleted.
34
Nikmesoft Ltd
Core Data
 Nullify
 Set the inverse relationship for objects at the destination to null.
 For example, if you delete a department, set the department for
all the current members to null. This only makes sense if the
department relationship for an employee is optional, or if you
ensure that you set a new department for each of the
employees before the next save operation.
35
Nikmesoft Ltd
Core Data
 Cascade
 Delete the objects at the destination of the relationship.
 For example, if you delete a department, fire all the employees
in that department at the same time.
36
Nikmesoft Ltd
Core Data
 No Action
 Do nothing to the object at the destination of the relationship.
 For example, if you delete a department, leave all the
employees as they are, even if they still believe they belong to
that department.
37
Nikmesoft Ltd
Core Data
 Many-to-Many Relationships
 You define a many-to-many relationship using two to-many
relationships. The first to-many relationship goes from the first
entity to the second entity. The second to-many relationship
goes from the second entity to the first entity. You then set each
to be the inverse of the other.
 A relationship can also be the inverse of itself. For example, a
Person entity may have a cousins relationship that is the
inverse of itself.
38
Nikmesoft Ltd
Core Data
 Many-to-Many Relationships
39
Nikmesoft Ltd
Core Data
 Many-to-Many Relationships
40
Nikmesoft Ltd
Core Data
 Cross-Store Relationships
 You must be careful not to create relationships from instances in
one persistent store to instances in another persistent store, as
this is not supported by Core Data. If you need to create a
relationship between entities in different stores, you typically
use fetched properties
41
Nikmesoft Ltd
Core Data
 Using Persistent Stores
 Access to stores is mediated by an instance of
NSPersistentStoreCoordinator. You should not need to
directly access a file containing a store. From a persistent store
coordinator, you can retrieve an object that represents a
particular store on disk. Core Data provides an
NSPersistentStore class to represent persistent stores.
42
Nikmesoft Ltd
Core Data
 Using Persistent Stores
 To create a store, you use a persistent store coordinator. You
must specify the type of the store to be created, optionally a
configuration of managed object model associated with the
coordinator, and its location if it is not an in-memory store.
43
Nikmesoft Ltd
Core Data
 Using Persistent Stores
44
Nikmesoft Ltd
Core Data
 Using Persistent Stores
45
Nikmesoft Ltd
Core Data
 Using Fetched Request
46
Nikmesoft Ltd
Core Data
 New/Delete a NSManagedObject
47
Nikmesoft Ltd
Core Data
 Example 5.1
48
Nikmesoft Ltd
Core Data
 NSFetchedResultsControllers
49
Nikmesoft Ltd
Core Data
 NSFetchedResultsControllers
50
Nikmesoft Ltd
Core Data
 NSFetchedResultsControllers
51
Nikmesoft Ltd
Core Data
 NSFetchedResultsControllers
52
Nikmesoft Ltd
Core Data
 Example 5.2
53
Nikmesoft Ltd
54

More Related Content

What's hot

MongoDB HA - what can go wrong
MongoDB HA - what can go wrongMongoDB HA - what can go wrong
MongoDB HA - what can go wrong
Igor Donchovski
 
Enhancing the default MongoDB Security
Enhancing the default MongoDB SecurityEnhancing the default MongoDB Security
Enhancing the default MongoDB Security
Igor Donchovski
 
Exploring the replication and sharding in MongoDB
Exploring the replication and sharding in MongoDBExploring the replication and sharding in MongoDB
Exploring the replication and sharding in MongoDB
Igor Donchovski
 
Topic 12: NoSQL in Action
Topic 12: NoSQL in ActionTopic 12: NoSQL in Action
Topic 12: NoSQL in Action
Zubair Nabi
 
How to scale MongoDB
How to scale MongoDBHow to scale MongoDB
How to scale MongoDB
Igor Donchovski
 
Maintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsMaintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica Sets
Igor Donchovski
 
Hibernate for Beginners
Hibernate for BeginnersHibernate for Beginners
Hibernate for Beginners
Ramesh Kumar
 
2012 phoenix mug
2012 phoenix mug2012 phoenix mug
2012 phoenix mug
Paul Pedersen
 
OData, Open Data Protocol. A brief introduction
OData, Open Data Protocol. A brief introductionOData, Open Data Protocol. A brief introduction
OData, Open Data Protocol. A brief introduction
Eugenio Lentini
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
Tharun Srinivasa
 
MongoDB and Spark
MongoDB and SparkMongoDB and Spark
MongoDB and Spark
Norberto Leite
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL database
Tobias Lindaaker
 

What's hot (12)

MongoDB HA - what can go wrong
MongoDB HA - what can go wrongMongoDB HA - what can go wrong
MongoDB HA - what can go wrong
 
Enhancing the default MongoDB Security
Enhancing the default MongoDB SecurityEnhancing the default MongoDB Security
Enhancing the default MongoDB Security
 
Exploring the replication and sharding in MongoDB
Exploring the replication and sharding in MongoDBExploring the replication and sharding in MongoDB
Exploring the replication and sharding in MongoDB
 
Topic 12: NoSQL in Action
Topic 12: NoSQL in ActionTopic 12: NoSQL in Action
Topic 12: NoSQL in Action
 
How to scale MongoDB
How to scale MongoDBHow to scale MongoDB
How to scale MongoDB
 
Maintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsMaintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica Sets
 
Hibernate for Beginners
Hibernate for BeginnersHibernate for Beginners
Hibernate for Beginners
 
2012 phoenix mug
2012 phoenix mug2012 phoenix mug
2012 phoenix mug
 
OData, Open Data Protocol. A brief introduction
OData, Open Data Protocol. A brief introductionOData, Open Data Protocol. A brief introduction
OData, Open Data Protocol. A brief introduction
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
 
MongoDB and Spark
MongoDB and SparkMongoDB and Spark
MongoDB and Spark
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL database
 

Viewers also liked

iOS Basics: Introducing the iPad, iPhone, and iCloud
iOS Basics: Introducing the iPad, iPhone, and iCloudiOS Basics: Introducing the iPad, iPhone, and iCloud
iOS Basics: Introducing the iPad, iPhone, and iCloud
St. Petersburg College
 
Linear Regression
Linear RegressionLinear Regression
Linear Regression
Ryan Sain
 
[iOS] Navigation
[iOS] Navigation[iOS] Navigation
[iOS] Navigation
Nikmesoft Ltd
 
iOS: Overview, Architecture, Development & Versions
iOS: Overview, Architecture, Development & Versions iOS: Overview, Architecture, Development & Versions
iOS: Overview, Architecture, Development & Versions
Sandra Kerbage
 
A seminar report on i cloud
A  seminar report on i cloudA  seminar report on i cloud
A seminar report on i cloud
Nagamalleswararao Tadikonda
 
[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS Programming[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS Programming
Nikmesoft Ltd
 
iOS Application Penetration Testing
iOS Application Penetration TestingiOS Application Penetration Testing
iOS Application Penetration Testing
n|u - The Open Security Community
 
iOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersiOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for Beginners
RyanISI
 
Pentesting iOS Applications
Pentesting iOS ApplicationsPentesting iOS Applications
Pentesting iOS Applications
jasonhaddix
 
[iOS] Basic UI Elements
[iOS] Basic UI Elements[iOS] Basic UI Elements
[iOS] Basic UI Elements
Nikmesoft Ltd
 
Ios operating system
Ios operating systemIos operating system
Ios operating system
Khaja Moiz Uddin
 
Apple iOS
Apple iOSApple iOS
Apple iOS
Chetan Gowda
 

Viewers also liked (12)

iOS Basics: Introducing the iPad, iPhone, and iCloud
iOS Basics: Introducing the iPad, iPhone, and iCloudiOS Basics: Introducing the iPad, iPhone, and iCloud
iOS Basics: Introducing the iPad, iPhone, and iCloud
 
Linear Regression
Linear RegressionLinear Regression
Linear Regression
 
[iOS] Navigation
[iOS] Navigation[iOS] Navigation
[iOS] Navigation
 
iOS: Overview, Architecture, Development & Versions
iOS: Overview, Architecture, Development & Versions iOS: Overview, Architecture, Development & Versions
iOS: Overview, Architecture, Development & Versions
 
A seminar report on i cloud
A  seminar report on i cloudA  seminar report on i cloud
A seminar report on i cloud
 
[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS Programming[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS Programming
 
iOS Application Penetration Testing
iOS Application Penetration TestingiOS Application Penetration Testing
iOS Application Penetration Testing
 
iOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersiOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for Beginners
 
Pentesting iOS Applications
Pentesting iOS ApplicationsPentesting iOS Applications
Pentesting iOS Applications
 
[iOS] Basic UI Elements
[iOS] Basic UI Elements[iOS] Basic UI Elements
[iOS] Basic UI Elements
 
Ios operating system
Ios operating systemIos operating system
Ios operating system
 
Apple iOS
Apple iOSApple iOS
Apple iOS
 

Similar to [iOS] Data Storage

Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Karen Thompson
 
Entity framework
Entity frameworkEntity framework
Entity framework
Mehdi jannati
 
Hibernate I
Hibernate IHibernate I
Hibernate I
People Strategists
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
Guidelines DataCite Denmark 2014
Guidelines DataCite Denmark 2014Guidelines DataCite Denmark 2014
Guidelines DataCite Denmark 2014
DTU Library
 
Oracle developer interview questions(entry level)
Oracle developer interview questions(entry level)Oracle developer interview questions(entry level)
Oracle developer interview questions(entry level)
Naveen P
 
Iphone programming: Core Data Tutorial for iOS
Iphone programming: Core Data Tutorial for iOSIphone programming: Core Data Tutorial for iOS
Iphone programming: Core Data Tutorial for iOS
Kenny Nguyen
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
Mahmoud Tolba
 
DataOps - The Foundation for Your Agile Data Architecture
DataOps - The Foundation for Your Agile Data ArchitectureDataOps - The Foundation for Your Agile Data Architecture
DataOps - The Foundation for Your Agile Data Architecture
DATAVERSITY
 
Ado.net session01
Ado.net session01Ado.net session01
Ado.net session01
Niit Care
 
Guidelines data cite_denmark_ver2
Guidelines data cite_denmark_ver2Guidelines data cite_denmark_ver2
Guidelines data cite_denmark_ver2
DTU Library
 
Guidelines data cite_denmark_ver3
Guidelines data cite_denmark_ver3Guidelines data cite_denmark_ver3
Guidelines data cite_denmark_ver3
DTU Library
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource GroupLINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
Shahzad
 
Hibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ NizampetHibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ Nizampet
Jayarajus
 
Domain Driven Design for Angular
Domain Driven Design for AngularDomain Driven Design for Angular
Domain Driven Design for Angular
Jennifer Estrada
 
Nhibernate Part 1
Nhibernate   Part 1Nhibernate   Part 1
Nhibernate Part 1
guest075fec
 
2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt
Chadharris42
 
Entity framework1
Entity framework1Entity framework1
Entity framework1
Girish Gowda
 

Similar to [iOS] Data Storage (20)

Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
Hibernate I
Hibernate IHibernate I
Hibernate I
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
 
Guidelines DataCite Denmark 2014
Guidelines DataCite Denmark 2014Guidelines DataCite Denmark 2014
Guidelines DataCite Denmark 2014
 
Oracle developer interview questions(entry level)
Oracle developer interview questions(entry level)Oracle developer interview questions(entry level)
Oracle developer interview questions(entry level)
 
Iphone programming: Core Data Tutorial for iOS
Iphone programming: Core Data Tutorial for iOSIphone programming: Core Data Tutorial for iOS
Iphone programming: Core Data Tutorial for iOS
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
DataOps - The Foundation for Your Agile Data Architecture
DataOps - The Foundation for Your Agile Data ArchitectureDataOps - The Foundation for Your Agile Data Architecture
DataOps - The Foundation for Your Agile Data Architecture
 
Ado.net session01
Ado.net session01Ado.net session01
Ado.net session01
 
Guidelines data cite_denmark_ver2
Guidelines data cite_denmark_ver2Guidelines data cite_denmark_ver2
Guidelines data cite_denmark_ver2
 
Guidelines data cite_denmark_ver3
Guidelines data cite_denmark_ver3Guidelines data cite_denmark_ver3
Guidelines data cite_denmark_ver3
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource GroupLINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
 
Hibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ NizampetHibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ Nizampet
 
Domain Driven Design for Angular
Domain Driven Design for AngularDomain Driven Design for Angular
Domain Driven Design for Angular
 
Nhibernate Part 1
Nhibernate   Part 1Nhibernate   Part 1
Nhibernate Part 1
 
2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt
 
Entity framework1
Entity framework1Entity framework1
Entity framework1
 

More from Nikmesoft Ltd

[Android] Multimedia Programming
[Android] Multimedia Programming[Android] Multimedia Programming
[Android] Multimedia Programming
Nikmesoft Ltd
 
[Android] Android Animation
[Android] Android Animation[Android] Android Animation
[Android] Android Animation
Nikmesoft Ltd
 
[Android] 2D Graphics
[Android] 2D Graphics[Android] 2D Graphics
[Android] 2D Graphics
Nikmesoft Ltd
 
[Android] Services and Broadcast Receivers
[Android] Services and Broadcast Receivers[Android] Services and Broadcast Receivers
[Android] Services and Broadcast Receivers
Nikmesoft Ltd
 
[Android] Web services
[Android] Web services[Android] Web services
[Android] Web services
Nikmesoft Ltd
 
[Android] Multiple Background Threads
[Android] Multiple Background Threads[Android] Multiple Background Threads
[Android] Multiple Background Threads
Nikmesoft Ltd
 
[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services
Nikmesoft Ltd
 
[Android] Data Storage
[Android] Data Storage[Android] Data Storage
[Android] Data Storage
Nikmesoft Ltd
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and Activity
Nikmesoft Ltd
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event Handling
Nikmesoft Ltd
 
[Android] Using Selection Widgets
[Android] Using Selection Widgets[Android] Using Selection Widgets
[Android] Using Selection Widgets
Nikmesoft Ltd
 
[Android] Basic Widgets and Containers
[Android] Basic Widgets and Containers[Android] Basic Widgets and Containers
[Android] Basic Widgets and Containers
Nikmesoft Ltd
 
[Android] Introduction to Android Programming
[Android] Introduction to Android Programming[Android] Introduction to Android Programming
[Android] Introduction to Android Programming
Nikmesoft Ltd
 

More from Nikmesoft Ltd (13)

[Android] Multimedia Programming
[Android] Multimedia Programming[Android] Multimedia Programming
[Android] Multimedia Programming
 
[Android] Android Animation
[Android] Android Animation[Android] Android Animation
[Android] Android Animation
 
[Android] 2D Graphics
[Android] 2D Graphics[Android] 2D Graphics
[Android] 2D Graphics
 
[Android] Services and Broadcast Receivers
[Android] Services and Broadcast Receivers[Android] Services and Broadcast Receivers
[Android] Services and Broadcast Receivers
 
[Android] Web services
[Android] Web services[Android] Web services
[Android] Web services
 
[Android] Multiple Background Threads
[Android] Multiple Background Threads[Android] Multiple Background Threads
[Android] Multiple Background Threads
 
[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services
 
[Android] Data Storage
[Android] Data Storage[Android] Data Storage
[Android] Data Storage
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and Activity
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event Handling
 
[Android] Using Selection Widgets
[Android] Using Selection Widgets[Android] Using Selection Widgets
[Android] Using Selection Widgets
 
[Android] Basic Widgets and Containers
[Android] Basic Widgets and Containers[Android] Basic Widgets and Containers
[Android] Basic Widgets and Containers
 
[Android] Introduction to Android Programming
[Android] Introduction to Android Programming[Android] Introduction to Android Programming
[Android] Introduction to Android Programming
 

Recently uploaded

GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 

Recently uploaded (20)

GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 

[iOS] Data Storage

  • 2. Nikmesoft Ltd Contents 2 Overview1 Working with Files2 Store user’s settings3 Core Data4 Exercise 55
  • 6. Nikmesoft Ltd Overview  Document: will be synced with iCloud  Library: will not be synced  Lacap.app: read only 6
  • 8. Nikmesoft Ltd Working with Files  The Foundation Framework provides three classes that are indispensable when it comes to working with files and directories:  NSFileManager: The NSFileManager class can be used to perform basic file and directory operations such as creating, moving, reading and writing files and reading and setting file attributes 8
  • 9. Nikmesoft Ltd Working with Files  The Foundation Framework provides three classes that are indispensable when it comes to working with files and directories:  NSFileHandle: The NSFileHandle class is provided for performing lower level operations on files, such as seeking to a specific position in a file and reading and writing a file's contents by a specified number of byte chunks and appending data to an existing file.  NSData: The NSData class provides a useful storage buffer into which the contents of a file may be read, or from which data may be written to a file. 9
  • 10. Nikmesoft Ltd Working with Files  Playing with Directory 10
  • 12. Nikmesoft Ltd Working with Files  Playing with Directory 12
  • 15. Nikmesoft Ltd Data Storage Store User’s Settings 15
  • 16. Nikmesoft Ltd Store User’s Settings  Saving and retrieving different types of data using the NSUserDefaults object. Saving this way is great for when you want to save small amounts of data such as High Scores, Login Information, and program state.  Saving to the NSUserDefaults is great because it does not require any special database knowledge. 16
  • 20. Nikmesoft Ltd Core Data  SQLite 20 App launch Check iPhone Db.sqlite LacaApp Not exist Copy Db.sql ite
  • 21. Nikmesoft Ltd Core Data  Why Should You Use Core Data?  One of the simplest metrics is that, with Core Data, the amount of code you write to support the model layer of your application is typically 50% to 70% smaller as measured by lines of code.  Core Data has a mature code base whose quality is maintained through unit tests, and is used daily by millions of customers in a wide variety of applications. The framework has been highly optimized over several releases. 21
  • 22. Nikmesoft Ltd Core Data  Why Should You Use Core Data?  You don’t have to implement yourself  You don’t have to test yourself  You don’t have to optimize yourself. 22
  • 23. Nikmesoft Ltd Core Data  What Core Data Is Not  Core Data is not a relational database or a relational database management system (RDBMS).  Core Data is not a silver bullet. Core Data does not remove the need to write code. Although it is possible to create a sophisticated application solely using the Xcode data modeling tool and Interface Builder, for more real-world applications you will still have to write code. 23
  • 24. Nikmesoft Ltd Core Data  What Core Data Is Not  Core Data is not a relational database or a relational database management system (RDBMS).  Core Data is not a silver bullet. Core Data does not remove the need to write code. Although it is possible to create a sophisticated application solely using the Xcode data modeling tool and Interface Builder, for more real-world applications you will still have to write code. 24
  • 25. Nikmesoft Ltd Core Data  What Core Data Is Not  Core Data is not a relational database or a relational database management system (RDBMS).  Core Data is not a silver bullet. Core Data does not remove the need to write code. Although it is possible to create a sophisticated application solely using the Xcode data modeling tool and Interface Builder, for more real-world applications you will still have to write code. 25
  • 27. Nikmesoft Ltd Core Data 27 Managed Object Context Managed Object Context Managed Object Context Managed Object Context Managed Object A Managed Object B Managed Object B Managed Object B Managed Object A Managed Object Context
  • 30. Nikmesoft Ltd Core Data  Managed Object Models  Much of Core Data's functionality depends on the schema you create to describe your application's entities, their properties, and the relationships between them. The schema is represented by a managed object model—an instance of NSManagedObjectModel  Features of a Managed Object Model 30
  • 31. Nikmesoft Ltd Core Data  Managed Object Models  Features of a Managed Object Model • Entities • Entity Inheritance • Abstract Entities • Properties • An entity's properties are its attributes and relationships, including its fetched properties (if it has any). Amongst other features, each property has a name and a type. Attributes may also have a default value. 31
  • 32. Nikmesoft Ltd Core Data  Managed Object Models  Features of a Managed Object Model • Attributes: Core Data natively supports a variety of attribute types, such as string, date, and integer (represented as instances of NSString, NSDate, and NSNumber respectively). If you want to use an attribute type that is not natively supported, you can use one of the techniques described in “Non- Standard Persistent Attributes.” • You can specify that an attribute is optional—that is, it is not required to have a value. In general, however, you are discouraged from doing so— especially for numeric values (typically you can get better results using a mandatory attribute with a default value—in the model—of 0). 32
  • 33. Nikmesoft Ltd Core Data  Managed Object Models  Features of a Managed Object Model • Relationships: Core Data supports to-one and to-many relationships, and fetched properties. • Inverse Relationships • Relationship Delete Rules 33 Name Employee List Name Department
  • 34. Nikmesoft Ltd Core Data  Deny  If there is at least one object at the relationship destination, then the source object cannot be deleted.  For example, if you want to remove a department, you must ensure that all the employees in that department are first transferred elsewhere (or fired!) otherwise the department cannot be deleted. 34
  • 35. Nikmesoft Ltd Core Data  Nullify  Set the inverse relationship for objects at the destination to null.  For example, if you delete a department, set the department for all the current members to null. This only makes sense if the department relationship for an employee is optional, or if you ensure that you set a new department for each of the employees before the next save operation. 35
  • 36. Nikmesoft Ltd Core Data  Cascade  Delete the objects at the destination of the relationship.  For example, if you delete a department, fire all the employees in that department at the same time. 36
  • 37. Nikmesoft Ltd Core Data  No Action  Do nothing to the object at the destination of the relationship.  For example, if you delete a department, leave all the employees as they are, even if they still believe they belong to that department. 37
  • 38. Nikmesoft Ltd Core Data  Many-to-Many Relationships  You define a many-to-many relationship using two to-many relationships. The first to-many relationship goes from the first entity to the second entity. The second to-many relationship goes from the second entity to the first entity. You then set each to be the inverse of the other.  A relationship can also be the inverse of itself. For example, a Person entity may have a cousins relationship that is the inverse of itself. 38
  • 39. Nikmesoft Ltd Core Data  Many-to-Many Relationships 39
  • 40. Nikmesoft Ltd Core Data  Many-to-Many Relationships 40
  • 41. Nikmesoft Ltd Core Data  Cross-Store Relationships  You must be careful not to create relationships from instances in one persistent store to instances in another persistent store, as this is not supported by Core Data. If you need to create a relationship between entities in different stores, you typically use fetched properties 41
  • 42. Nikmesoft Ltd Core Data  Using Persistent Stores  Access to stores is mediated by an instance of NSPersistentStoreCoordinator. You should not need to directly access a file containing a store. From a persistent store coordinator, you can retrieve an object that represents a particular store on disk. Core Data provides an NSPersistentStore class to represent persistent stores. 42
  • 43. Nikmesoft Ltd Core Data  Using Persistent Stores  To create a store, you use a persistent store coordinator. You must specify the type of the store to be created, optionally a configuration of managed object model associated with the coordinator, and its location if it is not an in-memory store. 43
  • 44. Nikmesoft Ltd Core Data  Using Persistent Stores 44
  • 45. Nikmesoft Ltd Core Data  Using Persistent Stores 45
  • 46. Nikmesoft Ltd Core Data  Using Fetched Request 46
  • 47. Nikmesoft Ltd Core Data  New/Delete a NSManagedObject 47
  • 48. Nikmesoft Ltd Core Data  Example 5.1 48
  • 49. Nikmesoft Ltd Core Data  NSFetchedResultsControllers 49
  • 50. Nikmesoft Ltd Core Data  NSFetchedResultsControllers 50
  • 51. Nikmesoft Ltd Core Data  NSFetchedResultsControllers 51
  • 52. Nikmesoft Ltd Core Data  NSFetchedResultsControllers 52
  • 53. Nikmesoft Ltd Core Data  Example 5.2 53