AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[xcode](coding)

Martin Hope
Badr Bujbara
Asked: 2025-04-29 01:24:45 +0800 CST

如何解决 Xcode 中的 UIViewControllerRepresentable 错误?

  • 5

我正在尝试创建一个UIViewControllerRepresentable结构体,但 Xcode 一直抱怨实现存根

struct PassVC: UIViewControllerRepresentable {
    typealias UIViewControllerType = UIViewController
    
    func makeUIViewController(context: Context) -> UIViewController {
        let vc = UIViewController()
        vc.view.backgroundColor = .yellow
        return vc
    }
    
    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
        
    }
}

我先添加了 typealias,然后手动输入,最后让 Xcode 实现存根,也手动输入,但所有尝试都以 Xcode 报错,说没有实现存根。如果我点击“修复”,它会报错说存根方法需要重新声明。有人在 Xcode 中遇到过同样的问题吗?我的 Xcode 版本是 16.0。 在此处输入图片描述

xcode
  • 2 个回答
  • 43 Views
Martin Hope
Gil
Asked: 2025-01-18 00:28:12 +0800 CST

HStack 中按钮出现的延迟

  • 5

我正在尝试让 HStack 中 5 个按钮上的标签一次出现一个,每个按钮之间间隔 1 秒。在我的代码中,它们全部同时出现。显然我没有正确使用 sleep。不确定我是否应该使用它。换句话说,我希望“A”出现,然后一秒钟后出现“B”等。

    HStack (spacing: 25) {
        ForEach(letters, id: \.self) { letter in
            Button {

            }
            label : {
                ZStack {
                    RoundedRectangle(cornerRadius: 15)
                        .fill(Color.blue.opacity(0.3))
                        .frame(width: 50, height: 50)
                    Text(letter)
                        .font(.largeTitle)
                        .foregroundColor(.black)
                }
            }
            .task {
                /// Delay of 1 second
                try? await Task.sleep(nanoseconds: 1_000_000_000)
            }
            
        }
    }

在此处输入图片描述

xcode
  • 1 个回答
  • 32 Views
Martin Hope
Maury Markowitz
Asked: 2024-12-09 01:16:42 +0800 CST

Xcode 提交因冲突而失败,但我找不到它们

  • 5

在合并到 master 之前,我即将在项目中提交最后一次签入。我已经暂存了更改,但是当我尝试提交时,出现有关冲突的错误:

error: Committing is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

我不确定,但“未合并”是否是“有冲突”的另一种说法?如果是这样,我不知道这些冲突可能在哪里。我的所有源文件都是 A 和 M,并且暂存区中的所有文件都是相同的。

有人能提供一种简单的方法来追踪这些吗?

xcode
  • 1 个回答
  • 38 Views
Martin Hope
Dovizu
Asked: 2024-11-25 07:22:04 +0800 CST

尝试预先选择单选按钮时,在调用宏“预览”时没有完全匹配

  • 5

我试图了解为什么 SwiftUI Preview 不允许我这样做:

struct ItemCreateView: View {
    
    @Environment(\.dismiss) var dismiss
    @Environment(\.modelContext) private var modelContext
    
    @Query private var collections: [Collection]
    let selectedCollection: Collection
    
    @State private var item = Item()
    @State private var selectedImage: PhotosPickerItem? = nil
    
    var body: some View {...}
}

#Preview {
    let config = ModelConfiguration(isStoredInMemoryOnly: true)
    let container = try! ModelContainer(for: Collection.self, configurations: config)
    
    for number in 1...10 {
        let col = Collection(name: "Test Collection \(number)")
        container.mainContext.insert(col)
    }
    
    let selectedCollection = container.mainContext.fetch(Collection.self).first!
    
    ItemCreateView(selectedCollection: selectedCollection).modelContainer(container)
}

错误是:

No exact matches in call to macro 'Preview'
Closure containing control flow statement cannot be used with
result builder 'PreviewMacroBodyBuilder'

