parse-community / Parse-SDK-iOS-OSX

The Apple SDK for Parse Platform (iOS, macOS, watchOS, tvOS)
https://parseplatform.org
Other
2.81k stars 871 forks source link

Automatic loading of `PFObject` subclasses does not work on Xcode 16 / iOS 18 #1792

Closed mman closed 1 month ago

mman commented 5 months ago

New Issue Checklist

Issue Description

Parse iOS / OSX SDK uses PFObject instances for basically everything. All subclasses of PFObject are represented in MongoDB/PostgreSQL as collections/tables with given names. Mapping of the PFObject subclasses and their names in MongoDB/PostreSQL need to be known to Parse SDK so that PFObject subclasses can be loaded/stored properly to the database.

Originally registration of all classes was needed to be done manually by invoking code like this after initialising the Parse SDK:

[PFInstallation registerSubclass];
[PFUser registerSublcass];
[PFSession registerSubclass];

Then came https://github.com/parse-community/Parse-SDK-iOS-OSX/pull/967 that made things much simpler by scanning executable bundles (read frameworks) for all classes that are subclassing PFObject and registering them during SDK startup automatically.

The code is here:

https://github.com/parse-community/Parse-SDK-iOS-OSX/blob/c301262e17951e893a76a2448e7ce5f74f49bf85/Parse/Parse/Internal/Object/Subclassing/PFObjectSubclassingController.m#L384-L387

Building with Xcode 16 seems to break the functionality because objc_copyClassNamesForImage returns nothing.

More investigation is needed. I have not yet been able to see if this is a compiler option that needs to be toggled, or some new measure preventing apps from examining available runtime classes and their properties via Objective-C runtime reflection.

Steps to reproduce

Recompile your app with Xcode 16 and try to run against iOS 18. And see if that works for you.

It fails for me with unrelated error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid class name. Class names cannot start with an underscore.'

This is actually an exception coming from deep inside the Parse SDK where it tries to instantiate PFInstallation with collection name _Installation and failing because PFInstallation class was not registered.

Actual Outcome

Recompiling working code using Xcode 16 breaks the app.

Workaround

For the moment registering all required classes manually seems to work around the problem:

        Parse.initialize(
            with: ParseClientConfiguration() { config in

                config.applicationId = .apiAppIdString
                config.clientKey = .apiKeyString
                config.server = .apiURLString
                config.applicationGroupIdentifier = .appGroup
                config.networkRetryAttempts = 2

        })

        PFInstallation.registerSubclass()
        PFUser.registerSubclass()
        PFSession.registerSubclass()

Environment

Client

Server

parse-github-assistant[bot] commented 5 months ago

Thanks for opening this issue!

justasza commented 3 months ago

Im getting subclassing error with 4.1.1 version. 'The class PFPin must be registered with registerSubclass before using Parse.' Could this be related? Provided workaround would not work, because PFPin is internal.

rgomesbr commented 2 months ago

Same as @justasza here; running Xcode 16 RC — Version 16.0 (16A242) "The class PFPin must be registered with registerSubclass before using Parse."

mtrezza commented 2 months ago

Bumping bounty given the impact of this issue. Anyone wants to take a look at this?

mapierce commented 2 months ago

Hey @mtrezza I believe my linked PR should solve the issue

mobinzk commented 2 months ago

Hey @mtrezza I believe my linked PR should solve the issue

I've tested your code and it did fix the issue for me. Looking forward to this get merged.

Satyam-Tripathi-89 commented 2 months ago

Please merge this PR asap.

Satyam-Tripathi-89 commented 2 months ago

The class PFPin must be registered with registerSubclass before using Parse.

I am getting this error. Is there any workaround for it?

dhoerl commented 2 months ago

A closed Issue had the information on how to get Xcode to run with the Parse Swift Package, but its not here in this thread.

Copying this from a closed Issue: When adding Parse-SDK using Swift Package Manager use this commit d2b9580db7ce44d6d4d0f626d5e388901f81f5ed instead of the latest 4.1.1 version.

Also - you do not need any "registerSubClass()" statements - this commit is all you need.

mtrezza commented 2 months ago

The issue mentioned above is https://github.com/parse-community/Parse-SDK-iOS-OSX/issues/1809#issuecomment-2370258736.

toto commented 1 month ago

@dhoerl Note that this works for compiling for Simulator/Device in DEBUG it still breaks if SwiftUI Previews so something more is :/

dhoerl commented 1 month ago

I’m using it with Production and it’s fine.

KaitoKid commented 1 month ago

I've been able to verify that the commit hash mentioned by dhoerl does indeed work

mtrezza commented 1 month ago

Could someone try out https://github.com/parse-community/Parse-SDK-iOS-OSX/pull/1811 whether it fixes the issue? Also for SwiftUI previews, @toto?

Using a commit hash won't help much in the long term. We have 2 PRs open in attempts to fix this:

Jaycyn commented 1 month ago

Just tried #1811 and it seems to work

I was able to remove all of the .registerSubclass() calls and the

The class PFPin must be registered with registerSubclass before using Parse

is not being thrown.

So the initialization called per the below code seems good.

override func viewDidLoad() {
    super.viewDidLoad()

    let parseConfig = ParseClientConfiguration {
        $0.applicationId = "parseApplicationId"
        $0.clientKey = "parseClientKey"
        $0.server = "http://somehost:1337/parse"
        $0.isLocalDatastoreEnabled = true
    }

    Parse.initialize(with: parseConfig)
}

XCode 16, macOS Sonoma.

mtrezza commented 1 month ago

Could @toto or someone else confirm that this also works for SwiftUI previews?

toto commented 1 month ago

@mtrezza I can confirm it https://github.com/parse-community/Parse-SDK-iOS-OSX/pull/1811 also fixes the SwiftUI preview issue 👍

mtrezza commented 1 month ago

Great; I'll go ahead and merge

parseplatformorg commented 1 month ago

🎉 This change has been released in version 4.1.2