Logo

ChangelogKit

一个 Swift 包,旨在轻松展示你的 App 的新功能。

为什么

我需要开发一个视图来展示我的 App 的新功能,并且我不想依赖任何外部的东西。 这就是我开发 ChangelogKit 的原因。 请随意使用它,并按你的意愿修改。

信息

这是为 SwiftUI 开发的,最低 iOS 目标是 iOS 17。 代码使用 Xcode markup 进行了完整的文档记录。

如何使用

你需要创建一个 Changelog 对象,然后将其传递给 ChangelogView 来渲染。 一个更新日志由以下内容组成:

一个 Feature 具有以下属性:

还可以自定义视图的样式。 你可以查看 ChangelogView.Style 结构以了解更多信息。

还有一个方便的修饰符可以显示更新日志视图,使用 changelogView(changelog:style:show:onDismiss:)

示例

使用 ChangelogsCollectionProvider

ChangelogsCollectionProvider 是一个协议,是处理 ChangelogKit 的首选方式。 将其传递给 showCurrentChangelogIfNeeded(...) 修饰符将允许显示当前版本的正确更新日志。 Info.plist 文件中的版本和更新日志的 version 属性中的版本必须相同,才能使此机制正常工作。

这是一个如何使用它的示例

这是 ChangelogsProvider 结构。

struct ChangelogsProvider: ChangelogsCollectionProvider {
    
    var changelogs: [Changelog] {
        [
            Changelog.init(
                version: "1.0",
                features: [
                    Changelog.Feature(symbol: "star.fill", title: "Favorites", description: "Now you will be able to add every item to your favorites. This flag will be synced with iCloud."),
                    Changelog.Feature(symbol: "wand.and.stars", title: "Magic Restyle", description: "Using this feature you will be able to improve the quality of your pictures without having to know the details of photo editing.", color: .indigo),
                    Changelog.Feature(symbol: "bookmark.circle.fill", title: "Bookmarks", description: "Bookmark the best articles to have them available offline. You can tap on the archive to see all of your bookmarked articles.", color: .orange),
                ]
            ),
            
            Changelog.init(
                version: "1.2",
                features: [
                    Changelog.Feature(symbol: "star.fill", title: "Favorites", description: "Now you will be able to add every item to your favorites. This flag will be synced with iCloud."),
                    Changelog.Feature(symbol: "wand.and.stars", title: "Magic Restyle", description: "Using this feature you will be able to improve the quality of your pictures without having to know the details of photo editing.", color: .indigo),
                    Changelog.Feature(symbol: "bookmark.circle.fill", title: "Bookmarks", description: "Bookmark the best articles to have them available offline. You can tap on the archive to see all of your bookmarked articles.", color: .orange),
                ]
            )
        ]
    }
}

这是使用 provider 的视图。

struct ContentView: View {
    
    @State private var isChangelogShown: Bool = false

    var body: some View {
        Button("Hello") {
            isChangelogShown.toggle()
        }
        .showCurrentChangelogIfNeeded(
            isPresented: $isChangelogShown,
            provider: ChangelogsProvider()
        )
    }
}

初始化 ChangelogView 并使用它

这是如何渲染 ChangelogView 的。 这是代码

struct ContentView: View {
    
    @State private var isChangelogShown: Bool = false
    private let versioneOne: Changelog = Changelog.init(
        version: "1.0",
        features: [
            Changelog.Feature(symbol: "star.fill", title: "Favorites", description: "Now you will be able to add every item to your favorites. This flag will be synced with iCloud."),
            Changelog.Feature(symbol: "wand.and.stars", title: "Magic Restyle", description: "Using this feature you will be able to improve the quality of your pictures without having to know the details of photo editing.", color: .indigo),
            Changelog.Feature(symbol: "bookmark.circle.fill", title: "Bookmarks", description: "Bookmark the best articles to have them available offline. You can tap on the archive to see all of your bookmarked articles.", color: .orange),
        ]
    )

    var body: some View {
        Button("Hello") {
            isChangelogShown.toggle()
        }
        .sheet(isPresented: $isChangelogShown, changelog: versionOne)
    }
}

这就是 ChangelogView 的渲染效果。

Logo