[英]Swift Cannot find variable in scope
Swift giving error that var is not in scope. Swift 给出 var 不在范围内的错误。 "Cannot find 'midiManager' in scope" I am not sure how to fix issue
“在范围内找不到 'midiManager'”我不确定如何解决问题
menu.swift菜单.swift
struct MainMenuBar: MenuBar {
public var body: StandardMenuBar {
StandardMenu(title: "Midi Devices") {
midiManager.endpoints.outputs.forEach { device in
TextMenuItem(title: device.name) { _ in
print(device.uniqueID)
}
}
}
}
}
midi.swift midi.swift
@objc(ReactNativeMidiModule)
class ReactNativeMidiModule: RCTEventEmitter, NSApplicationDelegate {
// Create midi manager
public let midiManager = MIDI.IO.Manager(
clientName: "MIDIEventLogger",
model: "ELMC Midi Monitor",
manufacturer: "ELMC")
// other code
}
midiManager
is not present inside your MainMenueBar
. midiManager
不存在于MainMenueBar
中。 So midiManager
can not be found.所以
midiManager
。 You must need to add midiManager
inside your MainMenueBar
structure.您必须需要在
MainMenueBar
结构中添加midiManager
。 Like this -像这样 -
struct MainMenuBar: MenuBar
{
public let midiManager = MIDI.IO.Manager(clientName: "MIDIEventLogger", model: "ELMC Midi Monitor", manufacturer: "ELMC")
public var body: StandardMenuBar
{
StandardMenu(title: "Midi Devices")
{
midiManager.endpoints.outputs.forEach { device in
TextMenuItem(title: device.name) { _ in
print(device.uniqueID)
}
}
}
}
}
or By creating a common class as-或通过创建一个通用类作为-
class MidiManager {
static let midiManager = MIDI.IO.Manager(clientName: "MIDIEventLogger", model: "ELMC Midi Monitor", manufacturer: "ELMC")
}
And then use it in both MainMenuBar
and ReactNativeMidiModule
as-然后在
MainMenuBar
和ReactNativeMidiModule
中使用它作为-
struct MainMenuBar: MenuBar {
public let midiManager = MidiManager.midiManager
public var body: StandardMenuBar {
StandardMenu(title: "Midi Devices") {
midiManager.endpoints.outputs.forEach { device in
TextMenuItem(title: device.name) { _ in
print(device.uniqueID)
}
}
}
}
}
@objc(ReactNativeMidiModule)
class ReactNativeMidiModule: RCTEventEmitter, NSApplicationDelegate {
// Create midi manager
public let midiManager = MidiManager.midiManager
// other code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.