24.6 C
Canberra
Thursday, November 14, 2024

ios – Easy Migration in SwiftData doesn’t work


I’ve an app with some SwiftData Fashions. One is known as Tapas and it has a relationship with TapasAsana. One Tapas has many Asanas, so I linked them with a relationship. This all works fantastic thus far.

Now I simply forgot one property in TapasAsana. I examine gentle migration and it must be simple to simply add that property. However irrespective of if I add it on the finish or in the midst of the properties it breaks my app. The app compiles and runs, however the outdated Knowledge would not get proven anymore. And cretaing new ones within the app additionally will not work, attempting to straight create a TapasAsana crashes the App.

That is the code for the TapasAsana Mannequin, the one the place I’m including a property. The brand new property is known as recoupCount.

import Basis
import SwiftData

@Mannequin
class TapasAsana {
    var title: String
    var length: Int           /// How lengthy to execute every day
    var timeToday: Int          /// Time executed already at this time
    var recoupCount: Int      /// What number of recoups this Asana has.
    
    var polar: Bool             /// If it's a polar Asana
    var doneToday: Bool         /// Whether it is accomplished at this time
    
    init(title: String = "Padahastasana", length: Int = 5 * 60, timeToday: Int = 0, recoupCount: Int = 0, polar: Bool = false, doneToday: Bool = false) {
        self.title = title
        self.length = length
        self.timeToday = timeToday
        self.recoupCount = recoupCount
        self.polar = polar
        self.doneToday = doneToday
    }
}

I attempted to simply add the brand new Property, so as to add it on the final place to not confuse SwiftData with the order. However none of that works. I did not strive extra as a result of studying about migration stated the straightforward add of a property ought to work tremendous.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles