A C structure is a compound data type: it combines multiple data types into a single type, which can be passed around as a single entity and can be accessed by those names through the compound entity, using dot-notation. The iOS API has many commonly used structs.
For example, CGPoint is defined as follows:
struct CGPoint
{
CGFloat x;
CGFloat y;
};
typedef struct CGPoint CGPoint;
So we can write:
CGPoint myPoint;
myPoint.x = 4.3;
myPoint.y = 7.1;
Another iOS struct,
CGSize:
struct CGSize
{
CGFloat width;
CGFloat height;
};
typedef struct CGSize CGSize;
Put a CGPoint and a CGSize together and you’ve got a CGRect:
struct CGRect
{
CGPoint origin;
CGSize size;
};
typedef struct CGRect CGRect;
No comments:
Post a Comment