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.