Remove (set)

From SwiftAPI

Jump to: navigation, search

Contents

C++

#include <set>
#include <string>
using namespace std;
 
set<string> s;
s.insert("foo");
s.insert("bar");
s.erase("foo");
int n = s.size();
// n == 1

Java

import java.util.*;
 
Set<String> s = new HashSet<String>(Arrays.asList("foo", "bar"));
s.remove("foo");
int n = s.size();
// n == 1

Objective-C

developer.apple.com

- (void)removeObject:(id)object
NSMutableSet *s = [NSMutableSet setWithObjects:@"foo", @"bar", nil];
[s removeObject:@"foo"];
int n = s.count;
// n == 1

Python

s = set(["foo", "bar"])
s.remove("foo")
n = len(s)
# n == 1

Ruby

Ruby-Doc.org

require 'set'
 
s = Set.new(['foo', 'bar'])
s.delete('foo')
n = s.length
# n == 1

Swift

var s : Set<String> = ["foo", "bar"]
s.remove("foo")
let n = s.count
// n == 1
Personal tools