
import SwiftUI
import WhatsNewKit
struct ContentView : View {
var body : some View {
NavigationView {
// ...
}
. whatsNewSheet ( )
}
} Apple의 Swift 패키지 관리자를 사용하여 통합하려면 다음을 Package.swift 에 종속성으로 추가하십시오.
dependencies: [
. package ( url : " https://github.com/SvenTiigi/WhatsNewKit.git " , from : " 2.0.0 " )
] 또는 Xcode 프로젝트로 이동 한 다음 Swift Packages 선택하고 "+"아이콘을 클릭하고 WhatsNewKit 을 검색하십시오.
WhatsNewKit이 작동하는 것을 보려면 예제 응용 프로그램을 확인하십시오. Example/Example.xcodeproj 열고 "예제"체계를 실행하기 만하면됩니다.

WhatsNewView 를 수동으로 제시하려면 sheet(whatsNew:) 수정자를 사용할 수 있습니다.
struct ContentView : View {
@ State
var whatsNew : WhatsNew ? = WhatsNew (
title : " WhatsNewKit " ,
features : [
. init (
image : . init (
systemName : " star.fill " ,
foregroundColor : . orange
) ,
title : " Showcase your new App Features " ,
subtitle : " Present your new app features... "
) ,
// ...
]
)
var body : some View {
NavigationView {
// ...
}
. sheet (
whatsNew : self . $whatsNew
)
}
} 자동 프레젠테이션 모드를 사용하면 Swiftui 환경을 통해 새로운 기능을 간단히 선언 할 수 있으며 WhatsNewKit은 해당 WhatsNewView 제시하기 위해주의를 기울입니다.
먼저 WhatsNewView 제시 해야하는보기에 .whatsNewSheet() 수정자를 추가하십시오.
struct ContentView : View {
var body : some View {
NavigationView {
// ...
}
// Automatically present a WhatsNewView, if needed.
// The WhatsNew that should be presented to the user
// is automatically retrieved from the `WhatsNewEnvironment`
. whatsNewSheet ( )
}
} .whatsNewSheet() 수정자는 WhatsNewEnvironment 를 사용하여 현재 버전에 대해 사용자에게 제시 해야하는 옵션 whatsnew 객체를 검색하는 것입니다. 따라서 environment 수정자를 통해 WhatsNewEnvironment 쉽게 구성 할 수 있습니다.
extension App : SwiftUI . App {
var body : some Scene {
WindowGroup {
ContentView ( )
. environment (
. whatsNew ,
WhatsNewEnvironment (
// Specify in which way the presented WhatsNew Versions are stored.
// In default the `UserDefaultsWhatsNewVersionStore` is used.
versionStore : UserDefaultsWhatsNewVersionStore ( ) ,
// Pass a `WhatsNewCollectionProvider` or an array of WhatsNew instances
whatsNewCollection : self
)
)
}
}
}
// MARK: - App+WhatsNewCollectionProvider
extension App : WhatsNewCollectionProvider {
/// Declare your WhatsNew instances per version
var whatsNewCollection : WhatsNewCollection {
WhatsNew (
version : " 1.0.0 " ,
// ...
)
WhatsNew (
version : " 1.1.0 " ,
// ...
)
WhatsNew (
version : " 1.2.0 " ,
// ...
)
}
} WhatsNewEnvironment 현재 버전에 대해 사용자에게 제시 해야하는 일치하는 WhatsNew 객체를 결정하기 위해주의를 기울입니다.
이전 예제에서 볼 수 있듯이 WhatsNewVersionStore 지정하고 WhatsNewCollection 을 제공하여 WhatsNewEnvironment 초기화 할 수 있습니다.
// Initialize WhatsNewEnvironment by passing an array of WhatsNew Instances.
// UserDefaultsWhatsNewVersionStore is used as default WhatsNewVersionStore
let whatsNewEnvironment = WhatsNewEnvironment (
whatsNewCollection : [
WhatsNew (
version : " 1.0.0 " ,
// ...
)
]
)
// Initialize WhatsNewEnvironment with NSUbiquitousKeyValueWhatsNewVersionStore
// which stores the presented versions in iCloud.
// WhatsNewCollection is provided by a `WhatsNewBuilder` closure
let whatsNewEnvironment = WhatsNewEnvironment (
versionStore : NSUbiquitousKeyValueWhatsNewVersionStore ( ) ,
whatsNewCollection : {
WhatsNew (
version : " 1.0.0 " ,
// ...
)
}
) 또한 WhatsNewEnvironment 패치 버전의 폴백이 포함되어 있습니다. 예를 들어, 사용자가 버전 1.0.1 설치하고 버전 1.0.0 의 WhatsNew 만 선언 한 경우 환경은 자동으로 버전 1.0.0 으로 자동으로 떨어지고 필요한 경우 WhatsNewView 를 사용자에게 제시합니다.
WhatsNewEnvironment 의 동작을 더욱 사용자 정의하려면 쉽게 서브 클래스를 클래스하고 whatsNew() 함수를 무시할 수 있습니다.
class MyCustomWhatsNewEnvironment : WhatsNewEnvironment {
/// Retrieve a WhatsNew that should be presented to the user, if available.
override func whatsNew ( ) -> WhatsNew ? {
// The current version
let currentVersion = self . currentVersion
// Your declared WhatsNew objects
let whatsNewCollection = self . whatsNewCollection
// The WhatsNewVersionStore used to determine the already presented versions
let versionStore = self . whatsNewVersionStore
// TODO: Determine WhatsNew that should be presented to the user...
}
} WhatsNewVersionStore 는 사용자에게 제시된 버전을 저장 및 검색하는 프로토콜 유형입니다.
let whatsNewVersionStore : WhatsNewVersionStore
// Save presented versions
whatsNewVersionStore . save ( presentedVersion : " 1.0.0 " )
// Retrieve presented versions
let presentedVersions = whatsNewVersionStore . presentedVersions
// Retrieve bool value if a given version has already been presented
let hasPresented = whatsNewVersionStore . hasPresented ( " 1.0.0 " )WhatsNewkit은 세 가지 사전 정의 된 구현과 함께 제공됩니다.
// Persists presented versions in the UserDefaults
let userDefaultsWhatsNewVersionStore = UserDefaultsWhatsNewVersionStore ( )
// Persists presented versions in iCloud using the NSUbiquitousKeyValueStore
let ubiquitousKeyValueWhatsNewVersionStore = NSUbiquitousKeyValueWhatsNewVersionStore ( )
// Stores presented versions in memory. Perfect for testing purposes
let inMemoryWhatsNewVersionStore = InMemoryWhatsNewVersionStore ( ) 영역 또는 핵심 데이터와 같은 사용자 관련 설정을 저장하는 특정 구현이 이미있는 경우 기존 구현을 WhatsNewVersionStore 프로토콜에 쉽게 채택 할 수 있습니다.
NSUbiquitousKeyValueWhatsNewVersionStore 를 사용하는 경우 Xcode 프로젝트의 "서명 및 기능"섹션에서 iCloud 키 값 저장 기능을 활성화하십시오.

