Useful structure of objective-C

Source: Internet
Author: User
Document directory
  • Range
  • Geometric Data Type
Range

Typedef struct _ nsange {

Unsigned intlocation;

Unsigned intlength;

}Nsange;

This struct is used to indicate the range of related items, usually the character range in the string or the range of elements in the array. Location is used to indicate the starting position, and length indicates the number of elements contained in the range.

For example, there is a string "myname is Leo". The word "is" can be represented by location 8 and length 2.

 

Geometric Data Type

NspointIt represents a vertex (x, y) in the flute plane, and nssize is used to store the length and width, while nsrect is a rectangular data type, which is composed of vertices and sizes:

Typedef struct_nspoint {

Float X;

Float y;

} Nspoint;

 

NssizeUsed to store the length and width:

Typedef struct_nssize {

Float width;

Float height;

} Nssize;

 

NsrectA rectangle data type is provided, which is composed of vertices and sizes:

Typedef struct _ nsrect {

Nspoint origin;

Nssize size;

} Nsrect;

There are three ways to create these structIn the following example:

FirstDirectly assign values to Fields

Nsange range;

Range. Location = 8;

Range. Length = 2;

SecondMethod, aggregation structure Assignment Mechanism

Nsange range = {8, 2 };

ThirdUsing the cocoa shortcut function nsmakerange ()

Nsange range = nsmakerange (8, 2 );

You can use this function wherever you can.

Other structs also have corresponding shortcut functions: nsmakepoint (), nsmakesize, and nsmakerect.

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.