但是,如果我将“Return”添加到最后一项。它会抱怨:Cannot use explicit 'return' statement in the body of result builder 'ViewBuilder'

但如果我不尝试从容器中获取随机元素,一切都会正常。

#Preview {
    let config = ModelConfiguration(isStoredInMemoryOnly: true)
    let container = try! ModelContainer(for: Collection.self, configurations: config)
    
    for number in 1...10 {
        let col = Collection(name: "Test Collection \(number)")
        container.mainContext.insert(col)
    }
    
    let selectedCollection = Collection(name: "Test Collection 1")
    
    return ItemCreateView(selectedCollection: selectedCollection).modelContainer(container)
}

^ 这有效。

我不确定我是否理解这里所有内容的关联,而且我似乎无法在网上找到有关该错误的信息。

提前感谢您的帮助。

参考模型

@Model
final class Collection {
    var name: String
    @Relationship(inverse: \Item.collection) var items: [Item]
    var timestamp: Date
    
    init(name: String = "", items: [Item] = [], timestamp: Date = Date()) {
        self.name = name
        self.items = items
        self.timestamp = timestamp
    }
}
xcode
  • 1 个回答
  • 39 Views
Martin Hope
Cécile Lebleu
Asked: 2024-11-19 10:29:39 +0800 CST

无法运行动画故障工具。这是一个错误吗?

  • 6

我尝试运行“动画故障”工具,但在 iPhone 上启动后立即失败。这种情况发生在多个项目中,包括一个全新的项目。

我收到以下错误:

时间戳 信息
(运行开始前) 意外故障:信使意外返回。
(运行开始前) 无法开始记录:无法启动 ktrace 会话。

该问题也发生在工具 App Launch 上,但在我测试过的任何其他工具上均未发生。

这是一个错误吗?

使用 Xcode 版本 16.1、Mac Mini M1 Sequoia 15.1。在 iPhone 14 Pro iOS 18.1 上运行项目。

也发布在 Apple 开发者论坛上

xcode
  • 1 个回答
  • 30 Views
Martin Hope
sinaar
Asked: 2024-11-16 02:33:49 +0800 CST

CoreSimulator存储空间

  • 5

我的/Library/Developer/CoreSimulator文件夹有 27 GB,其中/Library/Developer/CoreSimulator/Images占用了 15 GB,/Library/Developer/CoreSimulator/Profiles占用了 12 GB。我可以清除这些文件夹中的任何内容而不破坏任何内容吗?

请记住,这是一个不同的文件夹,~/Library/Developer/CoreSimulator大小仅有 3 GB。

xcode
  • 1 个回答
  • 24 Views
Martin Hope
Johannes Klopp
Asked: 2024-10-13 17:35:24 +0800 CST

如何设置 SwiftUI 以使设备不关闭?

  • 5

我正在开发 Pomdoro 函数,唯一的问题是,当计时器运行时,iPhone 或 iPad 会因为您未使用设备而关闭。我该如何在代码中更改此设置,使其在计时器处于活动状态时不会关闭,或者我可以使用开关自行决定是否要这样做?

非常感谢你的帮助

我最初尝试在 XCode 中激活后台处理,并认为它会自动转换,但不幸的是,这没有帮助。

这是我的代码:

struct FocusView: View {
    @State var progress: Double = 0
    @State var isTimerViewPresented: Bool = false
    
    @AppStorage("focusTime") private var focusTime: Double = 0
    @State private var workDuration: Double = 25
    @State private var pauseDuration: Double = 5
    
    @AppStorage("modus") private var modus: String = "work"
    
    @State var isRunning: Bool = false
    @State var pausenint: Int = 2
    
    @State var wiederholungen_Int: Int = 0
    @Binding var repetitions: Double
    
    @AppStorage("totalWorkTime") private var totalWorkTime: Double = 0
    
    let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
    
    @State var isCompleteWorkTimeShow: Bool = false
    
