I don't speak Swift, but the frontmostApplication property of NSWorkspace should give you what you want.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: