小编Yul*_*lky的帖子

Visual Studio Code 无法处理 Java

我正在尝试在 VSCode 中编辑 Java 文件,但遇到了来自 VSCode 的大量错误。例如:

The type java.lang.Object cannot be resolved.
    It is indirectly referenced from required .class files
String cannot be resolved to a type
System cannot be resolved
Run Code Online (Sandbox Code Playgroud)

我尝试运行 Java clean 来清理工作区,并尝试重新安装 Java 扩展包。无论哪种方式,问题仍然存在。

我无法摆脱这个,这真的很烦人!如果可以的话请帮忙!谢谢你。

java compiler-errors visual-studio-code

5
推荐指数
1
解决办法
1867
查看次数

停止点击(python 模块)捕获/处理键盘中断

我有以下代码:

import click


@click.command()
def main():
    while True:
        pass


try:
    main()
except KeyboardInterrupt:
    print('My own message!')
Run Code Online (Sandbox Code Playgroud)

当我按 Ctrl+C 退出程序时,我想打印自己的消息。但是,单击会拦截错误,这是输出:

^C
Aborted!
Run Code Online (Sandbox Code Playgroud)

如何阻止 click 处理错误?

python error-handling python-3.x

4
推荐指数
1
解决办法
1229
查看次数

SwiftUI - 如何制作启动/停止计时器

我的目标是在 SwiftUI 中创建一个从 0 开始的视图。当你按下视图时,计时器应该开始向上计数,再次点击停止计时器。最后,当您再次点击以启动计时器时,计时器应从 0 开始。

这是我当前的代码:

import SwiftUI

struct TimerView: View {
    @State var isTimerRunning = false
    @State private var endTime = Date()
    @State private var startTime =  Date()
    let timer = Timer.publish(every: 0.001, on: .main, in: .common).autoconnect()
    
    var tap: some Gesture {
        TapGesture(count: 1)
            .onEnded({
                isTimerRunning.toggle()
            })
    }

    var body: some View {

        Text("\(endTime.timeIntervalSince1970 - startTime.timeIntervalSince1970)")
            .font(.largeTitle)
            .gesture(tap)
            .onReceive(timer) { input in
                startTime = isTimerRunning ? startTime : Date()
                endTime = isTimerRunning ? input : endTime
            } …
Run Code Online (Sandbox Code Playgroud)

view timer swift swiftui

3
推荐指数
1
解决办法
3770
查看次数

Replace nth Substring With nth Strings of Lists

I have a string like so:

"initWithType:bundleIdentifier:uniqueIdentifier:"
Run Code Online (Sandbox Code Playgroud)

and two lists like so:

['long long', 'id', 'id']
['arg1', 'arg2', 'arg3']
Run Code Online (Sandbox Code Playgroud)

and want to end up with the string:

"initWithType:(long long)arg1 bundleIdentifier:(id)arg2 uniqueIdentifier:(id)arg3"
Run Code Online (Sandbox Code Playgroud)

As you may see, I effectively need to replace every nth semicolon with the nth string in each list (plus a little formatting with parentheses and a space).

我一直在尝试使用.format*拆包经营者,但都收效甚微。

python string format list python-3.x

1
推荐指数
1
解决办法
42
查看次数

如何使自定义属性包装器可绑定(可能使用@State)?

我创建了一个自定义属性包装器,它作为其 setter 和 getter 从文件中写入和读取。

@propertyWrapper struct Specifier<Value> {
    let key: String
    let defaultValue: Value
    let plistPath: String
    
    var prefs: NSDictionary {
        NSDictionary(contentsOfFile: plistPath) ?? NSDictionary()
    }

    var wrappedValue: Value {
        get {
            return prefs.value(forKey: key) as? Value ?? defaultValue
        }
        set {
            prefs.setValue(newValue, forKey: key)
            prefs.write(toFile: plistPath, atomically: true)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我现在想在设置视图中使用它,如下所示:

struct PrefsView: View {
    @Specifier<Bool>(key: "enable", defaultValue: true, plistPath: "/Library/path/to/Prefs.plist") private var enable

    var body: some View {
        Form {
            Toggle("Enable", isOn: $enable)
        }
    }

} …
Run Code Online (Sandbox Code Playgroud)

state properties swift swiftui property-wrapper

1
推荐指数
1
解决办法
1099
查看次数