Property names beginning with 'new' are not supported in Swift - is there a workaround?

Exception thrown when I open my synced Realm on iOS: "Thread 1: “Property names beginning with ‘new’ are not supported. Swift follows ARC’s ownership rules for methods based on their name, which results in memory leaks when accessing properties which return retained values via KVC.”

Ok, I understand the problem. I have a property called “newRecord” on one of my objects.

BUT - is there a way to remap this property to a different name in Swift? Or do I have to change my data model (and existing data), just because I now want to make an iOS app? (My other clients are Windows applications.)

Hi @polymath74,

This limitation has nothing to do with Realm, or not even Swift, as it dates back to the original Automatic Reference Counting (a.k.a. ARC) implementation in Clang. To ease the migration from a manual memory handling, some prefixes were mimicking the expected behaviour pre-ARC.

is there a way to remap this property to a different name in Swift?

You may try to use the Realm Object subscript functionality, i.e. something like

	var recordNew: <variable type> {
		get {
			return self["newRecord"] as! <variable type>
		set {
			self["newRecord"] = newValue

However that means you can’t use property wrappers (like @Persisted) anymore, so there may be side effects: I haven’t tried it myself except for syntax correctness, maybe someone from the Swift SDK team can chime in and clarify what those could be.


Thanks @Paolo_Manna this certainly allows me to connect without problems! :slight_smile:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.