withCheckedThrowingContinuation当没有返回类型时,我无法编译。例如:
public\n func\n write(toDevice inDeviceID: Int, atAddress inAddr: Int, value inVal: Float)\n async\n throws\n {\n try await withCheckedThrowingContinuation\n // ^ Generic parameter \'T\' could not be inferred\n { inCont in\n self.workQ.async\n {\n do\n {\n self.deviceID = inDeviceID\n try self.write(address: inAddr, value: inVal)\n inCont.resume()\n }\n \n catch (let e)\n {\n inCont.resume(throwing: e)\n }\n }\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n返回的版本工作得很好:
\n public\n func\n readRegister(address inAddr: Int, fromDevice inDeviceID: Int)\n async\n throws\n -> UInt16\n {\n try await withCheckedThrowingContinuation\n { inCont in\n self.workQ.async\n …Run Code Online (Sandbox Code Playgroud) 我有一些代码可以在 iOS 14 中运行,但在 15 中,xe2x80x99 就不太行了。下图所示的单元格可以有一行或两行标题。在 iOS 14(右侧)中,Spacer()标题和列表计数文本之间的元素按预期展开,以便单元格的高度相同。在 iOS 15 中,情况并非如此,单元格会缩小,并在其行中居中(请参阅 \xe2\x80\x9cA-Train\xe2\x80\x9d 项)。
单元格的代码如下所示:
\nZStack\n{\n Color.white\n .cornerRadius(8)\n \n VStack(alignment: .leading, spacing: 0)\n {\n // Listing Image\xe2\x80\xa6\n \n GeometryReader\n { geom in\n KFImage(self.imageURL)\n .cancelOnDisappear(true)\n .placeholder {\n Image("product-placeholder")\n .resizable()\n .aspectRatio(contentMode: .fit)\n .frame(width: geom.size.width, height: geom.size.width)\n }\n .resizable()\n .aspectRatio(contentMode: .fill)\n .frame(width: geom.size.width, height: geom.size.width)\n .cornerRadius(4)\n .clipped()\n }\n .aspectRatio(contentMode: .fit)\n .padding(.bottom, 12)\n \n // Title\xe2\x80\xa6\n \n Text("\\(self.title)")\n .font(.custom("Poppins", size: 14.0).weight(.semibold))\n .multilineTextAlignment(.leading)\n .lineLimit(2)\n \n Spacer(minLength: 0) // Not expanding …Run Code Online (Sandbox Code Playgroud) 我希望开发一些使用 SDL2 在 7" RPi 触摸屏上显示图形的代码,但我宁愿不安装完整的桌面操作系统。我已经安装了 Raspbian Buster Lite。一些简单的测试代码在我尝试运行它:
user@rpi4:~/01_hello_SDL $ ./hw
Window could not be created! SDL_Error: Could not initialize EGL
user@rpi4:~/01_hello_SDL $ sudo ./hw
error: XDG_RUNTIME_DIR not set in the environment.
Window could not be created! SDL_Error: Could not initialize EGL
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建窗口
SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL )
Run Code Online (Sandbox Code Playgroud)
我找到了一个帖子,其中引用了有关如何在没有 X 的情况下构建 SDL2 的说明,但我希望有人能教我更多关于 SDL 如何在各种环境中找到显示的信息,以及是否有可能做我想做的事情。
几年前,我使用 SDL 1.2 在运行 Debian 版本的 Beaglebone Black 上制作全屏图形,但我似乎丢失了该安装,并且不记得它是如何设置的。我依稀记得一些关于 fbdev 的问题,它是非加速图形,但这在当时并不重要(虽然我现在想获得加速图形,但这并不重要)。
示例代码:
/*This source code copyrighted …Run Code Online (Sandbox Code Playgroud) 我正在尝试为基于Spring 3.2.8的纯Java配置应用程序添加安全性.我按照说明http://docs.spring.io/spring-security/site/docs/3.2.2.RELEASE/reference/htmlsingle/#jc
我已经完成了3.1节,文档说此时每个URL都需要身份验证,但没有一个(至少我可以加载每个URL).它说它创建了一个Servlet过滤器等.
很明显,WebSecurityConfigurerAdapter子类本身是不够的.所以我看一下3.1.1节,它说下一步是将springSecurityFilterChain注册到WAR,然后继续说明在Servlet 3+环境中,我需要继承AbstractSecurityWebApplicationInitializer.但我已经在继承AbstractAnnotationConfigDispatcherServletInitializer.我应该有一个吗?在AbstractSecurityWebApplicationInitializer JavaDoc中有一些关于排序的讨论,暗示我应该有多个初始化类.
在所有这些中,它还说要将WebSecurityConfigurerAdapter子类添加到getRootConfigClasses()(尽管该示例没有显示其他Spring启动文档的"AppConfig";而且,仅此一项还不够).
所以我尝试添加另一个初始化类.我的所有其他类都是我的AbstractAnnotationConfigDispatcherServletInitializer子类的公共静态内部类,所以我把另一个放在那里作为AbstractSecurityWebApplicationInitializer子类(而不是创建一个单独的.java文件).
WARNING com.caucho.server.webapp.WebApp setConfigException: java.lang.UnsupportedOperationException: unimplemented
at com.caucho.server.webapp.ServletContextImpl.setSessionTrackingModes(ServletContextImpl.java:552)
at org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer.onStartup(AbstractSecurityWebApplicationInitializer.java:120)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
at com.caucho.server.webapp.WebApp.callInitializer(WebApp.java:3471)
at com.caucho.server.webapp.WebApp.callInitializers(WebApp.java:3439)
at com.caucho.server.webapp.WebApp.startImpl(WebApp.java:3661)
at com.caucho.server.webapp.WebApp$StartupTask.run(WebApp.java:5196)
at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
Run Code Online (Sandbox Code Playgroud)
我尝试添加订购无济于事.我的整个配置:
package com.latencyzero.satdb.web;
//
// Java Imports
//
import java.util.Properties;
import java.util.ResourceBundle;
import javax.naming.InitialContext;
import javax.servlet.ServletContext;
import javax.sql.DataSource;
//
// Library Imports
//
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.xml.DOMConfigurator;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
import …Run Code Online (Sandbox Code Playgroud) 我已经在 Ubuntu 机器上运行这个旧的 Caucho Resin (4.0.41) 很多很多年了。我需要退役该服务器,所以我尝试在新的 Ubuntu 18.04.4 服务器上设置resin 4.0.64,经过大量的尝试和摆弄,它正在启动,但最终在早期失败了:
OpenJDK 64-Bit Server VM warning: Archived non-system classes are disabled because the java.system.class.loader property is specified (value = "com.caucho.loader.SystemClassLoader"). To use archived non-system classes, this property must be not be set
Error occurred during initialization of VM
java.lang.Error: com.caucho.loader.SystemClassLoader
at java.lang.ClassLoader.initSystemClassLoader(java.base@11.0.6/ClassLoader.java:1989)
at java.lang.System.initPhase3(java.base@11.0.6/System.java:2069)
Caused by: java.lang.ClassNotFoundException: com.caucho.loader.SystemClassLoader
at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@11.0.6/BuiltinClassLoader.java:581)
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@11.0.6/ClassLoaders.java:178)
at java.lang.ClassLoader.loadClass(java.base@11.0.6/ClassLoader.java:521)
at java.lang.Class.forName0(java.base@11.0.6/Native Method)
at java.lang.Class.forName(java.base@11.0.6/Class.java:398)
at java.lang.ClassLoader.initSystemClassLoader(java.base@11.0.6/ClassLoader.java:1975)
at java.lang.System.initPhase3(java.base@11.0.6/System.java:2069)
Run Code Online (Sandbox Code Playgroud)
我似乎无法通过谷歌搜索找到任何结果,也找不到任何明显的设置 java.system.class.loader。
有什么建议么?谢谢!
我有一个简单的聊天视图,可以向上滚动以显示出现在聊天底部的新消息。奇怪的是,有时,滚动动画的持续时间比正常情况要长得多。

我认为当动画仍在进行时收到消息时就会发生这种情况。
我的代码如下所示:
struct
OverlayChatView: View
{
@ObservedObject public var stream : ChatStream
var body: some View {
ScrollViewReader { scrollView in
ScrollView {
LazyVStack(alignment: .leading, spacing: 0.0) {
ForEach(self.stream.messages) { inMsg in
ChatMessageCell(message: inMsg)
}
.onChange(of: self.stream.messages, perform: { inMessages in
if inMessages.count < 1 { return }
withAnimation(.linear(duration: 0.25)) {
scrollView.scrollTo(inMessages.last!.id, anchor: .bottom)
}
})
.padding(8)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
self.stream是从一个简单的计时器传入的,@ObservedObject ChatStream每 5.0 秒插入一条新消息。如果间隔为 2.0 秒,则它只是不断地缓慢向上滚动。
我注意到的另一件事是.onChange()每个插入都会被调用三次。也许我ChatStream正在做一些愚蠢的事情。我提到它是因为仅仅快速连续调用动画三次并不会导致速度变慢。它似乎与卷轴当前所在的位置与它必须去的位置更相关。
知道如何避免这种减速吗?
大多数类似的问题似乎都有与我\xe2\x80\x99m 相反的问题。
\n\nI\xe2\x80\x99m 使用以下命令构建基于 Spring Boot 的 Web 应用程序@RestController. JSON 响应运行良好,但现在我想支持通过模板(特别是 Thymeleaf)返回 HTML。所有示例都显示了这样的构建方法:
@RequestMapping(method = RequestMethod.GET)\nString index()\n{\n return "index";\n}\nRun Code Online (Sandbox Code Playgroud)\n\n只要 it\xe2\x80\x99s 中的类用@Controller. 如果我用 进行注释@RestController,我会得到文字字符串“index”。这是有道理的,因为@RestController意味着@ResponseBody.
我对此有一些一般性的问题\xe2\x80\xa6
\n\n@Controller使用和明确的做法是否正确@ResponseBody在旨在返回 JSON 的方法上
我担心我的 Controller 类会变得相当大,因为我\xe2\x80\x99ll 对大多数 GET 方法有两种实现(一种返回 HATEOAS JSON,一种返回模型中包含更多内容的 HTML)。是否有推荐的做法来分解这个?
感谢您的建议。谢谢!
\n有没有一种纯 SwiftUI 的方式来打开一个新窗口?我有一个基于文档的应用程序,它的应用程序看起来像这样:
@main struct MyApp: App
{
var
body: some Scene {
DocumentGroup(newDocument: ProjectDocument.init) { inGroup in
ProjectWindowContentView(document: inGroup.document)
.frame(minWidth: 301.0, minHeight: 100.0)
.onReceive(self.addTerrainGeneratorLayerCommand) { _ in
inGroup.document.addTerrainGeneratorLayer()
}
}
.commands {
...
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
现在我想添加一个菜单命令来在它自己的窗口中实例化一个小的自包含实用工具。到目前为止,我在网上看到的任何讨论实际上都涉及创建一个新NSWindow的NSHostingView内容视图。这似乎不是很像 SwiftUI,而且考虑到他们最近添加的DocumentGroup并且WindowGroup似乎是一个很大的疏忽。
我尝试将 aWindowGroup放入应用程序的场景中,但如果我注释掉DocumentGroup.
我想用它getDeclaredMethod()来找到一个带有这个签名的方法:
public void foo(String inArg1, Object... inArgs);
Run Code Online (Sandbox Code Playgroud)
使用此电话:
Class<?>[] argClasses = { String.class, Integer.class };
Method m = clazz.getDeclaredMethod("foo", argClasses);
Run Code Online (Sandbox Code Playgroud)
但它产生了一个NoSuchMethodException例外.但是,可以调用该方法(假设您以其他方式找到它):
Object[] args = { "arg1", new Integer(2) };
m.invoke(instance, args);
Run Code Online (Sandbox Code Playgroud)
我可以将它们全部列出来,getDeclaredMethods()然后尝试自己进行签名匹配,但这似乎很多工作.
我应该做什么?我只是缺少一些愚蠢的东西吗?
我有一个应用程序,它是Spring Bookmark教程的简化版本.在其中,控制器使用注释,@RestController应用程序仅返回JSON.
我已经添加了通过Thymeleaf模板返回HTML的能力.我的模板正在退回,但它们似乎不是由Thymeleaf处理的.我正在使用spring-boot,而且我已经使用spring-boot-starter-thymeleaf了我的build.gradle 文件,但这似乎还不够.
例如,这是一个简单的root控制器:
package com.latencyzero.hoa;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/")
class
MainController
{
@RequestMapping(method = RequestMethod.GET)
ModelAndView
index()
{
ModelAndView mav = new ModelAndView("index");
mav.addObject("version", "0.1");
return mav;
}
}
Run Code Online (Sandbox Code Playgroud)
并且src/main/resources/templates/index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>HOA v${version}</title>
</head>
<body>
<h1>HOA v${version}</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
呈现以下页面中的结果:
我发现的例子表明这是我需要做的全部,但它不起作用.我在某处需要一些额外的配置注释吗?
谢谢.
我有一组传统的UIViewControllers 和UIViews,我将 a 传递给Publisher:
class MyModel : ObservableObject {\n @Published var product: Product?\n}\n\n\xe2\x80\xa6\n\nlet someView = SomeView(product: self.model.$product)\n\n\xe2\x80\xa6\n\nclass SomeView : UIView {\n init(product: Published<Product?>.Publisher) {\n self.sub = product.sink { prod in <do stuff when it changes> }\n }\nRun Code Online (Sandbox Code Playgroud)\n我需要MyModel.product在视图初始化时仅对其中一个属性执行一次操作,而不是每次后续product更新。有没有这样的事情:
self.pub = product\n .sinkOnSub { prod in <do when creating this subscription> }\n .sinkRemaining { prod in <do subsequent times> }\nRun Code Online (Sandbox Code Playgroud)\n 在尝试使用库版本后,我陷入了困境。一个类似的问题似乎并不适用,因为它是三岁和我使用的东西太多新版本,它的抱怨Optional<>。我的Gradle文件:https : //github.com/JetForMe/spring-hoa/blob/master/build.gradle? ts =4
public
interface
UserRepository
extends JpaRepository<User, Long>
{
Optional<User> findByLogin(String inLogin);
}
Run Code Online (Sandbox Code Playgroud)
对于实体
@Entity public class User
{
public
User(String inLogin, String inClearPassword)
{
mLogin = inLogin;
mEncryptedPassword = inClearPassword; // TODO
}
public Long getId() { return mId; }
public String getLogin() { return mLogin; }
@Id
@GeneratedValue
private Long mId;
@JsonIgnore
public String mEncryptedPassword;
public String mLogin;
}
Run Code Online (Sandbox Code Playgroud)
完整日志:
$ gradle bootRun
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass …Run Code Online (Sandbox Code Playgroud) 我在 SwiftUI 中构建了以下模态对话框:
但我不知道如何使“打开”按钮成为默认按钮(即在标准 macOS HIG 中填充为蓝色)。它的代码如下所示:
struct
OpenLocationView : View
{
@State private var location: String = ""
var body: some View
{
VStack
{
HStack
{
Text("Location:")
TextField("https://", text: $location) { self.openLocation() }
}
HStack
{
Spacer()
Button("Cancel") { /* dismiss window */ }
Button("Open") { self.openLocation() }
}
}
.padding()
.frame(minWidth: 500.0)
}
func
openLocation()
{
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试 append .buttonStyle(DefaultButtonStyle()),但这没有明显的效果。
java ×4
swiftui ×4
spring ×3
spring-mvc ×3
swift ×3
spring-boot ×2
c++ ×1
combine ×1
framebuffer ×1
gradle ×1
hibernate ×1
ios ×1
java-11 ×1
linux ×1
macos ×1
openjdk-11 ×1
raspbian ×1
reflection ×1
resin ×1
sdl-2 ×1
spring-rest ×1
thymeleaf ×1