Objective-C basic notes (7) common structures in Foundation

Source: Internet
Author: User

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);

Related Article

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.