Reputation: 5993
struct CGSize {
CGFloat width;
CGFloat height;
};
typedef struct CGSize CGSize;
CGSize is an unadorned C struct and doesn't accept messages.
What are appropriate ways to (in my case) create a CGsize with its dimensions to be 0?
If I were working straight C, it would be a use case for calloc() or whatnot. What is the Objective-C idiom for this use case?
Upvotes: 0
Views: 190
Reputation: 108111
the specific case you can use
CGSize zeroSize = CGSizeZero;
CGSize zeroSize = (CGSize){ 0, 0 };
CGSize zeroSize = (CGSize){ .width = 0, .height = 0 };
CGSize zeroSize = CGSizeMake(0,0);
Keep in mind that many cases the frameworks such as Core Graphics and Core Foundation provide you with constants such as CGSizeZero
that you can use, so you generally don't need to dynamically initialize such structs with calloc
.
Upvotes: 4
Reputation: 22701
The easiest way to get one with 0 for both dimensions would be the constant, CGSizeZero
Another way would be CGSizeMake(0,0)
Upvotes: 2