I'm using the function NSItemProvider(contentsOfURL: NSBundle.mainBundle().URLForResource("blockerList", withExtension: "json")
in a content blocker extension.
The thing is that all my rules are stored in a few dictionaries and, when I'm using this function, it's always because the rules have changed. I'm currently creating a String from these dictionaries that looks like "[{\"trigger\": {\"url-filter\": \"webiste.com\"},\"action\": {"\type\": \"css-display-none\",\"selector\":\".testContentBlocker\"}}]"
and I have to transform it in a JSON file to finally be able to use it in the function written previously described.
Instead of having to put the String in a JSON file to be able to use it, could I do something simpler to use NSItemProvider()
?
By loading the extension up in the debugger (and by using Hopper), you can see that
NSItemProvider(contentsOfURL:)
is simply registering to provide data from the file's contents with typepublic.json
.It's roughly equivalent to this:
So you can do this yourself, in memory:
If you want to provide content dynamically, you can use NSJSONSerialization to transform a dictionary into NSData at runtime.