Xcode: Compare two NSMutableArrays - nsmutablearray

I have two NSMutableArrays(initialized from plist file contents) that contains Dictionary objects. Could anyone please help me with the best method to achieve following result. The structure of Array is:
I want to compare two following arrays to get the old entries which is not exists in new array.
Old Array:
<dict>
<key>ResourceId</key>
<string>352</string>
</dict>
<dict>
<key>ResourceId</key>
<string>3115</string>
</dict>
New Array:
<dict>
<key>ResourceId</key>
<string>352</string>
</dict>
<dict>
<key>ResourceId</key>
<string>4629</string>
</dict>
I want the resulted array contains following entry:
<dict>
<key>ResourceId</key>
<string>3115</string>
</dict>
Thanks.

Converting NSMutableArray to NSMutableSet objects and then using Intersect method should be the best one..

Related

Access macOS Photo Library using Electron

I am trying to write an Electron application that lets users select photos from their photo library on macOS. My assumption is that the only way to access the photos without exporting them is by going into ~/Pictures/Photos Library.photoslibrary. However, when passing the file path of a photo to an <img> tag, I get net::ERR_ACCESS_DENIED error.
Is there a way to grant Electron application access to the user's photo library?
I've been writing code recently that accesses the PhotosLibrary. I did this by writing a native module that calls the PhotoKit API. If you go that direction there's going to be a steep learning curve as you'll likely be using Objective-C++ with the features and quirks of both C++ and Objective-C while trying to write something in JavaScript.
https://github.com/nodejs/node-addon-api
https://developer.apple.com/documentation/photokit?language=objc
With Apple's recent security features, you'll also need to somehow run your code inside of an app with the correct entitlements and values set in its Info.plist that will allow access to APIs.
In build/entitlements.mac.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- https://github.com/electron/electron-notarize#prerequisites -->
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<!-- https://github.com/electron-userland/electron-builder/issues/3940 -->
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<!-- Allow app to access Photos Library using PhotoKit API -->
<key>com.apple.security.personal-information.photos-library</key>
<true/>
</dict>
</plist>
The following will be needed in your App's Info.plist:
<plist version="1.0">
<dict>
...
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to the photos library</string>
</dict>
</plist>
This can be done using electron-builder by adding the following value to the extendInfo extendInfo of your mac build settings in package.json.
{
...
"build": {
...
"mac": {
...
"extendInfo": {
...
"NSPhotoLibraryUsageDescription": "This app needs access to the photos library"
}
}
}
}
I hope this is gives you something to start with. Like I said above, this will come with a steep learning curve unless you're already familiar with JavaScript, native module development, Objective-C, C++ and Apple's APIs.
If you just need to read data from it for a one-off project, the photolibrary is really just a directory-like container around your photos, and an sqlite database for the metadata (faces, places and albums/folders). Right click-the photolibrary, show package contents, orig photos are under Masters/YYYY/MM/DD/IMG_XXXX.JPG format, and metadata is in database/photos.db, some tables you can query are RKMaster (filename/uuid of master files), RKAlbum, RKFace, RKMemory, RKPlace, RKFolder, RKVersion, RKKeyword, etc., get any free sqlite browser and you can figure out the rest.
You can also copy the .photolibrary file to Linux and scan its folder/sqlite file using pure node, you don't need any native modules to read it. Writing to it may try to fire some sqlite triggers that seem to belong to some macosx-proprietary extensions, so make backups first, try writes with extensions disabled, or just read and extract the images and metadata to some other format (raw jpeg/json files in a bucket somewhere) that are easy to collate and then (if you have to), reverse the process and write out to another photolibrary file once you get the relation between the tables and filesystem paths inside its container.

How to do XML-Split and Keep Parent Element?

I know Spring Integration is rather old but I have a piece of code that needs small modification to move on. I need to split the incoming XML message and preserve the parent node. Here is my XML:
<Order>
<Item>A</Item>
<Item>B</Item>
</Order>
And I want to split into 2 XMLs and preserve the XSD validation.
<Order>
<Item>A</Item>
</Order>
and
<Order>
<Item>B</Item>
</Order>
Did this:
<beans xmlns:int-xml="http://www.springframework.org/schema/integration/xml">
...
<int-xml:xpath-splitter id="splitter">
<int-xml:xpath-expression expression="/Order/Item"/>
</int-xml:xpath-splitter>
...
It split into
<Item>A</Item>
and
<Item>B</Item>
but I need the parent to be there. Anyway to make it works? Thanks in Advance.
What you need is an <int-xml:xslt-transformer> after your <int-xml:xpath-splitter>.
See Reference Manual for more info: https://docs.spring.io/spring-integration/docs/5.2.0.RELEASE/reference/html/xml.html#xml-xslt-payload-transformers
You need to learn what is XSLT and so on.
I know Spring Integration is rather old
??
It is actively maintained and enhanced; there was a completely new release this month.
You either need a custom splitter, or you can add a transformer after the splitter to add the outer node.

