我目前正在开发我正在使用的 SwiftUI 应用程序SceneDelegate和AppDelegate. 我想知道我可以在生命周期的转换UIKit到SwiftUI一个地方有一个App结构,并用scenes等。
另外我想知道如何满足 CoreData 和 PersistentContainers 并将它们注入我们的环境。
我也曾经UIApplicationDelegateAdapter注射过,AppDelegate但@main它给了我错误
'main()' 仅在 iOS 14.0 或更新版本中可用
我@available (iOS 14.0, *)在开始时使用:
import SwiftUI
@available(iOS 14.0, *)
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Run Code Online (Sandbox Code Playgroud)
这样做,SceneDelegate代码去哪儿了。我仍然很困惑这种转换是如何进行的。我还没有看到 Apple 在他们的会议或任何事情中谈论过这个问题。帮助将不胜感激。
有没有办法在 swiftUI 中更改 tabView 指示器颜色?
这是我的代码
struct OnBoarding: View {
var body: some View {
TabView {
ForEach(0 ..< 3) { item in
VStack {
Image("discover")
.resizable()
.scaledToFit()
}
}
}
.tabViewStyle(PageIndexViewStyle(backgroundDisplayMode: Color ?))
}
}
struct OnBoarding_Previews: PreviewProvider {
static var previews: some View {
OnBoarding()
}
}
Run Code Online (Sandbox Code Playgroud)
我试过 tabViewStyle(PageIndexViewStyle(backgroundDisplayMode: Color ?)) 但无法解决它
下面的代码是我的观点,我正在处理核心数据,但它不断给我错误,即它在范围内找不到实体,但应用程序运行良好,一切都得到了保存和提取。
import SwiftUI
struct ContentView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(
entity: TestModelCoreData.entity(),
sortDescriptors: [
NSSortDescriptor(keyPath: \TestModelCoreData.name, ascending: false)
]
) var entities: FetchedResults<TestModelCoreData>
var body: some View {
VStack {
Text("Hello, world!").padding()
Button(action: {
let newEntry = TestModelCoreData(context: self.moc)
newEntry.name = "New name"
if self.moc.hasChanges {
try? self.moc.save()
}
}) {
Text("Add entry")
}
List(entities, id: \.self) { entity in
Text(entity.name ?? "Unknown")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView() …Run Code Online (Sandbox Code Playgroud) 在 Xcode12 beta4 或 beta5 中,我的项目遇到了失败。我可以在我的设备上运行该项目,但它没有在模拟器中运行。
我收到失败消息:ld: in /libwebrtc.a(dequantizemmx.o),为 iOS 模拟器构建,但链接为独立构建的目标文件,文件“libwebrtc.a”用于架构 x8664。
那么有谁知道应该在 Xcode 12.4 中调整哪些设置?
我将现有项目迁移到 Xcode12。我不得不VALID_ARCHS从构建设置中删除。并arm64为Excluded Architecture( Any iOS simulator SDK)添加。然后我就可以在 iOS14 模拟器上运行应用程序了。
但是现在在创建存档时它正在显示。
Any iOS Device(armv7, arm64)
Run Code Online (Sandbox Code Playgroud)
请参阅此屏幕截图。
在以前的Xcode中它显示 Generic iOS Device
这是否意味着应用程序将不支持所有 iOS 手机?
自从我更新到 Xcode 12 以来,我一直无法在使用 lldb 进行调试时在控制台中打印出变量。
print()按预期直接在 Swift 代码中使用语句输出到控制台。
控制台中的命令po "hi"如预期的那样向控制台输出“hi”。
po <variable_name>相反,尝试运行时总是输出以下行:
error: <EXPR>:3:1: error: cannot find 'variable_name' in scope
Run Code Online (Sandbox Code Playgroud)
而不是预期变量的值。
将这些行添加到 Swift 代码中
let example = "hi"
print(example)
Run Code Online (Sandbox Code Playgroud)
将断点放在第二行,即带有print()语句的那一行
运行代码,等待断点命中
尝试po example在调试控制台中运行
它应该"hi"在控制台中打印
它打印此错误行
error: <EXPR>:3:1: error: cannot find 'example' in scope
Run Code Online (Sandbox Code Playgroud)
在模拟器或设备上运行时也是如此。我试过激活控制台,然后重新启动 Xcode。
我已经尝试在 Xcode12 中创建一个新项目并且运行良好,我使用以前版本的 Xcode 创建的其他旧项目在 Xcode 12 中运行良好。
我已经尝试在其他项目和新创建的项目中面对 Build 设置,似乎没有任何问题:优化设置None为调试构建配置应有的设置,并且运行方案设置为启动调试构建配置。
问题还可能出在哪里?
我认为此错误消息是 Xcode 12 中的 SwiftUI 的新消息,因为它在 Google 中的点击率为 0,而该消息本身相当通用:
在安装在 View 之外访问 State 的值。这将导致初始值的常量绑定并且不会更新。
我有以下代码(删除了一些绒毛):
public struct ContentView: View {
@ObservedObject var model: RootViewModel
public var body: some View {
VStack(alignment: .center, content: {
Picker(selection: model.$amount, label: Text("Amount")) {
Text("€1").tag(1)
Text("€2").tag(2)
Text("€5").tag(5)
Text("€10").tag(10)
}.pickerStyle(SegmentedPickerStyle())
Text("Donating: €\(model.amount)").font(.largeTitle)
}).padding(.all, 20.0)
}
}
public class RootViewModel: ObservableObject {
@State public var amount: Int = 1
}
Run Code Online (Sandbox Code Playgroud)
我曾经有field权利,ContentView而且工作正常。现在 UI 不再更新,而是我收到了运行时警告。
我已经安装了 Xcode 12 beta 2。我尝试在 Mac OS Catalina 上通过 Jenkins 运行我们的 xamarin 项目。它因以下错误而失败。当我从 Mac Visual Studio 构建相同的项目时,它成功了,没有任何错误。
SplashViewController.storyboard : error :
iOS 14.0 (14.0 - 18A5319g) - com.apple.CoreSimulator.SimRuntime.iOS-14-0 (unavailable, failed to open liblaunchsim.dylib) ==> not available:
Error Domain=com.apple.CoreSimulator.SimError Code=401 "The iOS 14.0 simulator runtime is not available."
UserInfo={NSLocalizedDescription=The iOS 14.0 simulator runtime is not available.,
NSUnderlyingError=0x7fef8847b520 {Error Domain=NSPOSIXErrorDomain Code=53 "Software caused connection abort"
UserInfo={NSLocalizedFailureReason=XPC error talking to SimLaunchHostService: <error: 0x7fff97d649a0> { count = 1, transaction: 0, voucher = 0x0,_
Run Code Online (Sandbox Code Playgroud)
我还 …
我无法从(Xcode -> 首选项 -> 组件)找到模拟器的iOS 12.5版本。
我在 Xcode 12.2 和 12.4 版本上检查过,但没有成功。有谁知道为什么?,我需要执行任何更新吗?,组件部分中显示的最新 iOS 版本 Xcode 是14.3