Hello everyone, I'm a newer to Swift and macOS Development.
I want to build a ScreenSaver to start my macOS development life, but I have encountered some problems:
First I read this blog post Creating a macOS screensaver and create an Xcode project.
Then I create a
MainView.swift
file, delete all .h
and .m
files and write some code (codes shown below):import ScreenSaver
class MainView: ScreenSaverView {
override init?(frame: NSRect, isPreview: Bool) {
super.init(frame: frame, isPreview: isPreview)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func draw(_ rect: NSRect) {
super.draw(rect)
// Drawing code here.
NSColor.black.setFill()
bounds.fill()
NSColor.white.set()
let hello: String = "Hello world!"
hello.draw(at: NSPoint(x: 100.0, y: 100.0), withAttributes: nil)
}
}
I know I need to change the
Principal class
attribute to my swift class name MainView
and change the Always Embed Swift Standard Libraries
attribute to Yes
.Then I build my project and double-click
.saver
file to install it, but I got an error:You cannot use the ... screen saver with this version of OS X. Please contact the vendor to get a newer version of the screen saver.
Xcode version is Version 10.1 (10B61)
Swift version is 4.2
macOS version is 10.14.1 (18B75)