LockSmith

LockSmith 是一个用于 Swift 可执行文件的系统锁管理器。

通过创建 LockSmith 实例,您可以锁定当前的 Swift 可执行文件,以防止其他实例运行。您还可以获得易于使用的文件和线程锁定机制,以帮助您使程序线程安全。

安装

可以通过 Swift Package Manager 进行安装

在您的 Package.swift 文件中,将以下行添加到您的依赖项中

.package(url: "https://github.com/Ponyboy47/LockSmith.git", from: "0.5.0")

用法

在您的 main.swift 中

import LockSmith

guard var processLock = LockSmith.singleton else {
    print("Another instance of your executable is already running")
}

// Your executable code here...

// This forces the destructor to be called, which unlocks any leftover locks (like the process lock)
processLock = nil

// the end

更多示例稍后提供...

许可

MIT