10

I'm trying to using Swift Combine to get the changed event of a property.

I have this class that publish the isLogged property

class CurrentUser: Account {
    static let me = CurrentUser() //Singleton 

    @Published var isLogged: Bool = false

}

that inherit from this other class that publish the profileImageVersion property

class Account {

    @Published var profileImageVersion: String?

    init(){
       self.profileImageVersion = ""
    }
}

I'm trying to subscribe to the published inherit profileImageVersion property like this without success!

// Subscribe to account image changes
userImageChangedSubscriber = CurrentUser.me.$profileImageVersion.receive(on: DispatchQueue.main).sink(receiveValue: { (imageVersion) in           
       ...
    }
})

The error is Fatal error: Call of deleted method

if, on the other hand, I subscribe to the isLogged property, all Is working fine...

// Subscribe to logged changes
userLoggedSubscriber = CurrentUser.me.$isLogged.receive(on: DispatchQueue.main).sink(receiveValue: { (logged) in
   ...
})

This error is thrown only on Xcode 11.4 beta 2 / iOS 13.4.
Using Xcode 11.3.1 / 13.3 all is working fine!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Oscar TJ
  • 524
  • 3
  • 16
  • Does this answer your question? [iOS Swift how to debug SIGABRT :"fatal error: call of deleted method" from a CocoaPod?](https://stackoverflow.com/questions/45051325/ios-swift-how-to-debug-sigabrt-fatal-error-call-of-deleted-method-from-a-coc) – Jacob Relkin Mar 01 '20 at 10:24
  • @JacobRelkin This is not caused by a pod but it's my own code. Do you think I can try to configure XCode with your link? If yes, why? – Oscar TJ Mar 01 '20 at 15:33
  • 1
    Well, I've managed to put provided code parts together and result works as expected. So I assume the issue is not in the provided code. Tested with Xcode 11.2 / iOS 13.2. – Asperi Mar 02 '20 at 16:41
  • 1
    Yes @Asperi! With XCode 11.3.1 / iOS 13.3 I don't get the fatal error and all is working good! – Oscar TJ Mar 02 '20 at 17:58
  • @BossOz Please file a bug report with Apple. – matt Mar 02 '20 at 18:13
  • 2
    Likely duplicate of https://stackoverflow.com/questions/60155665/xcode-11-4-beta-crash-on-published-property-subscription-whats-going-on. It gives a possible workaround, I think. – matt Mar 02 '20 at 18:14
  • @matt thank you! I don't know how to fix my issue with this – Oscar TJ Mar 02 '20 at 18:32

2 Answers2

0

I have this same crash, and as a temporary workaround I found that moving all your published properties to the concrete class you are using will fix the issue. I had a setup like this:

class EpisodesViewModel {
  @Published var episodes: [Episode]

  init(fetchRequest: NSFetchRequest<Episode>, context: NSManagedObjectContext? = nil) throws {
    ...
  }
  ...
}

With a subclass of this model that simply gave a fetch request:

final class LatestEpisodesViewModel: EpisodesViewModel {
    init() throws {
        try super.init(fetchRequest: Episode.latestFetchRequest())
    }
}

By changing my setup to this I was able to fix the crash:

class EpisodesViewModel {
    var fetchedEpisodes: [Episode]

    init(fetchRequest: NSFetchRequest<Episode>, context: NSManagedObjectContext? = nil) throws {
        ...
    }
    ...
}

final class LatestEpisodesViewModel: EpisodesViewModel {

    @Published var episodes: [Episode] = []

    override var fetchedEpisodes: [Episode] {
        didSet {
            episodes = fetchedEpisodes
        }
    }

    init() throws {
        try super.init(fetchRequest: Episode.latestFetchRequest())
    }
}

This certainly seems like an Apple bug to me, but this got me around the issue in the meantime.

gdavis
  • 2,556
  • 1
  • 20
  • 25
-1

I have this same crash on Xcode 11.4.1. I use "Clean Build Folder", build my project again and all works now fine !