Completely remove RLMObject in Realm.io - swift

I see there are ways to empty an RLMObject, but I want to completely remove it from the RLMRealm storage. And I don't want to do a migration either, I want it removed. Is that possible?

A better way is to do realm.deleteAllObjects on your instance of the realm. More about that here http://realm.io/docs/cocoa/0.90.6/#deleting-objects. This removes all of your objects.
If you want to remove one object, you can do realm.deleteObject(object here). There is more on that in the link above as well.
Removing the file like you are doing does prevent the need for migrations, just don't forget to remove that line if you do go that route!

Did it the hard way. Used RLMRealm.defaultRealmPath() to give me the default path. You can use NSFileManager to remove that, and other Realm related files in that directory, or you can do it manually. This will clear ALL the objects.

Related

Filereference extbase versus Core

I am confused because I figured out, that there are 2 different FileReference classes inside TYPO3. One of them is from the Core and the other one is from Extbase.
The one from the core has function like delete(), but this delete is not implemented yet. I cannot find any function for deleting the FileReference.
If I use update in my extension from the repository, the image will be added not replaced by the new one.
I would like to understand how I can add, delete and fetch files to/from ext_file_reference in a simple way.
Does anybody have a solution or a hint?
It's unclear from your question what you are trying to do.
If you want to replaces files, you do that on the File Object itself, not the references. But note, that this replaces the file for all references. There is a replaceFile() function on the ResourceStorage object of the file.
If you want to replace a file in a Property, you have to detach one file and attach the other. Every Property that holds FileReferences is an ObjectStorage, and as such comes with attach() and detach() methods to do that.
let me try to explain it in more details. I try to replace an image on a page with another one, but without modifying the image at all. Also the new image is already stored under fileadmin. I would need a new filereference and to replace the old one in the sys_file_reference.
So attach and detach would be the goodsolutions, but are not working with extbase filereference. For that I need a \TYPO3\CMS\Extbase\Persistence\ObjectStorage object. I tried "\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\HGA\Hgarecipes\Domain\Model\FileReference>" but it creates an error "Cannot cast object of type "TYPO3\CMS\Extbase\Persistence\ObjectStorage" to string". So finally I am looking for a sulution to add and delete images from sys_file_reference under extbase. I found many pleople which are looking for something, but no solution. Alo if I use the objectstorage I have not longer access to the originalResource of the filereference.
With other words, to create a entry in the sys_file_reference with a given filepath and delete this entry if not longer needed.
On the other hand I want to understand why extbase needs a own filereference.

TYPO3: Custom Globals?

I have some data (logins) I want to be ignored from git in my custom TYPO3 extension code.
As AdditionalConfiguration.php is already ignored in my case, it seems a good place to store such data.
It normally contains Data like
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname']
Now would it make sense to make something like custom globals? Does that exist?
$GLOBALS['CUSTOM_CONF_VARS']['MYEXT']['username']
Should and can I do that or not?
I think you can use your own globals. But I would consider using your own globals as bad programming style.
If you have installation specific data the right way to store the data depends on the kind of data and where you need it:
everything for the Frondend should be stored in typoscript. This can be in a file from a site-extension or in the database (template record)
for BE you could use Page- or User-TSconfig. here you also can use a file from a site-extension or database records (pages/be_user)
if you have FE and BE or anything alse (e.g. scheduler jobs) you can use extension specific global data, you can set in the extension manager. -> docs.
Instead of saving configuration in $GLOBALS try use typoscript. Will be much easier to keep and maintain it.

How to know if a Catpart is used in some product or not

I have hundreds of Catia V5 catparts and catproducts in a folder on hard disc. I want to know if a particular catpart is used in some catproduct or not. If it is not used in any product, I want to delete it and clean my hard disc. One way to do it is to open all catproducts one by one and check carefully they contain this model. This is cumbersome process and can lead to serious mistakes. Is there some automatic way to check it? If not, is it possible to write some macro for that purpose?
It is possible with a VBA script. If it's just Catpart file that your looking for in a product, then your script would work as follows
query your folder(s) for all catparts and catproducts.(use 2 dictionaries or arrays, one for each file type each)
Via a loop, Individually open and load each catproduct and essentially walk the tree and compare each child Catpart to your compiled list of catparts. If a match is found, movethe part to a new "white list"(dictionary or array)
Close the catproduct and check the next one.
Then, when all done, your original list(dictionary or array) will be your unused parts.
I'm not sure exactly how your models are built, but you may need to check for additional references/links in your catproducts (additional logic) before doing something like this.

How to build assetBundle without using Selection

I want to write my own editor that would allow me to search the whole Assets folder for object type of X and make an AssetBundle from them.
I went through all the manuals and docs and it seems that they all use the Selection class to build the Assets Bundle.
But what if there are 10 000+ objects scattered in different folders and I don't want to select each manually, yet I still want to track their dependencies. Is there a way to do so?
I have already tried editing Selection.objects, but as much as I understand it's limited to one concrete scene.
Is it possible to skip the whole Selection class and just use BuildPipeline.BuildAssetBundle() method? If yes, how to get the correct list of objects that can be used? Do I need to write my own deep threading loop to get the dependencies?
All you need is a list of objects. That's it. How you get them is irrelevant. You can do that with the Selection class, but if you have other means of finding the assets, that's no problem either.
As for dependencies, keep in mind that your final call will be something like:
BuildPipeline.BuildAssetBundle(main_asset, objects_array, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
See that BuildAssetBundleOptions.CollectDependencies? It will make sure that all the necessary dependencies for the objects you've specified get included as well.

Issue with duplicate search results and XMLParser array refresh

I use an NSXMLParser to parse ext. API data. I also use a Singleton shared array var to maintain info retrieved from ext API.
This info is dynamic and changesas the user types anything in UISearchBar
Now the thing is as soon as the user types anything, I clear off the existing array contents by using [retrievedArray removeAllObjects];
Thus this refreshed retrievedArray based on the current terms in the search bar.
This works fine if the user types slowly. However I get to see duplicate search results if the user types very fast. This, I am assuming, is because the retrievedArray contents do not get enough time to clear off.
I am still trying to resolve the issue. Please suggest some more fixes.
Could you please provide me the fix.
No, I don't think this is the case, unless you're doing search in a separate thread and clear array in another one. If not, then there is probably error in your search logic.
First of all I think a singleton approach may not be the best way to go for what you are doing. But make sure that you are synchronizing all mutable access to the array. Instead of allowing the singleton to return a NSMutableArray for any object and their mom (super) to use you need to have methods like addObject,removeObject,clear with #synchronize blocks or any kind of lock you decide on. I still see issues with this approach because the code calling addObject, remove and clear will all need to be synchronized as well. Maybe consider on each auto complete request you use a delegate or post a NSNotification containing a timestamp, the characters the user typed to get data, and a NSArray of results. At that time you can see if the response is still valid, discard any invalid responses, and update the user with just the contents of the most recent valid NSArray