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:
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.
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.
At code level it will be seen as two lines of:
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
in your project.pbxproj file.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With