Add (set)

From SwiftAPI

Jump to: navigation, search

Contents

C++

#import <set>
#import <string>
using namespace std;
 
set<string> s;
s.insert("foo");

Java

import java.util.*;
 
Set<String> s = new HashSet<String>();
s.add("foo");

Objective-C

Modifying a mutable set: developer.apple.com

- (void)addObject:(id)object
NSMutableSet *s = [NSMutableSet set];
[s addObject:@"foo"];

Creating a new set without modifying: developer.apple.com

- (NSSet *)setByAddingObject:(id)anObject
NSSet *s = [NSSet set];
s = [s setByAddingObject:@"foo"];

Python

docs.python.org

s = set()
s.add('foo')

Ruby

Ruby-Doc.org

require 'set'
 
s = Set.new
s << 'foo'

Swift

var s : Set<String> = []
s.insert("foo")
Personal tools