Structures commonly used in ios-foundation:

Source: Internet
Author: User

Many common structure types are defined in the foundation to simplify our daily development

Nsrange (location length) is used to denote the range, in a variety of cases

Nspoint \ Cgpoint(the latter used in development)

Nssize \ Cgsize

Nsrect \ CGRect (cgpint cgsize)

Nsrange prototypes

typedef struct _nsrange {    Nsuinteger location;    Nsuinteger length;} Nsrange;

This is the form of the internal structure of the NSRANGE structure, two members, one length, one position. You do not need to use the struct keyword like C again, and the data type of the member is Nsuinteger

typedef unsigned long Nsuinteger;

An alternative to an unsigned long type is to know that it is a positive number for an integral type.

Use the Nsrange structure to represent a range, such as:

    {1, 2, 3, 4, 5}    //Indicates the range of 3,4,5, location=2,length=3

Counting starts from 0, the 2nd position starts with a length of 3.

The range of love within the string, starting at 0, counting the 2nd position with a length of 4

@ "I love OC";

The following two formulations are not recommended (the former is too readable and the latter too verbose)

Nsrange R1 = {2, 4}; No//nsrange r2 = {. Location = 2,. length = 4};//

To master the following wording, the above two do not use

Nsrange R3 = Nsmakerange (2, 4); Master

A method used to find the position of a string in a project.

    NSString *str = @ "I love oc";        Find a string in the range of STR, a very common method, important!    //If not found, Length=0,location=nsnotfound==-1    Nsrange range = [str rangeofstring:@ "Java"];    NSLog (@ "loc =%ld, length=%ld", Range.location, range.length); 

Because location is an unsigned long type, 1 prints out a large positive number. Of course, if the highest bit is represented by a negative number, that is, Nsnotfound is printed according to the (signed) integer, then-1.

Nspoint \ Cgpoint

Point structure

struct cgpoint {  cgfloat x;  CGFloat y;}; typedef struct CGPOINT cgpoint;

And also:

typedef cgpoint NSPOINT;TYPEDEF struct _nspoint {    cgfloat x;    CGFloat y;} Nspoint;

Continue to view:

typedef cgfloat_type CGFloat;

Continue to view:

#define CGFLOAT_TYPE Double

The essence is double type

Similar to Nsrange structural body

Cgpoint P1 = Nsmakepoint (ten); Nspoint P2 = cgpointmake (20, 20);//most commonly used

Nssize \ Cgsize

Represents the height, width size of the structure, associative memory.

    nssize S1 = cgsizemake (+);    Nssize s2 = nsmakesize (+);    Cgsize s3 = Nsmakesize (a); 

CGRect represents rectangular dimensions

    CGRect r1 = CGRectMake (0, 0,.);    CGRect r2 = {{0, 0}, {$,n}};    CGRect R3 = {p1, s2}; 

We can see that the common structure in the foundation framework has a corresponding make method to create, which is our more commonly used in the future operations;

There is also a Nsstringfromxx method for string conversion, which is convenient for us to debug. The above also mentions Nssize actually is cgsize,nsrect actually is cgrect.

Attention:

UI is the UI library for iOS, with the objective-c encapsulated
NS is the base library for OBJC
CG,CF is a library of the lower-level C language.
It can be understood that Uifont is a OBJC encapsulated Cgfont, easy to use.

Structures commonly used in ios-foundation:

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.