Dan Rosenstark
Dan Rosenstark

Reputation: 69757

CGSizeMake Doesn't Work for Constant

Is there a way to do this type of thing?

static const CGSize maxPageSize = CGSizeMake(460, 651);

This is illegal because "Initializer element is not a compile-time constant."

I could use individual floats, of course, but I'm wondering if there's a way to do this.

Upvotes: 14

Views: 9945

Answers (2)

prashant
prashant

Reputation: 1920

CGSize

A structure that contains width and height values.

struct CGSize {
   CGFloat width;
   CGFloat height;
};
typedef struct CGSize CGSize;

Fields width A width value. height A height value.

const CGSize CGSizeZero;

e.g

static const CGSize pageSize = {320, 480};

Upvotes: 1

Matt Wilding
Matt Wilding

Reputation: 20153

Since CGSize is just a simple C-struct:

struct CGSize {
  CGFloat width;
  CGFloat height;
};
typedef struct CGSize CGSize;

You can use an initializer list:

static const CGSize maxPageSize = {460, 651};

Upvotes: 48

Related Questions