How can I do that programatically?
我怎样才能程序化地做到这一点呢?
I am told that this is the way to do it but the NSSet
has a different order.
我被告知这是一种方法但是NSSet有不同的顺序。
NSSet *set = [NSSet setWithArray:theArray];
Any idea?
任何想法?
Thanks in advance.
提前谢谢。
3 个解决方案
#1
11
If you want order, you'll have to use an NSOrderedSet.
如果你想要订购,你必须使用NSOrderedSet。
NSOrderedSet *set = [NSOrderedSet orderedSetWithArray:theArray];
#2
2
If you care about the order, you probably do not want to use an NSSet.
如果您关心顺序,您可能不希望使用NSSet。
#3
-1
There is the solution for Swift 3 :
Swift 3有一个解决方案:
let mutableArray : NSMutableArray!
// Use type NSObject or any custom type
let set = NSSet(array: mutableArray as NSArray as! [NSObject])
#1
11
If you want order, you'll have to use an NSOrderedSet.
如果你想要订购,你必须使用NSOrderedSet。
NSOrderedSet *set = [NSOrderedSet orderedSetWithArray:theArray];
#2
2
If you care about the order, you probably do not want to use an NSSet.
如果您关心顺序,您可能不希望使用NSSet。
#3
-1
There is the solution for Swift 3 :
Swift 3有一个解决方案:
let mutableArray : NSMutableArray!
// Use type NSObject or any custom type
let set = NSSet(array: mutableArray as NSArray as! [NSObject])