I build a ScreenSaver using swift 4.2 but it doesn't work

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)

Post not yet marked as solved Up vote post of SKDawkins Down vote post of SKDawkins
4.7k views

Replies

I hate to be the bearer of bad news but building a screen saver in Swift is not supported. You can read the posts in this thread for an explanation as to why.

If you’re just getting started with Swift on the Mac, my recommendation is that you choose a different project. For example, if you have a fabulous idea for a screen saver, you could temporarily host that code in Mac app until Swift and screen savers kiss and make up.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
  • That thread link is broken.

Add a Comment