Ios-foundation Frame

Source: Internet
Author: User

These things, such as the use of the time to check the data on the line, with more, naturally remember, probably a bit

Foundation Framework

It is the foundation of iOS application development, there are more than 80 commonly used frameworks, and foundation is the foundation of all of them, providing many basic object classes and data types, such as numbers, strings, arrays, collections, dictionaries, processing date times, automated memory management, files, archives, Processing geometry data structures and so on. It provides basic data services for all applications,

The foundation is independent of the interface and is prefixed with NS.

Some classes in the foundation are supported only by Mac OS and not by iOS.

In Mac Ox x Cocoa the Total Reference Foundation framework and the application Kit framework, while Cocoa touch refers to the foundation and Uikit framework.

Structures commonly used in Foundation:

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

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

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}     // represents 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)

//  no //Nsrange r2 = {. Location = 2,. length = 4};   // Don't

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

Nsrange R3 = Nsmakerange (24//  Master

So in engineering, a way to find the position of a string is often used

    @" I love OC " ;         // find a string in the range of STR, a very common method, important!     // If you can't find it, 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;   struct Cgpoint Cgpoint;

And also:

struct _nspoint {    cgfloat x;    CGFloat y;} Nspoint;

Continue to view:

typedef cgfloat_type CGFloat;

Continue to view:

Double

The essence is double type

Similar to Nsrange structural body

Cgpoint P1 = Nsmakepoint (ten= cgpointmake);   most commonly used

Nssize \ Cgsize

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

    nssize S1 = cgsizemake (+);     = Nsmakesize (+);     = Nsmakesize (a);

CGRect Synthetic representation points and dimensions

    CGRect r1 = CGRectMake (00);     = {{00}, {+}};     = {p1, s2};

The premise of using Cgpointzero is to add the Coregraphics framework

CGRect R4 = {Cgpointzero, cgsizemake (+)};

Indicates the origin.

Cgpointzero = = Cgpointmake (00);

convert struct to String

    // nsstring *str = Nsstringfrompoint (p1);     // nsstring *str = nsstringfromsize (S3);      *str = nsstringfromrect (r1);    NSLog (@ "%@", str);     // NSLog (@ "x=%f, y=%f, width=%f, height=%f", r1.origin.x, R1.ORIGIN.Y, R1.size.width, r1.size.height);

The premise of using these functions, such as Cgpointequaltopoint, Cgrectcontainspoint, is to add the Coregraphics framework

Compares two points for the same (x, y)

BOOL B = Cgpointequaltopoint (Cgpointmake (ten), Cgpointmake (Ten));

Compare two rectangles

Cgrectequaltorect (< #CGRect Rect1#>, < #CGRect rect2#>)

Compare two locations

Cgsizeequaltosize (< #CGSize Size1#>, < #CGSize size2#>)

X (40, 90), see if the rectangle contains a point

BOOL b2 = Cgrectcontainspoint (cgrectmake), Cgpointmake (  $ )); NSLog (@ "%d", B2);
 

Ios-foundation Frame

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.