    @State private var showCompletionSheet: Bool = false
    @State private var totalFocusTime: TimeInterval = 0
    
    func convertSecondsToTime(timeInSeconds: Int) -> String {
        let minutes = timeInSeconds / 60
        let seconds = timeInSeconds % 60
        return String(format: "%02i:%02i", minutes, seconds)
    }
    
    var body: some View {
        ZStack {
            VStack {
                Spacer()
                
                VStack {
                    ZStack {
                        CircularProgressView_pomodoro(progress: $progress, modus: modus)
                        
                        Text(convertSecondsToTime(timeInSeconds: Int(focusTime)))
                            .font(.custom("ArialRoundedMTBold", size: 70))
                            .onTapGesture {
                                withAnimation {
                                    isTimerViewPresented.toggle()
                                }
                            }
                            .sheet(isPresented: $isTimerViewPresented) {
                                TimerView(
                                    progress: $progress,
                                    isTimerViewPresented: $isTimerViewPresented,
                                    sliderValue: $workDuration,
                                    sliderValue_pause: $pauseDuration,
                                    sliderValue_wiederholungen: $repetitions,
                                    focusTime: $focusTime, modus: $modus, pause: $pausenint, wiederholungen: $wiederholungen_Int
                                )
                                .presentationBackground(.clear)
                            }
                    }
                    .frame(width: 250, height: 250)
                }
                
                Spacer()
                
                HStack {
                    Spacer()
                    Button(action: resetTimer) {
                        Image(systemName: "backward")
                            .font(.system(size: 42))
                            .foregroundColor(.primary)
                    }
                    .padding()
                    
                    Spacer()
                    
                    Button(action: toggleTimer) {
                        Image(systemName: isRunning ? "pause" : "play")
                            .font(.system(size: 42))
                            .foregroundColor(.primary)
                    }
                    .padding()
                    
                    Spacer()
                    
                    Button(action: skipTimer) {
                        Image(systemName: "forward")
                            .font(.system(size: 42))
                            .foregroundColor(.primary)
                    }
                    .padding()
                    
                    Spacer()
                }
                
                if isCompleteWorkTimeShow {
                    HStack {
                        Text("Gesamte Arbeitszeit: \(convertSecondsToTime(timeInSeconds: Int(totalWorkTime)))")
                            .font(.headline)
                            .foregroundColor(.primary)

                        Image(systemName: "arrow.clockwise")
                            .foregroundColor(.primary)
                            .onTapGesture {
                                totalWorkTime = 0
                            }
                            .padding()
                    }
                }
                
                Spacer()
            }
        }
        .onReceive(timer) { _ in
            updateTimer()
        }
        .sheet(isPresented: $showCompletionSheet) {
                   CompletionView(totalFocusTime: totalFocusTime, onDismiss: {
                       showCompletionSheet = false
                   })
               }
    }
    
    private func resetTimer() {
        focusTime = modus == "work" ? workDuration * 60 : pauseDuration * 60
        progress = 0
        isRunning = false
    }
    
    private func toggleTimer() {
        isRunning.toggle()
    }
    
    private func skipTimer() {
        focusTime = 0
        updateTimer()
    }
    
    private func updateTimer() {
        if isRunning && repetitions > 0 {
            if focusTime > 0 {
                focusTime -= 1
                if modus == "work" {
                    totalWorkTime += 1
                    totalFocusTime += 1
                }
                progress = 1.0 - (focusTime / (modus == "work" ? workDuration * 60 : pauseDuration * 60))
            } else {
                switchMode()
            }
        }
    }
    
    private func switchMode() {
        if modus == "work" {
            modus = "pause"
            focusTime = pauseDuration * 60
            scheduleNotification(for: modus)
        } else {
            modus = "work"
            focusTime = workDuration * 60
            repetitions -= 1
            if repetitions > 0 {
                scheduleNotification(for: modus)
            } else {
                completeSession()
            }
        }
        progress = 0
    }
    
