今年夏天,Apple 发布了一个信息丰富的示例应用程序,介绍如何使用 SwiftUI 中的 Core Data、CloudKit 和 UICloudSharingController 在 iCloud 用户之间共享对象。
\n但是,当用于带有 CloudKit 的 Core Data 时,使用 UICloudSharingController 添加更多参与者似乎不起作用。
\nMRE:
\n请参阅上面链接的 Apple 示例应用程序。\n使用其他示例应用程序时也会出现同样的问题,例如来自 RayW 的示例应用程序。\n该问题不会出现在使用纯 CloudKit 的示例中,例如Apple 的这个示例应用程序。
再生产:
\n期望:
\n我们可以使用 UICloudSharingController 通过消息、邮件或其他平台添加新参与者。该链接将在所有设备上正确显示。
现实:
\n在 iOS16+ 上,尝试通过消息共享会使用“协作”框架并导致警告:“发生错误。无法开始协作”(参见图 1)。出现控制台警告(见下文)。触发此错误会中断任何进一步的共享 - 现在也无法为 Mail 和其他平台创建链接(参见图 2)。此外,如果第一次尝试成功,则该链接不会在接收设备上正确显示(参见图 3)。
经过进一步测试,UICloudSharingController 在 iOS15 中也失败了 - 它只是关闭工作表,而不是在紧凑型设备上发出警报。显示现有共享时,UICloudSharingController 肯定会出现问题。
\n …我想在工作表中有一个系统/浅色/深色模式选择器以及其他设置。
选择不同的方案确实会正确更改 ContentView 中的 UI(工作表后面),但工作表本身保留旧方案,必须关闭并再次打开。
我究竟做错了什么?
例子:
import SwiftUI
struct ContentView: View {
@EnvironmentObject var viewManager: ViewManager
@State var showSettingsSheet = false
var body: some View {
NavigationView {
List {
Text("Some content 1")
Text("Some content 2")
}
.toolbar {
ToolbarItem {
Button(action: {
showSettingsSheet.toggle()
}){
Image(systemName: "gearshape.fill")
}
.sheet(isPresented: $showSettingsSheet){SettingsSheet()}
}
}
}
.preferredColorScheme(viewManager.colorScheme == "Light" ? .light : viewManager.colorScheme == "Dark" ? .dark : nil)
}
}
Run Code Online (Sandbox Code Playgroud)
struct SettingsSheet: View {
@Environment (\.presentationMode) var presentationMode
@EnvironmentObject var viewManager: …
Run Code Online (Sandbox Code Playgroud) 在开发 SwiftUI 应用程序时,我的控制台日志充满了以下噪音:
2022-03-19 11:13:21.522465+0100 AppName[AppNo] [IconManager] No config pack found for key Localized Chn Icons
2022-03-19 11:13:21.526159+0100 AppName[AppNo] [IconManager] No config pack found for key Localized Chn Icons
2022-03-19 11:13:21.527175+0100 AppName[AppNo] [IconManager] No config pack found for key Localized Poi INTL PostOfficeHorn Icons
2022-03-19 11:13:21.527227+0100 AppName[AppNo] [IconManager] No config pack found for key Localized Poi INTL PostOfficeHorn Icons
2022-03-19 11:13:21.527764+0100 AppName[AppNo] [IconManager] No config pack found for key Localized Poi CZE Icons
2022-03-19 11:13:21.527817+0100 AppName[AppNo] [IconManager] No config pack …
Run Code Online (Sandbox Code Playgroud) 我想显示一个列表,其中每一行都显示不透明动画并且延迟逐渐增加。因此,第一行应在 0.1 秒后出现,第二行应在 0.3 秒后出现,第三行应在 0.5 秒后出现,依此类推。
我尝试了以下方法,但它不起作用,因为所有行都会同时出现并且没有动画。
任何提示将不胜感激!
struct GuideListView: View {
@State var showListItems = false
@State var animationDelay = 0.1
// definitions of viewRouter, data etc.
var body: some View {
VStack {
// other items, navLink etc.
List {
ForEach(data) { item in
Button(action: {
// navigation action
}, label: {
RowView(item: item)
})
.opacity(showListItems ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(animationDelay), value: showListItems)
.onAppear{
animationDelay = animationDelay + 0.2
}
} //: ForEach
} //: List …
Run Code Online (Sandbox Code Playgroud) 根据 Apple 文档,这应该有效:
\n\n\n如果您使用字符串变量而不是字符串文字来初始化文本视图,则该视图会触发 init( :) 初始值设定项,因为它假定您在这种情况下不需要本地化。如果您确实想要本地化存储在字符串变量中的值,您可以选择通过首先从字符串变量创建 LocalizedStringKey 实例来调用 init( :tableName:bundle:comment:) 初始值设定项:
\nText(LocalizedStringKey(someString)) // 本地化
\nsomeString
.https://developer.apple.com/documentation/swiftui/text/init(_:表名:bundle:comment:)
\n
这里也推荐: https: //www.ibabbleon.com/swiftui_localization_tutorial.html
\n然而,至少就我而言,事实并非如此。在以下示例中,仅导出“Some content 1”值以进行本地化。
\nstruct ContentView: View {\n let text = "Some content 2"\n var body: some View {\n Text("Some content 1", comment: "This text is exported for localization, as expected.")\n .padding()\n Text(LocalizedStringKey(text), comment: "This text is not exported for localization, which is not expected behaviour.")\n .padding()\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n在应用程序设置中,“使用编译器提取 swift …