In Parse, I have an object which has a key that is an array of pointers to other objects. How do I delete one of the pointers without deleting the entire array and without deleting the actual object?
if you use the removeObject:forKey: method of PFObject, it removes the item from your array but won't delete the pointer.
That's obj-c, btw, I'm not familiar with the Swift SDK.
You should read into the API Guide a bit for PFObjects and PFQueries. It'll answer a lot of questions you have before you ask them.
https://parse.com/docs/ios/api/Classes/PFObject.html#//api/name/removeObjectForKey:
Related
I'm quite new to Swift, and I just started with persistence. I was wondering how the NSKeyUnarchiver works.
NSKeyedUnarchiver.unarchiveObject(withFile: file)
This is my current code. I have the file, but I don't know exactly what I'm getting. What if I archived multiple objects? How do I know which one I'm pulling? Somebody please help.
Only a single object can be archived per file. However, this can be an array, a dictionary, or other collection type, which stores multiple objects.
Problem: I cannot create new PFObjects objectWithoutDataWithClassName:objectId: in swift, is this possible and if so how?
Context: I have a stored array of objectIds of parse objects that I want to use to populate a view but first I have to get each object from parse. Rather than making 'n' number of network requests on parse for each object I want to instead make an array of PFObjects using Parse's objectWithoutDataWithClassName:objectId: functionality and then call [PFObject fetchAllInBackground:block:] with the array. However, in swift it does not appear as though PFObject.objectWithoutDataWithClassname exists. Has anyone encountered this/know how to do this in swift....?
Thanks in advance.
You can use
PFObject(withoutDataWithClassName: <String>, objectId: <String?>)
This method became an initializer.
I'm using Realm.io as database and I need a select * from all_tables in Realm.
I mean a method returning an RLMArray, but I have not found anything about this.
I need the class reference, such as Realm Browser.
Thanks.
You can use [realm.schema.objectSchema valueForKey:#"className"] to get an NSArray of all of the RLMObject subclasses used in the Realm.
I don't believe this is possible at the moment. You should request it on github. In the mean time you will have to create your own. First you have to know that an RLMArray can only hold one type so if in these different tables there are different types than you can not do the following. It would be as easy as creating your own method for this. It would consist of getting all objects from each table and just inserting them into the RLMArray; If your tables don't have the same type then you will have to use a NSMutableArray or an NSArray.
I have an NSMutableArray that contains NSMutableDictionary's. Each dictionary has an AVAsset, an NSURL, an NSString, and two UIImages. I want to save my array to disk so that each time I close and open my app, I can load the array and convert the URLs's to NSData objects in order to play audio and use the AVAssets for some other actions. I know I can save and load my array using initWithContentsOfFile and writeToFile:atomically and this answer is pretty informative: Saving a NSArray. However, that answer was from 2009. Is there a better way of saving and loading an array these days?.
As for the answer you linked, the answer is still valid. And according to it, you cannot store it the way it mentions. This is because array must be plist format compatible in order to be saved like that. When you parse your array down to lowest element hierarchy, you have UIImage which is just an object pointer and doesn't make sense.
One practical way would be store UIImages as separate files, and store their paths as part of your NSMutableDictionary objects. Same holds true for AVAssets. Off course you need to engineer the solution to fully accomplish this goal.
One more way to store non-plist compatible objects is to use archiving and unarchiving feature. Refer to the documentation. Here, make sure that each object in the tree follows protocol NSCoding (Probably, AVAsset in your question does not conform to it, so you need a way to work around it). For an example, see this answer and search the likes of it.
I'm new in iPhone development, can you advice me how to serialize AdressBook records?
I have read stackoverflow - How do I serialize a simple object in iPhone sdk, but I still have questions:
should I extend ABRecordRef? Is it possible? Or should I implement own class NSObject?
(similar question was on Mac forums and was left without answer)
Thank you!
ABRecord is an opaque C type. It is not an object in the sense of Objective-C. That means you can not extend it, you can not add a category on it, you can not message it. The only thing you can do is call functions described in ABRecord Reference with the ABRecord as a parameter.
You could do two things to be able to keep the information referenced by the ABRecord arround:
Get the ABRecords id by ABRecordGetRecordID(). The ABRecordID is defined as int32_t so you can cast it to an NSInteger and store it wherever you like. You can later get the record back from ABAddressBookGetPersonWithRecordID () or ABAddressBookGetGroupWithRecordID(). But aware, the record could be changed or even deleted by the user or another app meanwhile.
Copy all values inside the record to a standard NSObject subclass and use NSCoding or other techniques to store it. You will then of cause not benefit from changes or additions to the record the user could have made.
Of cause you can combine both approaches.