7

I rewrote the screen saver template that Xcode generates from Objective-C into Swift and when I try to load it I get this message:

You cannot use the BlahBlah screensaver with this version of MacOSX.

Please contact the vendor to get a new version of the screen saver.

I'm currently running Mavericks. Does it mean that Swift screen savers only work in Yosemite, or not even there?

This is the Swift code I used to replace the Objetive-C one:

import Foundation
import ScreenSaver

class BlahBlahView : ScreenSaverView {
    convenience override init() {
        self.init(frame: CGRectZero, isPreview: false)
    }

    override init(frame: NSRect, isPreview: Bool) {
        super.init(frame: frame, isPreview: isPreview)

        setAnimationTimeInterval(1.0 / 30.0)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }


    override func startAnimation() {
        super.startAnimation()
    }

    override func stopAnimation() {
        super.stopAnimation()
    }

    override func drawRect(rect: NSRect) {
        super.drawRect(rect)
    }

    override func animateOneFrame() {

    }

    override func hasConfigureSheet() -> Bool {
        return false
    }

    override func configureSheet() -> NSWindow? {
        return nil
    }
}

These are my project settings:

enter image description here

This was originally an Objective-C project (there's no Swift Screensaver template) created on MacOSX 10.9 and the APIs I'm using, Screensaver, have existed for years.

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • Are you able to run any application on your OS X built with Swift outside of Xcode? – Brandon Buck Jan 09 '15 at 01:49
  • @BrandonBuck yes, I can. – Pablo Fernandez Jan 09 '15 at 02:03
  • @Rob I don't think I am using a 10.10 API. Would it even compile? I also couldn't find OS X Deployment Target, but it's the same as generated in the screensaver template. I didn't change anything there. I'll post a screenshot of the project settings. – Pablo Fernandez Jan 09 '15 at 02:48
  • Are you aware that your question was copied [there](http://apple.stackexchange.com/questions/166600/do-swift-screensavers-work-in-mac-os-x-before-yosemite)? – nicael Jan 09 '15 at 13:31

3 Answers3

14

To make a screensaver written in Swift work on Mac OS X 10.9, set the project setting Embedded Content Contains Swift Code to Yes.

enter image description here

At code level it will be seen as two lines of:

EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;

in your project.pbxproj file.

Juanjo Conti
  • 28,823
  • 42
  • 111
  • 133
2

Check the "OS X Deployment Target" for your project settings. It probably defaults to whatever OS your development machine is running, but double check. If you want to support 10.9, you have to change this setting to 10.9:

Deployment Target

Also (and this is more of an aside than anything else), regardless of what deployment target you use, you'll be allowed to include 10.10 API in your code. So you will also want to check the documentation for any of the Cocoa methods you're calling, to make sure they aren't specific to 10.10. Unless you're using a newer feature, this is fairly unlikely, but it's something to bear in mind, too.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • It's a Screensaver project created on 10.9, it didn't automagically changed to 10.10, so, it is and always been on 10.9. And the API I'm using, Screensaver, has existed for years. – Pablo Fernandez Jan 09 '15 at 11:24
1

Yes, Swift can run on OS X 10.9, but nothing earlier.

I've run into a few problems when porting my screen saver to Swift, mainly because the headers haven't been "modernized" to work with Objective C 2.0. As such, getters and setters aren't declared with @property.

MaddTheSane
  • 2,981
  • 24
  • 27
  • Do you have a small example of a Swift screensaver running in Mavericks? We still have to find or craft such code. – Pablo Fernandez Jan 10 '15 at 11:44
  • 2
    I haven't ported all of the UI settings to Swift (I'm going to try and improve it), but you can find my work here: https://github.com/MaddTheSane/NonsenseSaver/tree/swiftVersion Note that I'm targeting 10.10, but the biggest thing you need to worry about is having `EMBEDDED_CONTENT_CONTAINS_SWIFT` set to `YES` on your screen saver. – MaddTheSane Jan 11 '15 at 18:21