SlideShare ist ein Scribd-Unternehmen logo
1 von 54
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

Weitere ähnliche Inhalte

Was ist angesagt?

MongoDB HA - what can go wrong
MongoDB HA - what can go wrongMongoDB HA - what can go wrong
MongoDB HA - what can go wrongIgor Donchovski
 
Enhancing the default MongoDB Security
Enhancing the default MongoDB SecurityEnhancing the default MongoDB Security
Enhancing the default MongoDB SecurityIgor 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 MongoDBIgor Donchovski
 
Topic 12: NoSQL in Action
Topic 12: NoSQL in ActionTopic 12: NoSQL in Action
Topic 12: NoSQL in ActionZubair Nabi
 
Maintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsMaintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsIgor Donchovski
 
Hibernate for Beginners
Hibernate for BeginnersHibernate for Beginners
Hibernate for BeginnersRamesh Kumar
 
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 introductionEugenio Lentini
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and ShardingTharun Srinivasa
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL databaseTobias Lindaaker
 

Was ist angesagt? (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
 

Andere mochten auch

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 iCloudSt. Petersburg College
 
Linear Regression
Linear RegressionLinear Regression
Linear RegressionRyan Sain
 
iOS: Overview, Architecture, Development & Versions
iOS: Overview, Architecture, Development & Versions iOS: Overview, Architecture, Development & Versions
iOS: Overview, Architecture, Development & Versions Sandra Kerbage
 
[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS Programming[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS ProgrammingNikmesoft Ltd
 
iOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersiOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersRyanISI
 
Pentesting iOS Applications
Pentesting iOS ApplicationsPentesting iOS Applications
Pentesting iOS Applicationsjasonhaddix
 
[iOS] Basic UI Elements
[iOS] Basic UI Elements[iOS] Basic UI Elements
[iOS] Basic UI ElementsNikmesoft Ltd
 

Andere mochten auch (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
 

Ähnlich wie [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
 
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 2014DTU 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 iOSKenny Nguyen
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity FrameworkMahmoud 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 ArchitectureDATAVERSITY
 
Ado.net session01
Ado.net session01Ado.net session01
Ado.net session01Niit Care
 
Guidelines data cite_denmark_ver3
Guidelines data cite_denmark_ver3Guidelines data cite_denmark_ver3
Guidelines data cite_denmark_ver3DTU Library
 
Guidelines data cite_denmark_ver2
Guidelines data cite_denmark_ver2Guidelines data cite_denmark_ver2
Guidelines data cite_denmark_ver2DTU 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 GroupShahzad
 
Hibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ NizampetHibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ NizampetJayarajus
 
Domain Driven Design for Angular
Domain Driven Design for AngularDomain Driven Design for Angular
Domain Driven Design for AngularJennifer Estrada
 
Nhibernate Part 1
Nhibernate   Part 1Nhibernate   Part 1
Nhibernate Part 1guest075fec
 
2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.pptChadharris42
 

Ähnlich wie [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_ver3
Guidelines data cite_denmark_ver3Guidelines data cite_denmark_ver3
Guidelines data cite_denmark_ver3
 
Guidelines data cite_denmark_ver2
Guidelines data cite_denmark_ver2Guidelines data cite_denmark_ver2
Guidelines data cite_denmark_ver2
 
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
 

Mehr von Nikmesoft Ltd

[Android] Multimedia Programming
[Android] Multimedia Programming[Android] Multimedia Programming
[Android] Multimedia ProgrammingNikmesoft Ltd
 
[Android] Android Animation
[Android] Android Animation[Android] Android Animation
[Android] Android AnimationNikmesoft Ltd
 
[Android] 2D Graphics
[Android] 2D Graphics[Android] 2D Graphics
[Android] 2D GraphicsNikmesoft Ltd
 
[Android] Services and Broadcast Receivers
[Android] Services and Broadcast Receivers[Android] Services and Broadcast Receivers
[Android] Services and Broadcast ReceiversNikmesoft Ltd
 
[Android] Web services
[Android] Web services[Android] Web services
[Android] Web servicesNikmesoft Ltd
 
[Android] Multiple Background Threads
[Android] Multiple Background Threads[Android] Multiple Background Threads
[Android] Multiple Background ThreadsNikmesoft 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 ServicesNikmesoft Ltd
 
[Android] Data Storage
[Android] Data Storage[Android] Data Storage
[Android] Data StorageNikmesoft Ltd
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and ActivityNikmesoft Ltd
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event HandlingNikmesoft Ltd
 
[Android] Using Selection Widgets
[Android] Using Selection Widgets[Android] Using Selection Widgets
[Android] Using Selection WidgetsNikmesoft Ltd
 
[Android] Basic Widgets and Containers
[Android] Basic Widgets and Containers[Android] Basic Widgets and Containers
[Android] Basic Widgets and ContainersNikmesoft Ltd
 
[Android] Introduction to Android Programming
[Android] Introduction to Android Programming[Android] Introduction to Android Programming
[Android] Introduction to Android ProgrammingNikmesoft Ltd
 

Mehr von 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
 

Kürzlich hochgeladen

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Kürzlich hochgeladen (20)

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

[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