views:

130

answers:

3

Ok , I'm consfused about an error :

error: incompatible type for argument 1 of 'initWithFrame:'

This is what causes it:

operationLabel = [[NSTextField alloc] initWithFrame:CGRectMake(0, self.frame.size.height / 2 - (40 * 3), self.frame.size.width, 100)];

The definition is:

- (id)initWithFrame:(NSRect)frameRect;

So the first argument is NSRect, lets check it :

typedef CGRect NSRect;

How can it cause an error? They are same types named differently!

+2  A: 

Where did you get the typedef definition of NSRect? According to the docs NSRect is defined as follows:

typedef struct _NSRect {
      NSPoint origin;
      NSSize size;
} NSRect;

In other words, it’s a structure that looks just like CGRect (but not a plain typedef). There’s already something written about conversions between CGRect and NSRect.

zoul
+5  A: 

In addition to zoul's answer I thought I'd mention the two helper functions (macros?) by Apple (starting with 10.5):

NSRect NSRectFromCGRect(CGRect cgrect)
CGRect NSRectToCGRect(NSRect nsrect)
Eiko
+5  A: 

NSRect is the same type as CGRect if building for iOS, for a 64-bit Mac architecture, or a 32-bit Mac architecture with the macro NS_BUILD_32_LIKE_64 is defined as 1 at the command line or in a prefix header.

Or, to quote NSGeometry.h:

#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
Ahruman