Post

Replies

Boosts

Views

Activity

Local SwiftData to CloudKit migration
Hi, I've been working on an app that - so far - has only had to deal with offline data store. The usage is fairly simple: the user picks their favourite tv shows and networks, and they get persisted with SwiftData with all the correct relationships. Now, I would like to migrate the local storage of the users to a private CloudKit db, but every time I upgrade the app, the data seems to disappear completely. This is the snippet evolved through the attempt of migrating the data: Current Production code public static func makeModelContainer() -> ModelContainer { do { let processRequiresInMemory = ProcessInfo.processInfo.arguments.contains("inMemoryDatabasePreferred") let modelConfiguration = ModelConfiguration( isStoredInMemoryOnly: processRequiresInMemory, groupContainer: .automatic, cloudKitDatabase: .none ) let modelContainer = try ModelContainer( for: Country.self, Episode.self, Movie.self, Season.self, Show.self, Network.self, NetworkSubscription.self, migrationPlan: AppModelMigrationPlan.self, configurations: modelConfiguration ) return modelContainer } catch { fatalError("Could not initialize model container") } } Testing CloudKit enabled public static func makeModelContainer() -> ModelContainer { do { let processRequiresInMemory = ProcessInfo.processInfo.arguments.contains("inMemoryDatabasePreferred") let modelConfiguration = ModelConfiguration( "synced", isStoredInMemoryOnly: processRequiresInMemory, groupContainer: .automatic, cloudKitDatabase: .automatic ) let modelContainer = try ModelContainer( for: Country.self, Episode.self, Movie.self, Season.self, Show.self, Network.self, NetworkSubscription.self, migrationPlan: AppModelMigrationPlan.self, configurations: modelConfiguration ) return modelContainer } catch { fatalError("Could not initialize model container") } } } The differences, which I don't understand fully because I could not find documentation, are: ModelContainer(...) -> ModelContainer("synced", ...) cloudKitDatabase, from none to automatic. I have the feeling that changing the name of the configuration also changes some reference to the db itself, but if I were not to change the name, the app would have crashed because unable to migrate. What's the best approach to take here?
4
1
959
Jun ’24
XCFrameworks dependencies via Cocoapods
Hi! I've been trying to precompile one of our internal modules for a while, but I can't figure out how to get this done. Info Let's call the library I'm trying to precompile InternalLib. InternalLib is a mixed Swift/Objc static library, that depends on SwiftProtobuf and Protobuf. Our project use InternalLib as dependency. So far I've successfully done these steps: Step 1: Archive InternalLib The Example app in InternalLib fetches the dependencies correctly, and a script generates archives the library from the InternalLib-ExampleApp.xcworkspace. The result are 2 archives (iOS and simulator), compiled with this xcconfig: SKIP_INSTALL = NO BUILD_LIBRARY_FOR_DISTRIBUTION = YES SWIFT_OPTIMIZATION_LEVEL = -Osize OTHER_SWIFT_FLAGS = $(inherited) -verify-emitted-module-interface GCC_PREPROCESSOR_DEFINITIONS = $(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1 Step 2: Generate xcframework The next step is generating the xcframework. For this step we have the following script: function create_xcframework { for NAME in "InternalLib" "Protobuf" "SwiftProtobuf" do xcodebuild -create-xcframework \ -framework archives/InternalLib-iOS_sim.xcarchive/Products/Library/Frameworks/$NAME.framework \ -framework archives/InternalLib-iOS.xcarchive/Products/Library/Frameworks/$NAME.framework \ -output products/universal/$NAME.xcframework done } ..which successfully generates 3 XCFrameworks. Step 3: Run cocoapods At this step we regenerate the full project setup, and use cocoapods to connect each module to its dependencies. I've tried a few configurations: dependencies fetched via cocoapods, and specifying the resulting XCFrameworks as separate Podspecs, in order to create the dependencies by having the InternalLib.xcframework depending on XCFrameworks only. Both solutions fail in the same terms. Issues: Preprocessor flags not available: When I compile, the compiler flags present in InternalLib configuration seem unavailable. In this specific case, the headers are trying to resolve the Protobuf dependencies via local #include "Header.h", instead of going to #include <Protobuf/Header.h>, like so, even if the GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS flag is set in the project's preprocessor flags. # #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS # #import <Protobuf/GPBProtocolBuffers.h> # #else # #import "GPBProtocolBuffers.h" # #endif Missing symbols: By overriding the headers in order to forcefully use #import <Protobuf/GPBProtocolBuffers.h>, we get to the very end of the project compilation, just to fail with Undefined Symbol SwiftProtobuf.[...], which means the library of which InternalLib depends on was not found. My questions here are: Why is the preprocessor flag not seen while compiling the app? is this this configuration of having a XCFramework depend on cocoapods libs not supported? I am not sure if this is the best place to ask these questions, as it's using a 3rd party dependency manager, but maybe someone has tried a similar configuration in their project. Thanks!
1
0
2.9k
Jul ’21