A brief introduction to nsindexset-

Source: Internet
Author: User

A brief introduction to nsindexset-
Remember the last time you used the method of deleting UITableView grouping

[TableView deletesections:[nsindexset indexsetwithindex:indexpath.section]withrowanimation: Uitableviewrowanimationleft];

Indeed, do not understand Nsindexset is what East! If you don't understand, look! Here, we have organized a common method. Master Bypass! Lots of pointers! 1. Nsindexset What is it?

Nsindexset is a collection of unsigned integers. The elements in the collection are immutable and non-repeatable. is often used as an index. As it is literally understood, it is called the Index collection.

2. Some common methods of nsindexset.

Class method:

Creates an empty collection of indexes.

+ (ID) indexset

Creates an index collection, based on the index value

+ (ID) Indexsetwithindex: (nsuinteger) index

Creates an index collection, based on a Nsrange object

+ (ID) Indexsetwithindexesinrange: (Nsrange) Indexrange

Example method:

Determines whether the indexed collection contains the established index values

-(BOOL) Containsindex: (nsuinteger) index

Determines whether the index collection contains the specified Indexset

-(BOOL) Containsindexes: (Nsindexset *) Indexset

Determines whether the index collection contains the specified Indexrange

-(BOOL) Containsindexesinrange: (Nsrange) Indexrange

Returns the number of indexes contained in an index collection

-(Nsuinteger) Count

Returns the number of indexes contained in the Indexrange

-(Nsuinteger) Countofindexesinrange: (Nsrange) Indexrange

Enumerates Nsindexset, performs a block operation, within the specified rang range, and uses the specified options method.

-(void) Enumerateindexesinrange: (nsrange) Range options: (nsenumerationoptions) opts Usingblock: (void (^) (Nsuinteger IDX, BOOL *stop)) block

If the range specified in the rang is not present in the Nsindexset to be enumerated, it is skipped.

Options parameters:

enum {

Nsenumerationconcurrent = (1UL << 0),

Nsenumerationreverse = (1UL << 1),

};

typedef Nsuinteger Nsenumerationoptions;

Nsenumerationconcurrent

During enumeration, each block is executed at the same time. The order in which the enumerations are completed is indeterminate.

Nsenumerationreverse

enumerated in reverse order.

Example:

Whether the thetwo contains Theone

BOOL iscontains1= [Thetwo Containsindexes:theone];

BOOL iscontains2= [Thetwo containsindex:1];

BOOL iscontains3= [Thetwo containsindex:9];

Whether the specified Nsmakerange is included in the Thetwo

BOOL iscontains4= [Thetwo containsindexesinrange:nsmakerange (0,5)];

int Thecount=[thetwo Count];

Traverse the Thetwo to execute the block method within the specified range, using the defined options

If the range specified in the range does not exist in the thetwo, it is skipped if it does not exist in the thetwo.

[Thetwo Enumerateindexesinrange:nsmakerange (0,8)

Options:nsenumerationreverse

usingblock:^ (Nsuinteger idx, BOOL *stop) {

NSLog (@ "-------%d", IDX);

NSLog (@ "%@", thetwo);

}];

Other methods, are similar, do not introduce each!

Hope to help you!

A brief introduction to nsindexset-

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.