Difference between Set (Swift ) and NSSet
One major difference I have observed between Set introduced as part of Swift and NSSet which is already available in Foundation framework is the way isSubSet method works in both.
NSSet does not bother the difference between a proper subset and a subset. But Set in Swift has method called
isStrictSubsetOf in addition to isSubsetOf which captures the scenario which Foundation fails to.
var set1 = Set(["r","a","m"]) var set2 = Set(["r","a","m"]) var bool = set1.isSubsetOf(set2) as Bool var bool1 = set1.isStrictSubsetOf(set2) as Bool bool = set2.isStrictSubsetOf(set2) as Bool
NSSet *set1 = [NSSet setWithObjects:@"a", @"b", @"c", nil]; NSSet *set3 = [NSSet setWithObjects:@"a", @"b", @"c", nil];; NSLog(@"isEqual :%d", [set1 isEqualToSet:set3]); NSLog(@"isSubSet :%d", [set1 isSubsetOfSet:set1]); <pre>
For differences between Proper Subset and Subset