    private func completeSession() {
        isRunning = false
        showCompletionSheet = true
    }
    
    private func scheduleNotification(for mode: String) {
        let content = UNMutableNotificationContent()
        content.title = "Pomodoro Timer"
        content.body = NSLocalizedString(mode == "work" ? "Zeit, wieder an die Arbeit zu gehen!" : "Zeit für eine Pause!", comment: "Pomodoro timer notification")
        content.sound = UNNotificationSound.default
        
        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
        let request = UNNotificationRequest(identifier: "PomodoroTimer", content: content, trigger: trigger)
        UNUserNotificationCenter.current().add(request)
    }
}

xcode
  • 1 个回答
  • 27 Views
Martin Hope
phast
Asked: 2024-10-11 20:04:50 +0800 CST

为什么 Swift Testing 无法识别我的辅助函数?

  • 5

我刚刚开始深入研究新的 Swift 测试框架,但遇到了特征方面的问题.enabled(if: Bool)。

下面我的代码返回Instance member 'accessTokenIsNil' cannot be used on type 'AuthorizationTests'; did you mean to use a value of this type instead?部分错误.enabled(if: accessTokenIsNil())。

import Testing
@testable import mews
import SwiftUI

struct AuthorizationTests {
    let accessTokenManager = AccessTokenManager()
    
    func accessTokenIsNil() -> Bool {
        accessTokenManager.token == nil
    }
    
    @Test("Get initial access token", .enabled(if: accessTokenIsNil()))
    func getAccessTokenSucces() {
        // continue test
    }
}

下面是来自Apple 的官方文档,所以我不确定我做错了什么。

func allIngredientsAvailable(for food: Food) -> Bool { ... }


@Test(
  "Can make sundaes",
  .enabled(if: Season.current == .summer),
  .enabled(if: allIngredientsAvailable(for: .sundae))
)
func makeSundae() async throws { ... }
xcode
  • 1 个回答
  • 25 Views
Martin Hope
alanrick
Asked: 2024-08-10 21:34:24 +0800 CST

直接编辑 swiftui String Catalog 文件最安全的方法是什么?

  • 5

看来我的字符串目录文件中的注释导致 Xcode 在源代码控制导航器视图中呈现时崩溃(是的 - 它确实让我发疯)

该字符串是: "X" : { "comment" : "Represents doubled in header\nfrom contract struct",

源自以下源代码: return String(localized: "X", comment: "Represents doubled in the header")

我怀疑注释中的回车符是问题所在,但我无法将其删除。显然,此注释是遗留的,不再与 swiftui 源代码匹配,但它不会更新,因此我的 Xcode 在尝试提交时崩溃了。

我怎样才能更改字符串目录中的该注释?

我尝试直接编辑 json 文件,但被忽略了。我尝试删除代码行,然后读取它,但有问题的注释返回到字符串目录,所以我猜它缓存在某个地方。我尝试清理构建文件夹并重复上述步骤 - 没有成功,注释仍然存在并且 Xcode 崩溃。

我可以简单地将字符串目录的副本拖放到我的项目中(并更正注释)吗?或者这会弄乱项目吗?

MacBook Air 上的版本 15.4 (15F31d)

xcode
  • 1 个回答
  • 38 Views
Martin Hope
user26383060
Asked: 2024-08-01 18:33:22 +0800 CST

在 Xcode 中,如何在不剪切和粘贴的情况下将代码块从同一个文件中的一个位置移动到另一个位置?

  • 7

我有这个代码:

`如果可用{

}

doSomething()goToSomeWere()`

如何将这段代码(2 个函数)移到“if”中,而无需剪切和粘贴(使用键盘)?XCode 中有快捷方式吗?

在 Android Studio 上我使用:

  • 向上移动一行:Alt + Shift + 向上箭头
  • 向下移动一行:Alt + Shift + 向下箭头
xcode
  • 1 个回答
  • 20 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve