Advertisement
Shrooms

Untitled

Nov 14th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. Core Data is an object design, management, and persistence framework.
  2.  
  3. A object graph is either an entity object (simple) or entity object collection (complex).
  4.  
  5. In our apps, we are always using objects and collections of objects, in memory.
  6.  
  7. An important component is the stack, which has the code that sets up and configures Core Data for the app. Most of this code is static, and will not need changes or editing.
  8.  
  9. One of the important objects that gets configured is the context (or more fully, the managed object context). We use the context everywhere in our app (data model manager, controllers). It is a work area for objects that are in memory.
  10.  
  11. 1. The context supports typical operations like fetch (from the persistent store), add new (programmatically), edit existing, and delete item.
  12.  
  13.  
  14. Data to-and-from the Core Data store is done with fetch request objects. Conceptually, they’re similar to the recently learned web API request objects, in that they enable data service operations (e.g. fetch, add, change, etc.).
  15.  
  16. let fetchRequest: NSFetchRequest<Person> = Person.fetchRequest()
  17. to perform fetch its context.fetch(fetchRequest)
  18.  
  19. A fetch request will return a typed array of results.
  20.  
  21. to save, its context.save()
  22.  
  23. Finally, when we’re working with a table view controller, we use a wrapper around a fetch request, known as a fetched results controller.
  24.  
  25. Core Data is like a database 
  26.  
  27. 1. In an app, the presence of a Core Data “stack” enables the app to use Core Data technology.
  28.  
  29. 1. A Core Data model editor is used to define entities and their attributes, and relationships among entities.
  30. 2. To execute/run the request, use the context’s fetch() method, and assign the results to a variable.
  31. 3. A predicate is an object (in Swift) that enables a developer to filter or constrain the selection, if desired.
  32. 4. A predicate has two important parts, that can be thought of as a conditional statement that you would have anywhere (as in an if statment). The first part is the predicate string, and the other is the argument(s).
  33.  
  34. 1. The NSPredicate class is used to create a predicate.
  35.  
  36. 1. A sort descriptor is an object (in Swift) that enables a developer to order or sequence the selection, if desired.
  37.  
  38. so a fetch request has a predicate and sort descriptor.
  39.  
  40. fetch is default for all.
  41.  
  42. use predicate and sort descriptor to get selective shit.
  43.  
  44. fetchresultcontroller is used if you need to edit data, remove data, grouped items, and if lists content is dynamic.
  45.  
  46. u got to initialize frc, set delegate, and use .performFetch()
  47.  
  48. has fetchedObjects.count
  49.  
  50. use frc.object(at: index)
  51.  
  52. let fetchRequest: NSFetchRequest<Person> = Person.fetchRequest()
  53.  
  54. // Filter the results
  55. fetchRequest.predicate = NSPredicate(format: "age < 25", argumentArray: nil)
  56.  
  57. // Sort the results
  58. fetchRequest.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]
  59.  
  60. do {
  61. let results = try m.ds_context.fetch(fetchRequest)
  62. // Handle the results
  63. } catch let error {
  64. print(error.localizedDescription)
  65. }
  66.  
  67. * CDStack

  68. * Core Data Stack; setup for all objects that activate core data

  69. * Has a save method and a factory method

  70. * Says “make a connection to the file system” 

  71. * No need to edit this really! 

  72. YOU TECHNICALLY DO NOT NEED A CDSTACK SWIFT FILE but it is a template for
  73.  
  74. StoreInitliazer a swift file aka template that simply loads data into core data store
  75.  
  76. in model editor, u can see uml diagram of relationships between entities
  77.  
  78. —————————————————
  79.  
  80. if a entity contains a collection of another entity, then u access by using a as Set<Entity>
  81.  
  82. entity class collections generates functions to add remove entity
  83.  
  84. extensions to a class is GAY AF but it could be used for tableviewcontroller with a nsfetchedresultscontrollerdelegate where it automatically updates tableviewcontroller list AUTOMATICALLY
  85.  
  86. The table view data source is a fetched results controller (frc).
  87.  
  88. so it all linked!
  89.  
  90. The “Core Location” kit provides services that determine a device’s geographic location, altitude, and orientation. The framework gathers data using all available components on the device, including Wi-Fi, GPS, Bluetooth, magnetometer, barometer, and cellular hardware.
  91.  
  92. The CLLocationManager class is used. We create an instance, then configure, start getting location info, and stop when appropriate.
  93.  
  94. First, the controller that uses location services must conform to the CLLocationManagerDelegateprotocol.
  95.  
  96. Then, a number of local instance variables should be declared and initialized, and they will hold location data as it is gathered and used.
  97. The request to get location data is usually wrapped by a function/method. It has a limited set of tasks to do:
  98. * Configure the location manager’s settings
  99. * Perform authorization tasks
  100. * Begin gathering location data
  101. A number of delegate methods must be implemented to handle events that arise during authorization and then during the gathering of location data.
  102. * Authorization problems
  103. * Get location failure
  104. * Get a suitable location piece of data, then stop gathering any more location data
  105. How you use the data is up to you. The code example does a reverse geocoding task, using an Apple service, and will attempt to report a street address for the current location. Future code examples will use maps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement