SlideShare a Scribd company logo
Core Data Optimization
Gagan Vishal Mishra
Memory Vs. Performance
Core Data Optimization
2
Memory
Speed
Less More
Slow Faster
Memory Vs. Performance
Core Data Optimization
3
Memory
Speed
Less More
Slow Faster
Thread Safety In Core Data
Core Data Optimization
4
• While working with Core Data, it's important to always remember that Core Data isn't
thread safe. Core Data expects to be run on a single thread.
• NSManagedObject, NSManagedObjectContext NSPersistentStoreCoordinator aren't
thread safe.
• This doesn't mean that every Core Data operation needs to be performed on the
main thread, which is used for UI, but it means that we need to take care which
operations are executed on which threads. We have to be careful how changes from
one thread are propagated to other threads.
Thread Safety In Core Data
Core Data Optimization
5
1. NSManagedObject: NSManagedObject isn't thread safe but has an
instance objectID that returns an instance of the NSManagedObjectID class which
is thread safe. For getting
do {
let managedObject = try managedObjectContext.existingObjectWithID(objectID)
} catch let fetchError as NSError { print("(fetchError), (fetchError.userInfo)”) }
2. NSManagedObjectContext: Isn't thread safe, we can create a managed object
context for every thread that interacts with Core Data. This strategy is referred
as thread confinement. A common approach is to create thread dictionary to store
MOC.
let currentThread = NSThread.currentThread()
currentThread.threadDictionary.setObject(managedObjectContext, forKey:
"managedObjectContext")
3. NSPersistentStoreCoordinator: We can create a separate persistent store
coordinator for every thread. Which is also possible.
Multithreading & Concurrency Strategies
Core Data Optimization
6
The NSPersistentStoreCoordinator class was designed to support multiple managed
object contexts, even if those managed object contexts were created on different
threads. Because the NSManagedObjectContext class locks the persistent store
coordinator while accessing it, it is possible for multiple managed object contexts to use
the same persistent store coordinator even if those managed object contexts live on
different threads. This makes a multithreaded Core Data setup much more manageable
and less complex.
There are two ways for Core Data Concurrency
1.Notifications
2.Parent/Child Managed Object Contexts
Another option is
1.Independent Persistent Store Built with Notification & PrivateQueue
Multithreading & Concurrency Strategies
Core Data Optimization
7
There are three types of Concurrency options provided by Apple
1.MainQueueConcurrencyType: The managed object context is only accessible from
the main thread. An exception is thrown if you try to access it from any other thread.
1.PrivateQueueConcurrencyType: When creating a managed object context with a
concurrency type of PrivateQueueConcurrencyType, the managed object context is
associated with a private queue and it can only be accessed from that private queue.
2.ConfinementConcurrencyType: Apple has deprecated this concurrency type as of
iOS 9. This is the concurrency type that corresponds with the thread
confinement concept . If you create a managed object context using init(), the
concurrency type of that managed object context is ConfinementConcurrencyType.
Fetching
Core Data Optimization
8
1. Use fetchBatchSize:
• This breaks the result set into batches. The entire request will be evaluated,
and the identities of all matching objects will be recorded, but no more than
batchSize objects' data will be fetched from the persistent store at a time.
• A batch size of 0 is treated as infinite, which disables the batch faulting
behavior.
let fetchRequest = NSFetchRequest(entityName: "DataEntity")
fetchRequest.sortDescriptors = [NSSortDescriptor(key:
UFO_KEY_COREDATA_SIGHTED, ascending: false)]
fetchRequest.fetchBatchSize = 20 //Set number double to visible cells
do
{
let test = try self.managedObjectContext.executeFetchRequest(fetchRequest) as Array
print("test count is: (test.count)")
}
catch let error as NSError
{
print("Error is : (error.localizedDescription)")
}
Fetching
Core Data Optimization
9
2. Use resultType: There are four types of result type
• ManagedObjectResultType
• ManagedObjectIDResultType
• DictionaryResultType
• CountResultType
let fetchRequest = NSFetchRequest(entityName: "DataEntity")
fetchRequest.resultType = .DictionaryResultType
do
{
let arrayOfFoundRecords = try
objAppDel.tempManagedObjectContext.executeFetchRequest(fetchRequest
}
catch let error as NSError
{
print("error in fetch is : (error.localizedDescription)")
}
Fetching
Core Data Optimization
10
3. Use NSExpressionDescription & NSExpression : Instances of
NSExpressionDescription objects represent a special property description type
intended for use with the NSFetchRequest PropertiesToFetch method. An
NSExpressionDescription describes a column to be returned from a fetch that may
not appear directly as an attribute or relationship on an entity. NSExpression is used
to represent expressions in a predicate. Comparison operations in an NSPredicate
are based on two expressions, as represented by instances of the NSExpression
class. Expressions are created for constant values, key paths etc.
//Create a expression
let expressionDescription = NSExpressionDescription()
expressionDescription.name = "count"
expressionDescription.expression = NSExpression(forFunction: "count:", arguments:
[NSExpression(forKeyPath: "shape")])
//Create a fetch Request
let fetchRequest = NSFetchRequest(entityName: "DataEntity")
Fetching
Core Data Optimization
11
3. Use GroupBy: Use groupBy to aggregate for same column name.
let fetchRequest = NSFetchRequest(entityName: "DataEntity")
fetchRequest.propertiesToGroupBy = ["shape"]
4. Use propertiesToFetch: create an array of properties you want to fetch from
CoreData.
let expressionDescription = NSExpressionDescription()
expressionDescription.name = "count”
expressionDescription.expression = NSExpression(forFunction: "count:", arguments:
[NSExpression(forKeyPath: "shape")])
//Create a fetch Request
let fetchRequest = NSFetchRequest(entityName: "DataEntity")
fetchRequest.propertiesToFetch = ["shape", expressionDescription]
Fetching
Core Data Optimization
12
5. PreFetch Any Required Relationship : Prefetching allows Core Data to obtain
developer-specified related objects in a single fetch.
let entityDescription = NSEntityDescription.entityForName("Employee",
inManagedObjectContext: self.managedObjectContext)
let fetchRequest = NSFetchRequest()
fetchRequest.entity = entityDescription
fetchRequest.relationshipKeyPathsForPrefetching = ["Department"]
do{
let arrayOfFoundRecords = try
self.managedObjectContext.executeFetchRequest(fetchRequest) as Array
for ( emp in arrayOfFoundRecords )
{
print("emp is: (emp)")
print("dept is: (emp.deptEmp)")
}
}
catch let error as NSError
{
}
Fetching
Core Data Optimization
13
Fetch Summary:
1.Don’t’ fetch anything that you don’t need.
2.Always use Batch Fetch.
3.Try to use NSExpressionDescription for Fetch in other word lets allow SQLite to do
calculation.
4.Use Prefeatch (relationshipKeyPathsForPrefetching) for required relationship.
Predicates:
Core Data Optimization
14
1. Light Predicate First: Always do String Comparison in last query. For example
fetchRequest.predicate = NSPredicate(format: "shape=%@ AND duration=%d", "circle", 30)
better way it to avoid string as much as possible or use string as a second argument.
So above code will perform better if we write it as:
fetchRequest.predicate = NSPredicate(format: "duration=%d shape=%@", 30, "circle”)
2. Use BeginsWith/EndsWith: Always try to use ‘beginsWith’ in creating a predicate.
Predicates:
Core Data Optimization
15
Predicate Summary & Cost Graph
1. Do light comparison first i.e. Numerical comparison.
2. Always try to use BeginsWith/EndsWith instead of Equals/Match.
3. Don’t/avoid to use CD in comparison.
Predicate
Cost
Less More
BeginsWith/
EndsWith
Equality
==
Contains
Matches
Search
Core Data Optimization
16
1. Always used Canonical String for search process. For example
String Canonical String
TEST test
åpple apple
Green Åpple green apple
2. Always use BeginsWith/EndsWith for searching.
Printing SQL Log
Core Data Optimization
17
Product menu by selecting “Manage Schemes” and then editing the current
scheme you are using. Select the “Run “phase and then select the “Arguments”
tab. Here you will see options to set arguments and environment variables. Add
-com.apple.CoreData.SQLDebug 3 to "Arguments Passed On Launch"
18
Thank you !

More Related Content

What's hot (17)

ODP
Sql installation
Balakumaran Arunachalam
 
PPTX
Nodejs Session01
Jainul Musani
 
DOC
( 15 ) Office 2007 Create A Membership Database
LiquidHub
 
PPTX
บทที่ 3 การเขียนโปรแกรมติดต่อฐานข้อมูล
Priew Chakrit
 
PPTX
ExpressJs Session01
Jainul Musani
 
DOCX
Oracle WebLogic
Anar Godjaev
 
PPTX
Mule esb :Data Weave
AnilKumar Etagowni
 
PDF
Tutorial windows service with java (procrun)
muhammad arif nasution
 
PDF
154090896 installation-of-oracle-database-12c
Venkatesh Ramiya Krishnamoorthy
 
DOCX
Dbm 438 week 6 ilab
MelissaHarrington321
 
PDF
Knowledge article
Deepanshu Tyagi
 
PDF
Oracle to MySQL DatabaseLink
Osama Mustafa
 
PDF
Why Task Queues - ComoRichWeb
Bryan Helmig
 
PPTX
Beginner guide to mysql command line
Priti Solanki
 
PPTX
PowerShell-2
Saravanan G
 
PPTX
NodeJs Session02
Jainul Musani
 
PDF
Dspace
Bibliounivbtn
 
Sql installation
Balakumaran Arunachalam
 
Nodejs Session01
Jainul Musani
 
( 15 ) Office 2007 Create A Membership Database
LiquidHub
 
บทที่ 3 การเขียนโปรแกรมติดต่อฐานข้อมูล
Priew Chakrit
 
ExpressJs Session01
Jainul Musani
 
Oracle WebLogic
Anar Godjaev
 
Mule esb :Data Weave
AnilKumar Etagowni
 
Tutorial windows service with java (procrun)
muhammad arif nasution
 
154090896 installation-of-oracle-database-12c
Venkatesh Ramiya Krishnamoorthy
 
Dbm 438 week 6 ilab
MelissaHarrington321
 
Knowledge article
Deepanshu Tyagi
 
Oracle to MySQL DatabaseLink
Osama Mustafa
 
Why Task Queues - ComoRichWeb
Bryan Helmig
 
Beginner guide to mysql command line
Priti Solanki
 
PowerShell-2
Saravanan G
 
NodeJs Session02
Jainul Musani
 

Similar to Core data optimization (20)

PPT
Connecting to a REST API in iOS
gillygize
 
PDF
Core Data with multiple managed object contexts
Matthew Morey
 
PDF
Intro to Core Data
Make School
 
PDF
Core Data with Swift 3.0
Korhan Bircan
 
KEY
iOSDevCamp 2011 Core Data
Chris Mar
 
PPT
Core data orlando i os dev group
Andrew Kozlik
 
PDF
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
smn-automate
 
PDF
Simpler Core Data with RubyMotion
Stefan Haflidason
 
DOC
EMF Tips n Tricks
Kaniska Mandal
 
DOC
Advanced Hibernate Notes
Kaniska Mandal
 
PDF
Share point 2013 coding standards and best practices 1.0
LiquidHub
 
PPT
Zend framework 03 - singleton factory data mapper caching logging
Tricode (part of Dept)
 
PPT
Session 5 Tp5
phanleson
 
KEY
Core Data
Robert Brown
 
PPT
EJB Clients
Roy Antony Arnold G
 
DOCX
Ruby on Rails Developer - Allerin
Lauree R
 
PDF
.NET Core, ASP.NET Core Course, Session 14
Amin Mesbahi
 
PDF
Data Binding in Silverlight
Boulos Dib
 
PPTX
Real World MVC
James Johnson
 
PDF
[2 d1] elasticsearch 성능 최적화
Henry Jeong
 
Connecting to a REST API in iOS
gillygize
 
Core Data with multiple managed object contexts
Matthew Morey
 
Intro to Core Data
Make School
 
Core Data with Swift 3.0
Korhan Bircan
 
iOSDevCamp 2011 Core Data
Chris Mar
 
Core data orlando i os dev group
Andrew Kozlik
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
smn-automate
 
Simpler Core Data with RubyMotion
Stefan Haflidason
 
EMF Tips n Tricks
Kaniska Mandal
 
Advanced Hibernate Notes
Kaniska Mandal
 
Share point 2013 coding standards and best practices 1.0
LiquidHub
 
Zend framework 03 - singleton factory data mapper caching logging
Tricode (part of Dept)
 
Session 5 Tp5
phanleson
 
Core Data
Robert Brown
 
EJB Clients
Roy Antony Arnold G
 
Ruby on Rails Developer - Allerin
Lauree R
 
.NET Core, ASP.NET Core Course, Session 14
Amin Mesbahi
 
Data Binding in Silverlight
Boulos Dib
 
Real World MVC
James Johnson
 
[2 d1] elasticsearch 성능 최적화
Henry Jeong
 
Ad

More from Gagan Vishal Mishra (8)

PPTX
iOS Versions history
Gagan Vishal Mishra
 
PPTX
Jenkins CI/CD setup for iOS in Mac OSX
Gagan Vishal Mishra
 
PPTX
Linking between JIRA & GIT, Smart Commit Command
Gagan Vishal Mishra
 
PPTX
Dynamic databinding
Gagan Vishal Mishra
 
PPTX
Visual Formatting Language in iOS
Gagan Vishal Mishra
 
PPTX
Search API
Gagan Vishal Mishra
 
PPTX
IBDesignable & IBInspectible
Gagan Vishal Mishra
 
PPTX
Core Data Performance Guide Line
Gagan Vishal Mishra
 
iOS Versions history
Gagan Vishal Mishra
 
Jenkins CI/CD setup for iOS in Mac OSX
Gagan Vishal Mishra
 
Linking between JIRA & GIT, Smart Commit Command
Gagan Vishal Mishra
 
Dynamic databinding
Gagan Vishal Mishra
 
Visual Formatting Language in iOS
Gagan Vishal Mishra
 
IBDesignable & IBInspectible
Gagan Vishal Mishra
 
Core Data Performance Guide Line
Gagan Vishal Mishra
 
Ad

Recently uploaded (20)

PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
July Patch Tuesday
Ivanti
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
July Patch Tuesday
Ivanti
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 

Core data optimization

  • 2. Memory Vs. Performance Core Data Optimization 2 Memory Speed Less More Slow Faster
  • 3. Memory Vs. Performance Core Data Optimization 3 Memory Speed Less More Slow Faster
  • 4. Thread Safety In Core Data Core Data Optimization 4 • While working with Core Data, it's important to always remember that Core Data isn't thread safe. Core Data expects to be run on a single thread. • NSManagedObject, NSManagedObjectContext NSPersistentStoreCoordinator aren't thread safe. • This doesn't mean that every Core Data operation needs to be performed on the main thread, which is used for UI, but it means that we need to take care which operations are executed on which threads. We have to be careful how changes from one thread are propagated to other threads.
  • 5. Thread Safety In Core Data Core Data Optimization 5 1. NSManagedObject: NSManagedObject isn't thread safe but has an instance objectID that returns an instance of the NSManagedObjectID class which is thread safe. For getting do { let managedObject = try managedObjectContext.existingObjectWithID(objectID) } catch let fetchError as NSError { print("(fetchError), (fetchError.userInfo)”) } 2. NSManagedObjectContext: Isn't thread safe, we can create a managed object context for every thread that interacts with Core Data. This strategy is referred as thread confinement. A common approach is to create thread dictionary to store MOC. let currentThread = NSThread.currentThread() currentThread.threadDictionary.setObject(managedObjectContext, forKey: "managedObjectContext") 3. NSPersistentStoreCoordinator: We can create a separate persistent store coordinator for every thread. Which is also possible.
  • 6. Multithreading & Concurrency Strategies Core Data Optimization 6 The NSPersistentStoreCoordinator class was designed to support multiple managed object contexts, even if those managed object contexts were created on different threads. Because the NSManagedObjectContext class locks the persistent store coordinator while accessing it, it is possible for multiple managed object contexts to use the same persistent store coordinator even if those managed object contexts live on different threads. This makes a multithreaded Core Data setup much more manageable and less complex. There are two ways for Core Data Concurrency 1.Notifications 2.Parent/Child Managed Object Contexts Another option is 1.Independent Persistent Store Built with Notification & PrivateQueue
  • 7. Multithreading & Concurrency Strategies Core Data Optimization 7 There are three types of Concurrency options provided by Apple 1.MainQueueConcurrencyType: The managed object context is only accessible from the main thread. An exception is thrown if you try to access it from any other thread. 1.PrivateQueueConcurrencyType: When creating a managed object context with a concurrency type of PrivateQueueConcurrencyType, the managed object context is associated with a private queue and it can only be accessed from that private queue. 2.ConfinementConcurrencyType: Apple has deprecated this concurrency type as of iOS 9. This is the concurrency type that corresponds with the thread confinement concept . If you create a managed object context using init(), the concurrency type of that managed object context is ConfinementConcurrencyType.
  • 8. Fetching Core Data Optimization 8 1. Use fetchBatchSize: • This breaks the result set into batches. The entire request will be evaluated, and the identities of all matching objects will be recorded, but no more than batchSize objects' data will be fetched from the persistent store at a time. • A batch size of 0 is treated as infinite, which disables the batch faulting behavior. let fetchRequest = NSFetchRequest(entityName: "DataEntity") fetchRequest.sortDescriptors = [NSSortDescriptor(key: UFO_KEY_COREDATA_SIGHTED, ascending: false)] fetchRequest.fetchBatchSize = 20 //Set number double to visible cells do { let test = try self.managedObjectContext.executeFetchRequest(fetchRequest) as Array print("test count is: (test.count)") } catch let error as NSError { print("Error is : (error.localizedDescription)") }
  • 9. Fetching Core Data Optimization 9 2. Use resultType: There are four types of result type • ManagedObjectResultType • ManagedObjectIDResultType • DictionaryResultType • CountResultType let fetchRequest = NSFetchRequest(entityName: "DataEntity") fetchRequest.resultType = .DictionaryResultType do { let arrayOfFoundRecords = try objAppDel.tempManagedObjectContext.executeFetchRequest(fetchRequest } catch let error as NSError { print("error in fetch is : (error.localizedDescription)") }
  • 10. Fetching Core Data Optimization 10 3. Use NSExpressionDescription & NSExpression : Instances of NSExpressionDescription objects represent a special property description type intended for use with the NSFetchRequest PropertiesToFetch method. An NSExpressionDescription describes a column to be returned from a fetch that may not appear directly as an attribute or relationship on an entity. NSExpression is used to represent expressions in a predicate. Comparison operations in an NSPredicate are based on two expressions, as represented by instances of the NSExpression class. Expressions are created for constant values, key paths etc. //Create a expression let expressionDescription = NSExpressionDescription() expressionDescription.name = "count" expressionDescription.expression = NSExpression(forFunction: "count:", arguments: [NSExpression(forKeyPath: "shape")]) //Create a fetch Request let fetchRequest = NSFetchRequest(entityName: "DataEntity")
  • 11. Fetching Core Data Optimization 11 3. Use GroupBy: Use groupBy to aggregate for same column name. let fetchRequest = NSFetchRequest(entityName: "DataEntity") fetchRequest.propertiesToGroupBy = ["shape"] 4. Use propertiesToFetch: create an array of properties you want to fetch from CoreData. let expressionDescription = NSExpressionDescription() expressionDescription.name = "count” expressionDescription.expression = NSExpression(forFunction: "count:", arguments: [NSExpression(forKeyPath: "shape")]) //Create a fetch Request let fetchRequest = NSFetchRequest(entityName: "DataEntity") fetchRequest.propertiesToFetch = ["shape", expressionDescription]
  • 12. Fetching Core Data Optimization 12 5. PreFetch Any Required Relationship : Prefetching allows Core Data to obtain developer-specified related objects in a single fetch. let entityDescription = NSEntityDescription.entityForName("Employee", inManagedObjectContext: self.managedObjectContext) let fetchRequest = NSFetchRequest() fetchRequest.entity = entityDescription fetchRequest.relationshipKeyPathsForPrefetching = ["Department"] do{ let arrayOfFoundRecords = try self.managedObjectContext.executeFetchRequest(fetchRequest) as Array for ( emp in arrayOfFoundRecords ) { print("emp is: (emp)") print("dept is: (emp.deptEmp)") } } catch let error as NSError { }
  • 13. Fetching Core Data Optimization 13 Fetch Summary: 1.Don’t’ fetch anything that you don’t need. 2.Always use Batch Fetch. 3.Try to use NSExpressionDescription for Fetch in other word lets allow SQLite to do calculation. 4.Use Prefeatch (relationshipKeyPathsForPrefetching) for required relationship.
  • 14. Predicates: Core Data Optimization 14 1. Light Predicate First: Always do String Comparison in last query. For example fetchRequest.predicate = NSPredicate(format: "shape=%@ AND duration=%d", "circle", 30) better way it to avoid string as much as possible or use string as a second argument. So above code will perform better if we write it as: fetchRequest.predicate = NSPredicate(format: "duration=%d shape=%@", 30, "circle”) 2. Use BeginsWith/EndsWith: Always try to use ‘beginsWith’ in creating a predicate.
  • 15. Predicates: Core Data Optimization 15 Predicate Summary & Cost Graph 1. Do light comparison first i.e. Numerical comparison. 2. Always try to use BeginsWith/EndsWith instead of Equals/Match. 3. Don’t/avoid to use CD in comparison. Predicate Cost Less More BeginsWith/ EndsWith Equality == Contains Matches
  • 16. Search Core Data Optimization 16 1. Always used Canonical String for search process. For example String Canonical String TEST test åpple apple Green Åpple green apple 2. Always use BeginsWith/EndsWith for searching.
  • 17. Printing SQL Log Core Data Optimization 17 Product menu by selecting “Manage Schemes” and then editing the current scheme you are using. Select the “Run “phase and then select the “Arguments” tab. Here you will see options to set arguments and environment variables. Add -com.apple.CoreData.SQLDebug 3 to "Arguments Passed On Launch"

Editor's Notes

  • #10: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/
  • #11: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/
  • #12: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/
  • #13: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/
  • #14: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/
  • #15: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/
  • #16: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/
  • #17: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/
  • #18: http://www.cimgf.com/2015/06/25/core-data-and-aggregate-fetches-in-swift/ https://www.bignerdranch.com/blog/new-in-core-data-and-ios-8-batch-updating/