Henrietta Read
Henrietta Read

Reputation: 61

Xcode 8.0 beta 6, Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'CGSWindow' (aka 'int')

Seems I’m having some growing pains associated with the Xcode 8 beta and 64bit migration. In searching I’ve found a few related questions but not one specifically related to solving an ‘NSInteger' (aka 'long') to 'CGSWindow' (aka 'int') error.

Anyone here know how to get it going the right way round?

here's an example:

#import <Cocoa/Cocoa.h>

@interface CustomWindow : NSWindow {
    // this point is used in dragging to mark the initial click location
    NSPoint initialLocation;
}

@property (assign) NSPoint initialLocation;

@end


#import "CustomWindow.h"

#import <AppKit/AppKit.h>

@implementation CustomWindow

@synthesize initialLocation;

/*
 In Interface Builder, the class for the window is set to this subclass. Overriding the initializer
 provides a mechanism for controlling how objects of this class are created.
 */
- (id)initWithContentRect:(NSRect)contentRect
                styleMask:(NSUInteger)aStyle
                  backing:(NSBackingStoreType)bufferingType
                    defer:(BOOL)flag {

    // Using NSBorderlessWindowMask results in a window without a title bar.
    self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
    if (self != nil) {
        // Start with no transparency for all drawing into the window
        [self setAlphaValue:1.0];
        // Turn off opacity so that the parts of the window that are not drawn into are transparent.
        [self setOpaque:NO];
    }
    return self;
}

Upvotes: 0

Views: 307

Answers (1)

rmaddy
rmaddy

Reputation: 318804

Look at the documentation for NSWindow initWithContentRect:styleMask:backing:defer:. What is the type for the styleMask parameter?

- (instancetype)initWithContentRect:(NSRect)contentRect
                          styleMask:(NSWindowStyleMask)style
                            backing:(NSBackingStoreType)bufferingType
                              defer:(BOOL)flag;

So you need to change NSInteger to NSWindowStyleMask.

Now look at the documentation for NSWindowStyleMask. NSBorderlessWindowMask is not one of the listed values (it's an old, deprecated value). Use NSWindowStyleMaskBorderless.

So your code should be:

- (id)initWithContentRect:(NSRect)contentRect
                styleMask:(NSWindowStyleMask)aStyle
                  backing:(NSBackingStoreType)bufferingType
                    defer:(BOOL)flag {

    // Using NSBorderlessWindowMask results in a window without a title bar.
    self = [super initWithContentRect:contentRect styleMask: NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO];
    if (self != nil) {
        // Start with no transparency for all drawing into the window
        [self setAlphaValue:1.0];
        // Turn off opacity so that the parts of the window that are not drawn into are transparent.
        [self setOpaque:NO];
    }
    return self;
}

Upvotes: 1

Related Questions