nano-store 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.gitignore +1 -0
  2. data/.gitmodules +0 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +24 -0
  5. data/README.md +5 -0
  6. data/Rakefile +21 -1
  7. data/lib/nano_store.rb +2 -0
  8. data/lib/nano_store/finder.rb +76 -0
  9. data/lib/nano_store/model.rb +1 -32
  10. data/lib/nano_store/version.rb +1 -1
  11. data/nano-store.gemspec +1 -0
  12. data/spec/finder_spec.rb +67 -0
  13. data/spec/model_spec.rb +0 -30
  14. data/vendor/Podfile.lock +5 -0
  15. data/vendor/Pods/Headers/NanoStore/NSFNanoBag.h +306 -0
  16. data/vendor/Pods/Headers/NanoStore/NSFNanoBag_Private.h +37 -0
  17. data/vendor/Pods/Headers/NanoStore/NSFNanoEngine.h +542 -0
  18. data/vendor/Pods/Headers/NanoStore/NSFNanoEngine_Private.h +69 -0
  19. data/vendor/Pods/Headers/NanoStore/NSFNanoExpression.h +125 -0
  20. data/vendor/Pods/Headers/NanoStore/NSFNanoExpression_Private.h +35 -0
  21. data/vendor/Pods/Headers/NanoStore/NSFNanoGlobals.h +323 -0
  22. data/vendor/Pods/Headers/NanoStore/NSFNanoGlobals_Private.h +99 -0
  23. data/vendor/Pods/Headers/NanoStore/NSFNanoObject.h +298 -0
  24. data/vendor/Pods/Headers/NanoStore/NSFNanoObjectProtocol.h +119 -0
  25. data/vendor/Pods/Headers/NanoStore/NSFNanoObject_Private.h +35 -0
  26. data/vendor/Pods/Headers/NanoStore/NSFNanoPredicate.h +123 -0
  27. data/vendor/Pods/Headers/NanoStore/NSFNanoPredicate_Private.h +35 -0
  28. data/vendor/Pods/Headers/NanoStore/NSFNanoResult.h +137 -0
  29. data/vendor/Pods/Headers/NanoStore/NSFNanoResult_Private.h +43 -0
  30. data/vendor/Pods/Headers/NanoStore/NSFNanoSearch.h +381 -0
  31. data/vendor/Pods/Headers/NanoStore/NSFNanoSearch_Private.h +48 -0
  32. data/vendor/Pods/Headers/NanoStore/NSFNanoSortDescriptor.h +124 -0
  33. data/vendor/Pods/Headers/NanoStore/NSFNanoStore.h +475 -0
  34. data/vendor/Pods/Headers/NanoStore/NSFNanoStore_Private.h +57 -0
  35. data/vendor/Pods/Headers/NanoStore/NanoStore.h +463 -0
  36. data/vendor/Pods/Headers/NanoStore/NanoStore_Private.h +37 -0
  37. data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoEngine.h +542 -0
  38. data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoEngine.m +1781 -0
  39. data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.h +137 -0
  40. data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.m +265 -0
  41. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoBag_Private.h +37 -0
  42. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoEngine_Private.h +69 -0
  43. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoExpression_Private.h +35 -0
  44. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoGlobals_Private.h +99 -0
  45. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoObject_Private.h +35 -0
  46. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoPredicate_Private.h +35 -0
  47. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoResult_Private.h +43 -0
  48. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoSearch_Private.h +48 -0
  49. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoStore_Private.h +57 -0
  50. data/vendor/Pods/NanoStore/Classes/Private/NanoStore_Private.h +37 -0
  51. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoBag.h +306 -0
  52. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoBag.m +485 -0
  53. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.h +125 -0
  54. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.m +103 -0
  55. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.h +323 -0
  56. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.m +145 -0
  57. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObject.h +298 -0
  58. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObject.m +187 -0
  59. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObjectProtocol.h +119 -0
  60. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.h +123 -0
  61. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.m +130 -0
  62. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.h +381 -0
  63. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.m +859 -0
  64. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +124 -0
  65. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +79 -0
  66. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoStore.h +475 -0
  67. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoStore.m +1375 -0
  68. data/vendor/Pods/NanoStore/Classes/Public/NanoStore.h +463 -0
  69. data/vendor/Pods/NanoStore/LICENSE +25 -0
  70. data/vendor/Pods/NanoStore/README.md +411 -0
  71. data/vendor/Pods/Pods-prefix.pch +3 -0
  72. data/vendor/Pods/Pods-resources.sh +15 -0
  73. data/vendor/Pods/Pods.bridgesupport +1215 -0
  74. data/vendor/Pods/Pods.xcconfig +4 -0
  75. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +974 -0
  76. metadata +89 -6
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2010, Tito Ciuro, Webbo, L.L.C. All rights reserved.
2
+ Redistribution and use in source and binary forms, with or without
3
+ modification, are permitted provided that the following conditions are met:
4
+
5
+ * Redistributions of source code must retain the above copyright notice, this
6
+ list of conditions and the following disclaimer.
7
+ * Redistributions in binary form must reproduce the above copyright notice,
8
+ this list of conditions and the following disclaimer in the documentation
9
+ and/or other materials provided with the distribution.
10
+ * Neither the name of Tito Ciuro, Webbo, L.L.C. nor the names of its
11
+ contributors may be used to endorse or promote products derived from this
12
+ software without specific prior written permission.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22
+ AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
24
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25
+ DAMAGE.
@@ -0,0 +1,411 @@
1
+ # Welcome To NanoStore
2
+
3
+ **What is NanoStore?**
4
+
5
+ NanoStore is an open source, lightweight schema-less local key-value document store written in Objective-C for Mac OS X and iOS.
6
+
7
+ Relational databases tend to have a rich understanding of the structure of your data, but requires some planing beforehand and some level of maintenance as well. NanoStore provides the flexibility that comes with key-value document stores, but still understands something about your data. Because the data is key-value based, it can be accessed quickly and can grow as much as needed... all without ever worrying about the schema.
8
+
9
+ **Main advantages**
10
+
11
+ * No SQL knowledge required
12
+ * Schema-less
13
+ * Key-value based storage
14
+ * Store your own custom objects
15
+ * Bags, a free-form relational system
16
+ * Fast, direct object manipulation
17
+ * Dynamic queries
18
+ * Full index support, inner-objects, embedded arrays and dictionaries
19
+ * Convenience methods to access, manipulate and maintain SQLite databases
20
+ * Full SQLite access available
21
+ * Mac OS X Lion 10.7 and iOS 5 ready
22
+ * iOS library runs on the device and simulator
23
+ * ARC compliant
24
+
25
+ # Installation
26
+
27
+ Building NanoStore is very easy. Just follow these steps:
28
+
29
+ 1) Download NanoStore
30
+ 2) Open the NanoStore.xcodeproj file
31
+ 3) Select Universal > My Mac 64-bit or 32-bit from the Scheme popup
32
+ 4) Build (Command-B)
33
+
34
+ Now you should have a new ***Distribution*** directory within the NanoStore project directory which contains the Universal static library (armv6/armv7/i386) as well as the header files. To add it in your project, do the following:
35
+
36
+ 1) Drag the Distribution directory to the Project Navigator panel
37
+ 2) Include #import "NanoStore.h" in your code
38
+
39
+ Example:
40
+
41
+ #import "NanoStore.h"
42
+
43
+ @implementation MyDemoAppDelegate
44
+
45
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
46
+ {
47
+ // Override point for customization after application launch.
48
+ // Instantiate a NanoStore and open it
49
+
50
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
51
+ ...
52
+
53
+ ### Note
54
+ If you want to add a dependency between your project and NanoStore so that it gets automatically rebuilt when
55
+ you update NanoStore, do the following (we'll assume your app is called "MyDemoApp"):
56
+
57
+ 1) Select the MyDemoApp project in the Project Navigator
58
+ 2) Select the MyDemoApp target
59
+ 3) Expand the Target Dependencies box
60
+ 4) Click "+" and add NanoStore
61
+
62
+ # How does NanoStore work?
63
+
64
+ The basic unit of data in NanoStore is called NanoObject. A NanoObject is any object which conforms to the `NSFNanoObjectProtocol` protocol.
65
+
66
+ At its core, a NanoObject is nothing more than a wrapper around two properties:
67
+
68
+ * A dictionary which contains the metadata (provided by the developer)
69
+ * A key (UUID) that identifies the object (provided by NanoStore)
70
+
71
+ The dictionary must be serializable, which means that only the following data types are allowed:
72
+
73
+ * NSArray
74
+ * NSDictionary
75
+ * NSString
76
+ * NSData (*)
77
+ * NSDate
78
+ * NSNumber
79
+
80
+ ### Note
81
+ (*) The data type NSData is allowed, but it will be excluded from the indexing process.
82
+
83
+ To save and retrieve objects from the document store, NanoStore moves the data around by encapsulating it in NanoObjects. In order to store the objects in NanoStore the developer has three options:
84
+
85
+ * Use the `NSFNanoObject` class directly
86
+ * Expand your custom classes by inheriting from `NSFNanoObject`
87
+ * Expand your custom classes by implementing the `NSFNanoObjectProtocol` protocol
88
+
89
+ Regardless of the route you decide to take, NanoStore will be able to store and retrieve objects from the document store seamlessly. The beauty of this system is that NanoStore returns the object as it was stored, that is, instantiating an object of the class that was originally stored.
90
+
91
+ ### Note
92
+ If the document store is opened by another application that doesn't implement the object that was stored, NanoStore
93
+ will instantiate a NSFNanoObject instead, thus allowing the app to retrieve the data seamlessly. If the object is then
94
+ updated by this application, the original class name will be honored.
95
+
96
+ ### Example
97
+ App A stores an object of class Car.
98
+ App B retrieves the object, but since it doesn't know anything about the class Car, NanoStore returns a NSFNanoObject.
99
+ App B updates the object, with additional information. NanoStore saves it as a Car, not as a NSFNanoObject.
100
+ App A retrieves the updated object as a Car object, in exactly the same format as it was originally stored.
101
+
102
+ # Types of Document Stores
103
+
104
+ There are three types of document stores available in NanoStore: in-memory, temporary and file-based. These document stores are defined by the `NSFNanoStoreType` type:
105
+
106
+ `NSFMemoryStoreType`
107
+
108
+ Create the transient backing store in RAM. Its contents are lost when the process exits. Fastest, uses more RAM (*).
109
+
110
+ `NSFTemporaryStoreType`
111
+
112
+ Create a transient temporary backing store on disk. Its contents are lost when the process exits. Slower, uses less
113
+ RAM than NSFMemoryStoreType.
114
+
115
+ `NSFPersistentStoreType`
116
+
117
+ Create a persistent backing store on disk. Slower, uses less RAM than NSFMemoryStoreType (*).
118
+
119
+ ### Note
120
+ Until the limit set by NSFNanoEngine's - (NSUInteger)cacheSize has been reached, memory usage would be the same for
121
+ in-memory and on-disk stores. When the size of the store grows beyond - (NSUInteger)cacheSize in-memory stores start to
122
+ consume more memory than on-disk ones, because it has nowhere to push pages out of the cache.
123
+
124
+ Typically, most developers may want to create and open the document store. To do that, use the following method:
125
+
126
+ + (NSFNanoStore *)createAndOpenStoreWithType:(NSFNanoStoreType)aType path:(NSString *)aPath error:(out NSError **)outError
127
+
128
+ ### Example
129
+ // Instantiate an in-memory document store and open it. The path parameter is unused.
130
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
131
+
132
+ // Instantiate a temporary document store and open it. The path parameter is unused.
133
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFTemporaryStoreType path:nil error:nil];
134
+
135
+ // Instantiate a file-based document store and open it. The path parameter must be specified.
136
+ NSString *thePath = @"~/Desktop/myDatabase.database";
137
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFPersistentStoreType path:thePath error:nil];
138
+
139
+ ### Note
140
+ In the case of file-based document stores, the file gets created automatically if it doesn't exist and then opened. If
141
+ it already exists, it gets opened and made available for use right away. There are instances where you may want to
142
+ fine-tune the engine. Tuning the engine has to be performed before the document store is opened. Another method is
143
+ available in NSFNanoStore for this purpose:
144
+
145
+ + (NSFNanoStore *)createStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath.
146
+
147
+ ### Example
148
+ // Instantiate a file-based document store but don't open it right away. The path parameter must be specified.
149
+ NSString *thePath = @"~/Desktop/myDatabase.database";
150
+ NSFNanoStore *nanoStore = [NSFNanoStore createStoreWithType:NSFPersistentStoreType path:thePath error:nil];
151
+
152
+ // Obtain the engine
153
+ NSFNanoEngine *nanoStoreEngine = [nanoStore nanoStoreEngine];
154
+
155
+ // Set the synchronous mode setting
156
+ [nanoStoreEngine setSynchronousMode:SynchronousModeOff];
157
+ [nanoStoreEngine setEncodingType:NSFEncodingUTF16];
158
+
159
+ // Open the document store
160
+ [nanoStore openWithError:nil];
161
+
162
+ ### Note
163
+ Check the section Performance Tips below for important information about how to get the most out of NanoStore.
164
+
165
+ # Working with a NanoObject
166
+
167
+ There are three basic operations that NanoStore can perform with a NanoObject:
168
+
169
+ * Add it to the document store
170
+ * Update an existing object in the document store
171
+ * Remove it from the document store
172
+
173
+ To add an object, instantiate a `NSFNanoObject`, populate it and add it to the document store.
174
+
175
+ ### Example
176
+ // Instantiate a NanoStore and open it
177
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
178
+
179
+ // Generate an empty NanoObject
180
+ NSFNanoObject *object = [NSFNanoObject nanoObject];
181
+
182
+ // Add some data
183
+ [object setObject:@"Doe" forKey:@"kLastName"];
184
+ [object setObject:@"John" forKey:@"kFirstName"];
185
+ [object setObject:[NSArray arrayWithObjects:@"jdoe@foo.com", @"jdoe@bar.com", nil] forKey:@"kEmails"];
186
+
187
+ // Add it to the document store
188
+ [nanoStore addObject:object error:nil];
189
+
190
+ // Close the document store
191
+ [nanoStore closeWithError:nil];
192
+
193
+ Alternatively, you can instantiate a NanoObject providing a dictionary via:
194
+
195
+ + (NSFNanoObject*)nanoObjectWithDictionary:(NSDictionary *)theDictionary
196
+
197
+ NanoStore will assign a UUID automatically when the NanoObject is instantiated. This means that requesting the key from the NanoObject will return a valid UUID. The same holds true for objects that inherit from `NSFNanoObject`. However, classes that implement the `NSFNanoObjectProtocol` protocol should make sure they return a valid key via:
198
+
199
+ - (NSString *)nanoObjectKey
200
+
201
+ ### Warning
202
+ If an attempt is made to add or remove an object without a valid key, an exception of type NSFNanoObjectBehaviorException
203
+ will be raised. To update an object, simply modify the object and add it to the document store. NanoStore will replace
204
+ the existing object with the one being added.
205
+
206
+ ### Example
207
+ // Instantiate and open a NanoStore
208
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
209
+
210
+ // Assuming the dictionary exists, instantiate a NanoObject
211
+ NSDictionary *info = ...;
212
+ NSFNanoObject *object = [NSFNanoObject nanoObjectWithDictionary:info];
213
+
214
+ // Add the NanoObject to the document store
215
+ [nanoStore addObject:object error:nil];
216
+
217
+ // Update the NanoObject with new data
218
+ [object setObject:@"foo" forKey:@"SomeKey"];
219
+
220
+ // Update the NanoObject in the document store
221
+ [nanoStore addObject:object error:nil];
222
+
223
+ To remove an object, there are several options available. The most common methods are found in NSFNanoStore:
224
+
225
+ - (BOOL)removeObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError
226
+ - (BOOL)removeObjectsWithKeysInArray:(NSArray *)theKeys error:(out NSError **)outError
227
+ - (BOOL)removeObjectsInArray:(NSArray *)theObjects error:(out NSError **)outError
228
+
229
+ ### Example
230
+ // Instantiate and open a NanoStore
231
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
232
+
233
+ // Assuming the dictionary exists, instantiate a NanoObject
234
+ NSDictionary *info = ...;
235
+ NSFNanoObject *object = [NSFNanoObject nanoObjectWithDictionary:info];
236
+
237
+ // Add the NanoObject to the document store
238
+ [nanoStore addObject:object error:nil];
239
+
240
+ // Remove the object
241
+ [nanoStore removeObject:object error:nil];
242
+
243
+ // ... or you could pass the key instead
244
+ [nanoStore removeObjectsWithKeysInArray:[NSArray arrayWithObject:[object nanoObjectKey]] error:nil];
245
+
246
+ # It's not a flat World
247
+
248
+ Most database solutions force the developer to think in a two-dimensional space (rows and columns), forcing the developer to plan the schema ahead of time. This situation is not ideal because in most cases schema refinements could be required, oftentimes impacting the code as well.
249
+
250
+ NanoStore goes beyond that allowing the developer to store objects in their natural form. These objects must conform to the `NSFNanoObjectProtocol` protocol, providing NanoStore with the NSDictionary that will be stored. By using a dictionary data can be inspected very quickly, and it also allows the structure to be defined in a hierarchical fashion as well, due to the fact that it includes support for nested collections (of type NSDictionary and NSArray.) Each inner-object is indexed automatically, thus allowing to quickly find objects which contain a specific key and/or value.
251
+
252
+ By default, NanoStore allows objects to be stored without any sense of relationship to other objects. This simple format, while powerful, is limited because the developer has to keep track of the relationships among objects. Some applications may need to relate objects, some of them perhaps of different nature or class type. This is exactly what NanoBag (represented by the `NSFNanoBag` class) does: it allows any object conforming to the `NSFNanoObjectProtocol` protocol to be added to the bag. By saving the bag with one single call, the new and/or modified NanoObjects are taken care of seamlessly.
253
+
254
+ The `NSFNanoBag` API is rich, allowing the developer to add, remove, reload and undo its changes, deflate it (thus saving memory) and inflate it whenever it's required. In addition, it provides methods to obtain all bags, specific bags matching some keys, and bags containing a specific object (see `NSFNanoStore` for more information).
255
+
256
+ # Where are my objects?
257
+
258
+ While `NSFNanoStore` provides some convenience methods to obtain standard objects such as bags, the bulk of the search mechanism is handled by `NSFNanoSearch`. The steps involved to perform a search are quite simple:
259
+
260
+ 1) Instantiate a search object
261
+ 2) Configure the search via its accessors
262
+ 3) Obtain the results specifying whether objects or keys should be returned (*)
263
+
264
+ ### Note
265
+ (*) If introspecting the data is needed, request objects. You should request keys if you need to feed the result to
266
+ another method, such as the following method in NSFNanoStore:
267
+
268
+ -(BOOL)removeObjectsWithKeysInArray:(NSArray *)theKeys error:(out NSError **)outError
269
+
270
+ ### Example: finding all objects with the attribute 'LastName' and value 'Doe'
271
+
272
+ NSFNanoSearch *search = [NSFNanoSearch searchWithStore:nanoStore];
273
+
274
+ search.attribute = @"LastName";
275
+ search.match = NSFEqualTo;
276
+ search.value = @"Doe";
277
+
278
+ // Returns a dictionary with the UUID of the object (key) and the NanoObject (value).
279
+ NSDictionary *searchResults = [search searchObjectsWithReturnType:NSFReturnObjects error:nil];
280
+
281
+ ### Example: removing all objects with the attribute 'LastName' and value 'Doe'
282
+
283
+ NSFNanoSearch *search = [NSFNanoSearch searchWithStore:nanoStore];
284
+
285
+ search.attribute = @"LastName";
286
+ search.match = NSFEqualTo;
287
+ search.value = @"Doe";
288
+
289
+ // Returns an array of matching UUIDs
290
+ NSArray *matchingKeys = [search searchObjectsWithReturnType:NSFReturnKeys error:nil];
291
+
292
+ // Remove the NanoObjects matching the selected UUIDs
293
+ NSError *outError = nil;
294
+ if (YES == [nanoStore removeObjectsWithKeysInArray:matchingKeys error:&outError]) {
295
+ NSLog(@"The matching objects have been removed.");
296
+ } else {
297
+ NSLog(@"An error has occurred while removing the matching objects. Reason: %@", [outError localizedDescription]);
298
+ }
299
+
300
+ ### Example: calculating the average salary of all objects with the attribute 'LastName' and value 'Doe'
301
+
302
+ Another cool feature is the possibility to invoke aggregated functions (count, avg, min, max and total) on the search results. Using the search snippet above, calculating the average salary of all people with last name equal to 'Doe' is very easy.
303
+
304
+ NSFNanoSearch *search = [NSFNanoSearch searchWithStore:nanoStore];
305
+
306
+ search.attribute = @"LastName";
307
+ search.match = NSFEqualTo;
308
+ search.value = @"Doe";
309
+
310
+ float averageSalary = [[search aggregateOperation:NSFAverage onAttribute:@"Salary"]floatValue];
311
+
312
+ # Sorting
313
+
314
+ Combining search and sort is an extremely easy operation. There are two simple parts:
315
+
316
+ 1) Preparing your classes for sorting
317
+ 2) Setup a search operation and set its sort descriptors
318
+
319
+ ### Preparing your classes for sorting
320
+
321
+ Since NanoStore relies on KVC to perform the sorts, a hint of the location where the data lives within the object is required. Since KVC uses a key path to reach the element being sorted, we need a way to "point" to it. Most custom classes will return *self*, as is the case for NSFNanoBag:
322
+
323
+ - (id)rootObject
324
+ {
325
+ return self;
326
+ }
327
+
328
+ *Self* in this case represents the top level, the location where the variables *name*, *key* and *hasUnsavedChanges* are located:
329
+
330
+ @interface NSFNanoBag : NSObject <NSFNanoObjectProtocol, NSCopying>
331
+ {
332
+ NSFNanoStore *store;
333
+ NSString *name;
334
+ NSString *key;
335
+ BOOL hasUnsavedChanges;
336
+ }
337
+
338
+ Assume we have an object that represents a person and its root object is set to <i>self</i>, just as demonstrated above:
339
+
340
+ @interface Person : NSFNanoObject
341
+ {
342
+ NSString *firstName;
343
+ NSString *lastName;
344
+ NSString *email;
345
+ }
346
+
347
+ If we wanted to retrieve all the existing people with <i>firstName</i> equal to <i>John</i> sorted by <i>lastName</i> we would do the following:
348
+
349
+ // Assume NanoStore has been opened elsewhere
350
+ NSFNanoStore *nanoStore = ...;
351
+
352
+ // Prepare the search
353
+ NSFNanoSearch *search = [NSFNanoSearch searchWithStore:nanoStore];
354
+ search.attribute = @"firstName";
355
+ search.match = NSFEqualTo;
356
+ search.value = @"John";
357
+
358
+ // Prepare and set the sort descriptor
359
+ NSFNanoSortDescriptor *sortByLastName = [[NSFNanoSortDescriptor alloc]initWithAttribute:@"lastName" ascending:YES];
360
+ search.sort = [NSArray arrayWithObject:sortByLastName];
361
+
362
+ // Perform the search
363
+ NSArray *searchResults = [search searchObjectsWithReturnType:NSFReturnObjects error:nil];
364
+
365
+ // Cleanup
366
+ [sortByLastName release];
367
+
368
+ # Performance Tips
369
+
370
+ NanoStore by defaults saves every object to disk one by one. To speed up inserts and edited objects, increase NSFNanoStore's `saveInterval` property.
371
+
372
+ ### Example
373
+
374
+ // Instantiate and open a NanoStore
375
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
376
+
377
+ // Increase the save interval
378
+ [nanoStore setSaveInterval:1000];
379
+
380
+ // Do a bunch of inserts and/or edits
381
+
382
+ // Don't forget that some objects could be lingering in memory. Force a save.
383
+ [nanoStore saveStoreAndReturnError:nil];
384
+
385
+ ### Note
386
+ If you set the saveInterval value to anything other one, keep in mind that some objects may still be left unsaved after
387
+ being added or modified. To make sure they're saved properly, call:
388
+
389
+ - (BOOL)saveStoreAndReturnError:(out NSError **)outError .
390
+
391
+ Choosing a good saveInterval value is more art than science. While testing NanoStore using a medium-sized dictionary
392
+ (iTunes MP3 dictionary) setting saveInterval to 1000 resulted in the best performance. You may want to test with
393
+ different numbers and fine-tune it for your data set.
394
+
395
+ ### Warning
396
+ Setting saveInterval to a large number could result in decreased performance because SQLite's would have to spend more
397
+ time reading the journal file and writing the changes to the store.
398
+
399
+ # Need more help?
400
+
401
+ There are two quick ways to find answers: reading the documentation and browsing the Unit tests.
402
+
403
+ While several attempts have been made to make the documentation easy to read and understand, it's far from perfect. If you find that the documentation is incomplete, incorrect or needs some clarification, please file a bug. I'll appreciate it and correct it as soon as possible:
404
+
405
+ * NanoStore Documentation: http://dl.dropbox.com/u/2601212/NanoStore%202.0/html/index.html
406
+ * NanoStore Bug Tracker: https://github.com/tciuro/NanoStore/issues
407
+ * Twitter: http://twitter.com/nanostoredev
408
+
409
+ # Official Source Repository
410
+
411
+ The official repository for NanoStore is hosted on GitHub: https://github.com/tciuro/NanoStore
@@ -0,0 +1,3 @@
1
+ #ifdef __OBJC__
2
+ #import <UIKit/UIKit.h>
3
+ #endif
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+
3
+ install_resource()
4
+ {
5
+ case $1 in
6
+ *.xib)
7
+ echo "ibtool --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename $1 .xib`.nib ${SRCROOT}/Pods/$1 --sdk ${SDKROOT}"
8
+ ibtool --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename $1 .xib`.nib ${SRCROOT}/Pods/$1 --sdk ${SDKROOT}
9
+ ;;
10
+ *)
11
+ echo "cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
12
+ cp -R "${SRCROOT}/Pods/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
13
+ ;;
14
+ esac
15
+ }