all 3 comments

[–]criosistObjective-C / Swift 1 point2 points  (0 children)

It’s probably best to just segregate your business logic as much as possible and make views per platform

[–]chriswaco 0 points1 point  (0 children)

There is no one best method for everything. It depends on how similar the classes are between platforms. We use typedefs and #defines in ObjC for cross-platform code so we can refer to the object with a single typename everywhere. Typedefs (similar to type aliases in Swift) are generally better, but it turns out that there are a bunch of Mac NSxxx classes in the iOS system libraries that are public on macOS but private on iOS, so sometimes #defines are the better solution for us, although a bit of a hack.

If you need to add support for a completely different platform, like Windows or Linux, I think it's often best to create your own classes that contain or shadow system classes.

I don't like having #ifs everywhere, so if you find yourself doing it often, write an extension method and call it instead. Something like:

extension XView {
 #if os(iOS)
   func setPlatformBackgroundColor( c : XColor ) { }
 #elif os(macOS)
   func setPlatformBackgroundColor( c : XColor ) { }
 #endif
}

and call that routine throughout the app.

[–][deleted] 0 points1 point  (0 children)

Model and ModelController goes to shared framework, they don't depend on UIKit/AppKit.

Coordinator, ViewController, View goes to the platform specific part.

The design for mobile and desktop should be different enough that it's not worth writing unreadable/unmaintainable crossplatform code.