Deep-linking Xamarin iOS

I need to add deep linking feature to my app with Xamarin iOS.
My info.plist looks like this:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>domine.somthing/index.html?UV</string>
</array>
<key>CFBundleURLTypes</key>
<string>com.domine.somthing/index.html?UV</string>
</dict>
I seems not working due to "/" char in the URL.
How am I supposed to write CFBundleURLTypes and CFBundleURLSchemes URL values in order to make it work?
Deep links can returns users directly to your application.
After adding URI support to your application like you did, just clicking on a URL consisting of a scheme name for your application will launch your app, but it seems you are filling CFBundleURLSchemes and CFBundleURLTypeswith with wrong values.
CFBundleURLName - Usually, this corresponds to the bundle ID of your
application. Please see Apple's Development doc for more informations.
CFBundleURLSchemes - Array of strings containing URL scheme names,
usually at least your application's name (without spaces). Pay
attentiont to ensure these values are unique to your application.
Look at this sample:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.yourcompany.yourapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>appname</string>
</array>
</dict>
</array>
Now clicking on a URL consisting of appname:// on the device will launch your app.
If you want to send a user to a specific part of your application, you need to add arguments to this URL, making a deep link. Here is a sample with a path and query:
appname://custompath?customquery=customvalue
When a user clicks a URL containing your scheme (appname://), your app's delegate is called and specifically the method OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)where you can handle schemas an execute correct app routing based on schema arguments (if provided).

iOS JPG File Association using Swift 2

I have an iOS Project I'm working on using Xcode7 and Swift2. I have file association working great on it with PDF files. I did this in my Info.plist. I want to now associate it with images, particularly with JPG images. I have looked online and cannot find anything for this. Can someone please help?
For PDF I have:
Which looks like this in Source Code:
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>PDFIcon64.png</string>
<string>PDFIcon320.png</string>
</array>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
</dict>
I tried copying the above and adjusting for JPG with no luck:
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>JPGIcon64.JPG</string>
<string>JPGIcon320.JPG</string>
</array>
<key>CFBundleTypeName</key>
<string>JPEG</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.xyz.JPG</string>
</array>
</dict>
I also tried this instead with no luck:
<dict>
<key>CFBundleTypeName</key>
<string>public.JPG</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>public.JPG</string>
</array>
</dict>
When I'm viewing an image in my iOS Photo Library and click on the action button, it does not list my app in the area where the Message, Facebook, Twitter, etc. apps are located, like it does with PDF files from my Mail app. I've looked online in all kinds of forums with no luck for this.
For images that will be stores with the app you should consider using an Asset Catalog.
There is one asset catalog that defaults to every project and you can store images in there.
Once you add as asset to the catalog you can reference it in a string by the name you have it (without its extension).
For example
UIImage(named: "JPGIcon64")
Here is the link to the apple doc that talks about it here

xsl:fo how to include dynamically generated svg

I want to generate a svg chart and insert it into pdf using apache fop. So far I have tried using
<fo:instream-foreign-object xmlns:svg="http://www.w3.org/2000/svg">
<xsl:value-of select="svgData"/>
</fo:instream-foreign-object>
in xsl file and generated svg is held as a string in the "svgData". This approach is not working as it is not parsing the string svg data and just appending it.
How do I achieve this ? I need to create the svg in java (baitk?) and add it to the pdf.
I spent some time too having headache on this problem. Finally I could make it work by using a <xsl:copy-of> instead of <xsl:value-of> + using prefixed namespace.
<fo:block>
<fo:instream-foreign-object content-type="content-type:xml/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<xsl:copy-of select="/path/to/svg:svg"/>
</fo:instream-foreign-object>
</fo:block>
I spent many hours solving the problem. Without success. My recommendation is not to pursue this approach any further.
My solution to get dynamic SVG into a PDF is the following.
Save the SVG on your hard disk and remember the filename/path in the object.
Then use the filename to fill the external-graphic src attribute.
After creating the PDF the svg-files have to be deleted.
Done.
XSL:
<xsl:template match="qandapair">
<fo:block text-align="center">
<fo:external-graphic src="{chart}"/>
</fo:block>
</xsl:template>
XML:
<qandapair>
<chart>gaoejTLVfcBUrCgjvmsWgjBwQzHYmYYJ.svg</chart>
...
</qandapair>

Resources