Cross-platform code

All,

[apologies if this is not the right forum - there's a few places it could have gone]


We've written a swift app for OSX (swift 2.2, couchbaselite syncing to cloud servers, all works fine) and need to port it to iOS. We are in the process of moving as much code into cross platform frameworks as we could - encryption, common utilities, models. Then we can start on the UI.


The projects (for each framework) were created using instructions from here - each has two targets, one for iOS, one for OSX.

http://basememara.com/creating-cross-platform-swift-frameworks-ios-watchos-tvos-via-carthage-cocoapods/


The encryption and common utils are fine - we have builds working in iOS and OSX. But the models framework goes a little awry. For some reason, we've started getting some weird errors such as follows:


Compiling the OSX target:

- Use of undeclared type 'NSDocumentTypeDocumentAttribute'

- Value of type 'NSAttributedString' has no member 'dataFromRange'


This code used to work when it was all a big OSX app. And docs for Mac and iOS versions of NSAttributedString definately list dataFromRange and NSDocumentTypeDocumentAttribute. When I type "NSAttributedString(", auto-completion now only offers me a very few completions, and it doesn't include dataFromRange. Is there some target setting I've messed up which reduces NSAttributedString?


Each source file in the project is associated with both build targets (iOS, macOS).


Further, on another line with the NSDocumentTypeDocumentAttribute replaced by "DocumentType":

                astr = try NSAttributedString(data: data,
                         options: ["DocumentType":gDocumentSaveFormat],
                         documentAttributes: nil)

gets the error:

- Type of expression is ambiguous without more context


Another error I see is in the iOS build (I dont see further errors becuase this stops compilation very early):

- No such module "CouchbaseLite"


This one is weird because CouchbaseLite is definately included in the Target's "Linked Frameworks and Libraries" and appears in Build Phases | Link Binaries With Libraries for both iOS and macOS. It doesn't happen on macOS.


I'd appreciate any ideas you have on this, and any resources on cross platform frameworks you can point me at.

Cheers.

Paul

Ok. I've got passed the CouchbaseLite issue. I dont know how, but it started working

after an Xcode stop/start.


The other problem is still there - I cannot use NSAttributedString functions in my macOS target.

I've given up on using multiple frameworks to structure an app. It just seems like xcode doesn't support it that well.

The idea was that we have 3 pieces of stand alone code - encryption, general utilities, model, plus the

UI code. We were hoping to create a project and framework for each, with targets so that each framework would be built for macOS

and iOS. Plus test code would be local to each framework project.

Encryption uses only the macOS Common Crypt and was completely stand alone.

Utilities used Encryption, and provided a set of general purpose functions

Model use both of the above.


Lastly, we would have a project for the UI code, which pulled in the appropriate frameworks above.

But xcode just doesn't seem to support this well.


Instead, we have a single project with all code, split into groups/folders for crypto, utils, model,

iOS, macOS. Plus targets to build iOS and macOS.


One big monolithic project, but it works.

Cross-platform code
 
 
Q