다음 섹션에서는 주어진 앱 버전의 새로운 기능을 설명하기 위해 WhatsNew Struct를 초기화 할 수있는 방법을 설명합니다.
let whatsnew = WhatsNew (
// The Version that relates to the features you want to showcase
version : " 1.0.0 " ,
// The title that is shown at the top
title : " What's New " ,
// The features you want to showcase
features : [
WhatsNew . Feature (
image : . init ( systemName : " star.fill " ) ,
title : " Title " ,
subtitle : " Subtitle "
)
] ,
// The primary action that is used to dismiss the WhatsNewView
primaryAction : WhatsNew . PrimaryAction (
title : " Continue " ,
backgroundColor : . accentColor ,
foregroundColor : . white ,
hapticFeedback : . notification ( . success ) ,
onDismiss : {
print ( " WhatsNewView has been dismissed " )
}
) ,
// The optional secondary action that is displayed above the primary action
secondaryAction : WhatsNew . SecondaryAction (
title : " Learn more " ,
foregroundColor : . accentColor ,
hapticFeedback : . selection ,
action : . openURL (
. init ( string : " https://github.com/SvenTiigi/WhatsNewKit " )
)
)
) WhatsNew.Version 은 앱에 특정 기능을 도입 한 버전을 지정합니다.
// Initialize with major, minor, and patch
let version = WhatsNew . Version (
major : 1 ,
minor : 0 ,
patch : 0
)
// Initialize by string literal
let version : WhatsNew . Version = " 1.0.0 "
// Initialize WhatsNew Version by using the current version of your bundle
let version : WhatsNew . Version = . current ( ) WhatsNew.Title 은 기능 위에 렌더링되는 제목 텍스트를 나타냅니다.
// Initialize by string literal
let title : WhatsNew . Title = " Continue "
// Initialize with text and foreground color
let title = WhatsNew . Title (
text : " Continue " ,
foregroundColor : . primary
)
// On >= iOS 15 initialize with AttributedString using Markdown
let title = WhatsNew . Title (
text : try AttributedString (
markdown : " What's **New** "
)
) WhatsNew.Feature 앱의 특정 기능을 설명하고 일반적으로 이미지, 제목 및 자막으로 구성됩니다.
let feature = WhatsNew . Feature (
image : . init (
systemName : " wand.and.stars "
) ,
title : " New Design " ,
subtitle : . init (
try AttributedString (
markdown : " An awesome new _Design_ "
)
)
) WhatsNew.PrimaryAction 은 제시된 WhatsNewView 무시하는 데 사용되는 기본 버튼의 동작을 구성 할 수 있습니다.
let primaryAction = WhatsNew . PrimaryAction (
title : " Continue " ,
backgroundColor : . blue ,
foregroundColor : . white ,
hapticFeedback : . notification ( . success ) ,
onDismiss : {
print ( " WhatsNewView has been dismissed " )
}
)참고 : HapticFeedback은 iOS에서만 실행됩니다
WhatsNew.PrimaryAction 인스턴스 WhatsNew 초기화 할 때 WhatsNew.SecondaryAction .
// SecondaryAction that presents a View
let secondaryActionPresentAboutView = WhatsNew . SecondaryAction (
title : " Learn more " ,
foregroundColor : . blue ,
hapticFeedback : . selection ,
action : . present {
AboutView ( )
}
)
// SecondaryAction that opens a URL
let secondaryActionOpenURL = WhatsNew . SecondaryAction (
title : " Read more " ,
foregroundColor : . blue ,
hapticFeedback : . selection ,
action : . open (
url : . init ( string : " https://github.com/SvenTiigi/WhatsNewKit " )
)
)
// SecondaryAction with custom execution
let secondaryActionCustom = WhatsNew . SecondaryAction (
title : " Custom " ,
action : . custom { presentationMode in
// ...
}
)참고 : HapticFeedback은 iOS에서만 실행됩니다
WhatsNewKit을 사용하면 제시된 WhatsNewView 의 레이아웃을 다양한 방식으로 조정할 수 있습니다.
가장 간단한 방법은 WhatsNew.Layout.default 인스턴스를 변형시키는 것입니다.
WhatsNew . Layout . default . featureListSpacing = 35자동 프리젠 테이션 스타일을 사용하는 경우 WhatsNewenVironment를 초기화 할 때 기본 레이아웃을 제공 할 수 있습니다.
. environment (
. whatsNew ,
. init (
defaultLayout : WhatsNew . Layout (
showsScrollViewIndicators : true ,
featureListSpacing : 35
) ,
whatsNew : self
)
) 또는 WhatsNewView를 자동으로 또는 수동으로 제시 할 때 WhatsNew.Layout 을 통과 할 수 있습니다.
. whatsNewSheet (
layout : WhatsNew . Layout (
contentPadding : . init (
top : 80 ,
leading : 0 ,
bottom : 0 ,
trailing : 0
)
)
) . sheet (
whatsNew : self . $whatsNew ,
layout : WhatsNew . Layout (
footerActionSpacing : 20
)
) UIKit 또는 AppKit 사용할 때 WhatsNewViewController 를 사용할 수 있습니다.
let whatsNewViewController = WhatsNewViewController (
whatsNew : WhatsNew (
version : " 1.0.0 " ,
// ...
) ,
layout : WhatsNew . Layout (
contentSpacing : 80
)
) WhatsNewViewController 제시하려면 WhatsNew 인스턴스의 버전이 제시되지 않은 경우에만 편리한 실패 가능한 이니셜 라이저를 사용할 수 있습니다.
// Verify WhatsNewViewController is available for presentation
guard let whatsNewViewController = WhatsNewViewController (
whatsNew : WhatsNew (
version : " 1.0.0 " ,
// ...
) ,
versionStore : UserDefaultsWhatsNewVersionStore ( )
) else {
// Version of WhatsNew has already been presented
return
}
// Present WhatsNewViewController
// Version will be automatically saved in the provided
// WhatsNewVersionStore when the WhatsNewViewController gets dismissed
self . present ( whatsNewViewController , animated : true )