On the swift student challenge page it says "Your app playground must be built with and run on Swift Playgrounds 4.2.1 or later (requires iPadOS 16 or macOS 13) or Xcode 14 on macOS 13." Could I build it with Xcode in a swift.pm file but ask for it to be viewed on iPhone?
AFAIK, you cannot make such request.
Why require to view on iPhone only ? It should run on iPad as well. But you could note "best viewed on iPhone".
However, take care: largest screen on iPhone (430932 or 932430 logical size) are now not so far from smallest screens on iPad mini (7681024 or 1024768logical size). Hence, why make a difference ? Your app should adapt automatically to best fit the screen size.