IOS review note 13: Common struct
Both must contain the header file of Foundation. h.
CG: CoreGraphics framework for short. The content starting with CG is declared in the Foundation framework, but not implemented.
NS: NextStep
1. Range of nsange
1 Definition:
typedef struct _NSRange{NSUInteger location;NSUInteger length;}NSRange;
2 example:
NSString * str = @ "I love OC"; // nsange * rg = {2, 4}; // nsange * rg = {. location = 2 ,. length = 4}; nsange * rg = NSMakeRange (2, 4); nsange * r = [str rangOfString: @ "love"]; // "love" character, starting from 2, the length is 4 nsange p0 = nsangezero; // determines whether it is equal and returns the bool Value
Two NSPoint/CGPoint
1 Definition:
CGFloat: doubletypedef _ NSPoint {CGFloat x; CGFloat y;} NSPoint; typedef NSPoint CGPoint;
CGPoint cross-platform
2 example:
// CGPoint p = CGMakePoint (10, 10); CGPoint p = CGPointMake (10, 10); NSLog (@ "% @", NSStringFromPoint (p )); CGPoint p0 = CGPointZero; CGPointEqualToPoint (p, p0); // returns the bool value if it is equal.
Three NSSize/CGSize
1 Definition:
typedef struct _NSSize{CGFloat x;CGFloat y;}NSSize;typedef NSSize CGSize;
2 example:
CGSize sz = CGSizeMake (10, 10); NSLog (@ "% @", NSStringFromSize (sz); CGSize sz0 = CGSizeZero; CGSizeEqualToSize (sz, sz0 ); // determine whether the values are equal and return the bool Value
Four NSRect/CGRect rectangle
1 Definition
typedef struct _NSRect{NSPoint origin;NSSize size;}NSRect;typedef NSRect CGRect;
2 Examples
CGRect r = CGRectMake (0, 0,100, 50); NSLog (@ "% @", NSStringFromRect (r); CGRect r0 = CGRectZero; CGRectEqualToRect (r, r0 ); // determine whether the bool value is equal. Return the bool value CGRectContainsPoint (r, p). // determine whether the rectangle contains vertices and return the bool value.