Questions tagged [nscountedset]

The NSCountedSet class declares the programmatic interface to a mutable, unordered collection of indistinct objects. A counted set is also known as a bag.

The NSCountedSet class declares the programmatic interface to a mutable, unordered collection of indistinct objects. A counted set is also known as a bag.

Each distinct object inserted into an NSCountedSet object has a counter associated with it. NSCountedSetkeeps track of the number of times objects are inserted and requires that objects be removed the same number of times. Thus, there is only one instance of an object in an NSSet object even if the object has been added to the set multiple times. The count method defined by the superclass NSSet has special significance; it returns the number of distinct objects, not the total number of times objects are represented in the set. The NSSet and NSMutableSet classes are provided for static and dynamic sets (respectively) whose elements are distinct.

While NSCountedSet and CFBag are not toll-free bridged, they provide similar functionality.

26 questions
11
votes
4 answers

NSCountedSet order by count

Does anyone know how to take an NSCountedSet of objects and create an array of those objects in order by their object count? (highest count to lowest)
Choppin Broccoli
  • 3,048
  • 2
  • 21
  • 28
5
votes
3 answers

Most common array elements

I need to find the most common (modal) elements in an array. The simplest way I could think of was to set variables for each unique element, and assign a count variable for each one, which increases every time it is recorded in a for loop which…
TimWhiting
  • 2,405
  • 5
  • 21
  • 41
2
votes
1 answer

NSCountedSet enumeration in Swift

I'm looking for a way to use NSCountedSet in a more Swift-like way (whatever that means). Consider the following snippet that I basically translated directly from Objective C. I iterate over each symbol (a String) in the set, get its corresponding…
koen
  • 5,383
  • 7
  • 50
  • 89
2
votes
3 answers

How to set object count to zero(or some value) in NSCountedSet?

I have following NSCountedSet (item1 [2000], item2 [9000], item3 [200], item4 [3000]) Now i want to remove item1 object from my set. one solution is while([mySet countForObject:item1]) [mySet…
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
1
vote
1 answer

Where is CountedSet in Swift 3 (beta 6)?

Swift 3 introduces the CountedSet class (yes it's a class, not a struct) which should replace/bridge the old Objective-C NSCountedSet class. However using the last beta of Swift 3 (beta 6) the CountedSet symbol is no longer recognised. What happened…
Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148
1
vote
1 answer

Find numbers in array that appear 2 or more times

I need to find duplicated numbers (that appear 2 or more times) in array how can I do it without using NSCountedSet? This is a solution I did: NSCountedSet *countedSet = [NSCountedSet setWithArray:array]; __block NSUInteger totalNumberOfDuplicates =…
Lipatov Eugen
  • 407
  • 3
  • 10
1
vote
0 answers

Access data in Dictionary from NSCountedSet objects

I have an NSCountedSet consisting of String objects, if I iterate over the set and print it out, I see something like this: for item in countedSet { print(item) } Optional(One) Optional(Two) The countedSet is created from an Array of String…
koen
  • 5,383
  • 7
  • 50
  • 89
0
votes
2 answers

Is there more efficient way to keep custom object array unique by each pagination data feeds?

In the tableView's willDisplay checks latest cell and then trigger new request for upcoming datas cited as pagination. I want to keep that custom object array's IDs as unique with upcoming datas too. I tried below solution to make it, but I wonder…
iamburak
  • 3,508
  • 4
  • 34
  • 65
0
votes
1 answer

NSCountedSet generic function

To see how many Person objects with a specific identifier occur in an NSCountedSet, I created the following function: public extension NSCountedSet { public func countFor(identifier: String) -> Int { let p = self.compactMap { $0 as?…
koen
  • 5,383
  • 7
  • 50
  • 89
0
votes
1 answer

Array Not Sorted Correctly

I want to sort my array by month and year. I successfully did that with the following code: let formatter : DateFormatter = { let df = DateFormatter() df.locale = Locale(identifier: "en_US_POSIX") df.dateFormat = "MMMM yyyy" return…
tyguy
  • 358
  • 2
  • 4
  • 16
0
votes
3 answers

To Get Duplicate as well as original items from an array in iOS

I have an array, as (John, Jane, John) I want to get duplicates,as well as original elements of array like (John,John) I am able to get single occurance from code here NSArray *names = [NSArray arrayWithObjects:@"John", @"Jane", @"John",…
Dhananjay Jadhav
  • 177
  • 1
  • 2
  • 13
0
votes
1 answer

swift "Duplicate links in many to many relationship" it is real?

i have many to many relationship in my Core Data model, and i need to add some duplicate links in my links containers, i know the type of link container is NSSet @NSManaged public var linkContainer: NSSet? can i change this type to Array of my…
Skie
  • 91
  • 1
  • 2
  • 13
0
votes
1 answer

`CountedSet` initialization issue

I'm comparing the characters contained within two words. In seeking to accomplish this, Set (aka NSSet) seemed like the way to go to accomplish this task. I've discovered it returns false positives on matches, so I am attempting to use CountedSet…
Adrian
  • 16,233
  • 18
  • 112
  • 180
0
votes
1 answer

Alternative to NSCountedSet in Objective-C to keep order

The code below does what I need except it isn't ordered afterwards.(Please don't tell me its because of a NSSet is unordered I know that.) This isn't a repeated SO question either I've spent over 40 minutes reading all the "similar" questions and…
Robert
  • 63
  • 7
0
votes
0 answers

Counting Repeated Objects In NSArray Only Working Some of Time

My NSArray inside of a PFObject needs to be sorted. The PFObject contains multiple items, including an array, which contains days of the week, and I need to know which date is repeated most often for each item inside the PFObject. Inside my…
user717452
  • 33
  • 14
  • 73
  • 149
1
2