Xcode: Compare two NSMutableArrays

2019-08-01 04:17发布

问题:

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.

回答1:

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