title: How do I get unique values from an array
body: <p>Please note <strong><em>this is for OSX, not for iOS.</em></strong> </p>
  
  <p>I have looked and tried some solutions in other SO questions, but none seem to work for me, hence this:</p>
  
  <p>I want to get a unique set of years out of an array.</p>
  
  <p>My code is this:</p>
  
  <pre><code>NSMutableArray * unique = [NSMutableArray array];
          NSMutableSet * processed = [NSMutableSet set];
          for (yearString in yearStringArray) {
              if (![processed containsObject:yearString] == NO) {
                  [unique addObject:yearString];
              }
              [processed addObject:yearString];
          }
  
          NSLog(@"unique: %@",unique );
          NSLog(@"processed: %@",processed );
  
      }];
  
  The console returns:
  
  unique: (
          (
          1941,
          1942,
          1943,
          1945,
          1948,
          1948,
          1948,
          1949
      )
  
  processed: {(
          (
          1941,
          1942,
          1943,
          1945,
          1948,
          1948,
          1948,
          1949
      )
  )}
  </code></pre>
  
  <p>I only want one 1948.  I would appreciate any help.</p>
  
  <p>UPDATES: Thanks for the answers all. Keep em coming please!!!</p>
  
  <p>These are the code snips I've tried now:</p>
  
  <p>1.</p>
  
  <pre><code>for (yearString in yearStringArray) {
              if ([processed containsObject:yearString] == NO) {
                  [unique addObject:yearString];
              }
              [processed addObject:yearString];
          }
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>   NSString *yearString = [[NSString alloc] init];
      NSArray *objectArray = [[NSArray alloc] init];
      [objectArray = objects copy];
  
      for (int j = 0; j &lt;= objectArray.count; j++) {
          NSString *yearString = [objectArray valueForKey:@"year"];
          [yearStringArray addObject:yearString];
      }
  
  
      NSMutableArray * unique = [NSMutableArray array];
      NSMutableSet * processed = [NSMutableSet set];
  
  
      for (yearString in yearStringArray) {
  
          [unique addObject:yearString];
          [processed addObject:yearString];
      }
  
      NSArray *processed2 = [[NSSet setWithArray:unique] allObjects];
      NSLog(@"unique: %@",unique );
      NSLog(@"processed: %@",processed );
      NSLog(@"processed2: %@",processed2 );
      //[self setYears];
  }];
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>NSString *yearString = [[NSString alloc] init];
      NSArray *objectArray = [[NSArray alloc] init];
      [objectArray = objects copy];
  
      for (int j = 0; j &lt;= objectArray.count; j++) {
          yearString = [objectArray valueForKey:@"year"];
          [yearStringArray addObject:yearString];
      }
  
  
  
      NSArray *uniqueYears = [yearStringArray valueForKeyPath:@"@distinctUnionOfObjects.self"];
      NSLog(@"uniqueYears: %@", uniqueYears);
  
  
  }];
  
  
  
  }
  </code></pre>
  
  <p>Still not getting unique years..</p>