Nsset and nsmutableset-by Wu Shulei

Source: Internet
Author: User

1, the use of Nsset

[Nsset setwithset: (Nsset *) set]; Constructs [Nsset setwitharray: (Nsarray *) array] with another set object, constructs [Nsset setwithobjects: ...] with an array, creates a collection object, and initializes the values in the collection, with the nil flag required at the end. [Set Count]; Get the length of this binding object. [Set Containsobject: ...]: Determines whether an incoming object exists in this collection and returns a bool value. [Set Objectenumerator]: puts the collection into the iterator. [Enumerator Nextobject]: Gets the next node data in the iterator, using the while traversal of the iterator to traverse the objects in the collection object. [Set Isequaltoset:objset]: Determines whether two sets are exactly equal and returns a bool value. [Set Issubsetofset:objset]: Determines whether all data in the collection is equal to the Objeset collection, and returns the bool value. [Set allobjects];
Nsset *Set= [Nsset setwithobjects:@" -",@" Age",@"Zhang San",@"name",@"male", nil]; Nsset*set1 = [Nsset setwithobjects:@" -",@" Age",@"Zhang San",@"name",@"male",@"Sex", nil]; NSLog (@"Set Count:%lu", [SetCount]); //determine if an age string is included        if([SetContainsobject:@" Age"]) {NSLog (@"set contains age"); }        //determine if set equals Set1        if([SetIsequaltoset:set1]) {NSLog (@"set equals Set1"); }        //determines whether a set is a subset of Set1        if([SetIssubsetofset:set1]) {NSLog (@"Set Issubsetofset Set1"); }        //get all Set objectsNsarray *array = [SetAllObjects]; NSLog (@"array:%@", array); //Iterative TraversalNsenumerator *enumerator = [SetObjectenumerator];  for(NSObject *Object inchenumerator) {NSLog (@"objects in Set1:%@",Object); }

2, the use of Nsmutableset

Nsmutableset inherits Nsset, which can use the Nsset method.

[Nsmutableset Setwithcapacity:6]: Creates a Mutable collection object, and the initialization length is 6.

[Set Addobject:obj]: Adds an object dynamically to the collection.

[Set Removeobject:obj]: Deletes an object from the collection.

[Set removeallobjects]: Deletes all objects in the collection.

[Set Unionset:obj]: Adds all the data of an obj collection to the collection.

[Set Minusset:obj]: Removes all data from an obj collection to the collection.

[Set Intersectset]: Removes all data from the collection that does not contain the Obj collection.
Nsmutableset *muset = [Nsmutableset setwithcapacity:6]; [Muset AddObject:@"Object 1"]; Nsset*Set= [Nsset setwithobjects:@"Object 2",@"Object 3",@"bitten by a penguin.", nil]; //adding set Data[Muset Unionset:Set];  for(NSObject *Object inchMuset) {NSLog (@"All nuset:%@",Object); } Nsset*set1 = [Nsset setwithobjects:@"Object 2",@"Object 3", nil]; //Delete total data containing Set1 in Muset[Muset Minusset:set1];  for(NSObject *Object inchMuset) {NSLog (@"After minusset:%@",Object);

The collection is less used, but it still needs to be used!

Nsset and nsmutableset-by Wu Shulei

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.