Objective-C basic notes (7) common structures in Foundation
1. nsange
Definition of nsange:
typedef struct _NSRange { NSUInteger location; NSUInteger length;} NSRange;
Use of nsanage:
NSRange range = NSMakeRange(8, 10); NSLog(@"location:%zi", range.location); NSLog(@"length:%zi", range.length); NSString *str = NSStringFromRange(range); NSLog(@"%@", str);
Ii. NSPoint
NSPoint definition:
Typedef CGPoint NSPoint;
struct CGPoint { CGFloat x; CGFloat y;};typedef struct CGPoint CGPoint;
NSPoint usage:
NSPoint p; p. x = 10; p. y = 10; p = NSMakePoint (11, 11); // common method: p = CGPointMake (12, 12); NSString * str = NSStringFromPoint (p ); NSLog (@ "% @", str );
Iii. NSSize
NSSize definition:
Typedef CGSize NSSize;
struct CGSize { CGFloat width; CGFloat height;};typedef struct CGSize CGSize;
NSSize usage:
NSSize s; s.width = 100.1; s.height = 100.3; s = NSMakeSize(12.3, 16.9); s = CGSizeMake(15.3, 19.2); NSString *str = NSStringFromSize(s); NSLog(@"%@", str);
Iv. NSRect
NSRect definition:
Typedef CGRect NSRect;
struct CGRect { CGPoint origin; CGSize size;};typedef struct CGRect CGRect;
NSRect usage:
NSRect r; //r.origin.x = 11; //r.origin.y = 13; r.origin = NSMakePoint(50, 50); r.size = NSMakeSize(60, 60); r = NSMakeRect(20, 20, 30, 30);