Post

Replies

Boosts

Views

Activity

Getting NWInterface for NWEthernetChannel without Internet Connectivity
The "advances in networking" talks for WWDC had this example of using NWEthernetChannel to monitor a custom protocol.import FoundationImport Networklet path = NWPathMonitor(requiredInterfaceType: .wiredEthernet).currentPathguard let interface = path.availableInterfaces.first else { fatalError("not connected to Internet")}let channel = NWEthernetChannel(on: interface, etherType: 0xB26E)For my application I need to use a NWEthernetChannel to monitor a custom protocol* on an Ethernet link which does not have IP Internet connectivity (but it does have physical link to a switch). NWPath appears to only give me a NWInterface struct if it is a valid path to the Internet.How can I get a list of NWInterface Structs on the Mac without having a valid Internet path?In my particular use case I'm only interested in .wiredEthernet.Darrell* I'm trying to use Network.framework to receive LLDP (link-layer discovery protocol) and CDP (Cisco discovery protocol) traffic when I'm plugged into an ethernet switch, which may or may not have Internet connectivity.
15
0
3.7k
Jan ’20
Possible MacOS SwiftUI onFocusChange bug
I think I've found a bug with focusable(_: onFocusChange:) on MacOS with SwiftUI and wanted to sanity check it here before using feedback assistant. This is with Xcode 11.3.1When I create the window, the VStack inside thinks it is in focus. But the onFocusChange closure never gets called to say it loses focus. As a result, both my VStacks in both my windows think they are infocus.Demonstration project at https://github.com/darrellroot/focusBug/Here's my ContentView which displays whether it thinks it is in focus:struct ContentView: View { @State var inFocus = false let windowCount: Int var body: some View { VStack { Text("Focus Window \(windowCount)") inFocus ? Text("This window thinks it is in focus") : Text("This window does not think it is in focus") }.padding(50).focusable() { newFocus in debugPrint("onFocusChange: \(newFocus)") self.inFocus = newFocus } } }Here's my appDelegate code which spawns 1 window on launch and 1 more every time a particular menu is selected: var windows: [Int:NSWindow] = [:] var windowCount = 0 func applicationDidFinishLaunching(_ aNotification: Notification) { newWindow() } @IBAction func newFocusWindow(_ sender: NSMenuItem) { newWindow() } func newWindow() { windowCount = windowCount + 1 let contentView = ContentView(windowCount: windowCount) let window = NSWindow( contentRect: NSRect(x: 100, y: 100, width: 1000, height: 1000), styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], backing: .buffered, defer: false) window.isReleasedWhenClosed = false windows[windowCount] = window window.title = "Focus Window \(self.windowCount)" window.tabbingMode = .disallowed window.center() //window.setFrameAutosaveName("Window \(self.windowCount)") window.contentView = NSHostingView(rootView: contentView) window.makeKeyAndOrderFront(nil) }DebugPrint output shows that onFocusChange got called once per window:2020-03-09 10:24:22.363001-0700 focusBug[2555:258395] Metal API Validation Enabled"onFocusChange: true""onFocusChange: true"
3
1
1.8k
Mar ’20