Search code examples
iosobjective-cccgrect

How to create a file with functions in C and access them from my application?


I would like to "extend" CGGeometry but that is not a class. So I have to create external functions I can use from my App.

I have created a header file with a code like this:

#ifndef CGGeometry_Extensions_h
#define CGGeometry_Extensions_h


CGRect CGRectFromCenterAndSize(CGPoint center, CGSize size) {
  CGFloat width = [size width];    //1
  CGFloat height = [size height];  //2
  CGFloat x = center.x - width;
  CGFloat y = center.y - height;
  return CGRectMake(x, y, width, height);
}

#endif /* CGGeometry_Extensions_h */

I have compiling errors on lines marked with \\1 and \\2

Bad Receiver type 'CGSize' (aka struct CGSize)

what is wrong?


Solution

  • I think these codes are syntax error in C:

      CGFloat width = [size width];    //1
      CGFloat height = [size height];  //2
    

    I am not sure how CGFloat define, Will it should be

      CGFloat width = size.width    
      CGFloat height = size.height