Ios notes-NSSet

Source: Internet
Author: User

Ios notes-NSSet

//// Main. m // NSSet /// Created by Passer-by on 15-3-23. // Copyright (c) 2015 MAC. all rights reserved. // # import
 
  
Int main (int argc, const char * argv []) {@ autoreleasepool {/* comparison between NSSet and NSArray 1> commonalities * are set, multiple OC objects can be stored. * Only OC objects can be stored. Non-OC object types (basic data types: int, char, float, struct, and enumeration) cannot be stored, each has a variable subclass 2> difference * NSArray has a sequence, NSSet has no sequence */NSSet * set1 = [NSSet setWithObjects: @ "a", @ "B ", @ "c", @ "d", nil]; NSSet * set2 = [[NSSet alloc] initWithObjects: @ "1", @ "2", @ "3 ", nil]; NSArray * array = [NSArray arrayWithObjects: @ "a", @ "B", @ "c", nil]; NSSet * set3 = [NSSet setWithArray: array]; NSLog (@ "set1: % @", set1); NSLog (@ "set2: % @", set2); NSLog (@ "set3: % @", set3 ); // obtain the number of sets NSLog (@ "set1 count: % d", set1.count); // obtain all objects in the set in the form of arrays NSArray * allObj = [set2 allObjects]; NSLog (@ "allObj: % @", allObj); // obtain any object NSLog (@ "anyObj: % @", [set3 anyObject]); // whether an object NSLog is contained (@ "contains: % d", [set3 containsObject: @ "obj2"]); // whether the NSLog object in the specified set is included (@ "intersect obj: % d", [set1 intersectsSet: set3]); // whether the NSLog (@ "isEqual: % d ", [set2 isEqualToSet: set3]); // whether it is a subset NSLog (@" isSubSet: % d ", [set3 isSubsetOfSet: set1]); NSSet * set4 = [NSSet setWithObjects: @ "a", @ "B", nil]; NSArray * ary = [NSArray arrayWithObjects: @ "1", @ "2 ", @ "3", @ "4", nil]; NSSet * set5 = [set4 setByAddingObjectsFromArray: ary]; NSLog (@ "addFromArray: % @", set5 ); NSMutableSet * mutableSet1 = [NSMutableSet parameters: @ "1", @ "2", @ "3", nil]; NSMutableSet * mutableSet2 = [NSMutableSet setWithObjects: @ "", @ "2", @ "B", nil]; NSMutableSet * mutableSet3 = [NSMutableSet setWithObjects: @ "1", @ "c", @ "B", nil]; // The set element subtraction [mutableSet1 minusSet: mutableSet2]; NSLog (@ "minus: % @", mutableSet1); // only the equivalent element is left [mutableSet1 intersectSet: mutableSet3]; NSLog (@ "intersect: % @", mutableSet1); // merge the set [mutableSet2 unionSet: mutableSet3]; NSLog (@ "union: % @", mutableSet2 ); // Delete the specified Element [mutableSet2 removeObject: @ "a"]; NSLog (@ "removeObj: % @", mutableSet2); // delete all data [mutableSet2 removeAllObjects]; NSLog (@ "removeAll: % @", mutableSet2);} return 0 ;}
 

Related Article

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.