10

I'm doing design for a project and nothing's been implemented - so I'm still going through the thought process to determine if Core Data is viable for the project.

Here's my query -

I want to create a managed object model using Core Data to represent some server side objects e.g Folder, File, etc.... All the objects (Folder, File etc..) are accessible via XMLRPC APIs that return some well formed XML.

For example, there may be an API called getFolders that can return the following -

<xml>
 <folders>
  <folder id=1>
    <name>Test 123</name>
   <files>
      <file id=100>
           <name>hello.txt</name>
          <path>./hello.txt</path>
      </file>
      ...
  </files>
 </folder>
 ...
</folders>

Similarly there can be an updateFolders API that operates on an existing folder item and for simplicity lets say it just updates the folder name. The request for it would post something like the following -

<xml>
 <method name="updateFolder">
  <folder_id="1">
  <params>
   <param name="folder_name" value="Test"/>
  </params>
 </method>

I'm trying to figure out -

  1. How can I represent folder as a managed object i.e., how do I initialize it from the above XML
  2. Once initialized, how can I handle an update to it using the updateFolder API shown above

It seems like the NSPersistentStore such as XMLStoreType point directly to actual XML files that hold the final data. In my case, the XML is simply whats returned from an XMLRPC call and the actual data is stored on a server side DB. Therefore, since the stores are not direct representations of the objects (or where the objects are stored), I was wondering if I should create a custom NSAtomicStore and handle load and save for initialization and update respectively. Here's a link on doing this for a NSAtomicStore -

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/AtomicStore_Concepts/Articles/asLoading.html#//apple_ref/doc/uid/TP40005298

Please let me know if this makes sense or if there's a better way to handle this.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Srinivas
  • 101
  • 4

2 Answers2

1

Have you read through:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

Also check out TBXML:

TBXML is a light-weight XML document parser written in Objective-C designed for use on Apple iPad, iPhone & iPod Touch devices. TBXML aims to provide the fastest possible XML parsing whilst utilising the fewest resources. This requirement for absolute efficiency is achieved at the expense of XML validation and modification. It is not possible to modify and generate valid XML from a TBXML object and no validation is performed whatsoever whilst importing and parsing an XML document.

gotnull
  • 26,454
  • 22
  • 137
  • 203
0

There is no simple way to do what you ask and Core Data won't make it any easier for you.

I assume you've read the docs - you need to determine a suitable model to represent your remote data locally, manage the interactions between the remote end and the local end, and synchronize the state between the ends. Deciding on and coordinating your synchronization process is the hardest part. I'm not sure whether there is any third-party framework that can automate this process.

Nick Toumpelis
  • 2,717
  • 22
  • 38