Swiftdata get-error (Thread 6: EXC_BREAKPOINT (code=1, subcode=0x1cc165d0c)) -issues when inserting a new swiftdata

When I do the classic modelcontext.insert(myModel) everything works fine. But since I want at the same time initialize a local notification using myModels UUID as the identifier the app crashes. Now, I tried out not initializing the notification directly, just reading the UUID.uuidstring when viewing the newly inserted myModel. But it cannot fetch the UUID (the variable is called objectID in my case), it only crashes. Why?

The error is: Thread 6: EXC_BREAKPOINT (code=1, subcode=0x1cc165d0c

My model:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Model
final class HomeObject: ObservableObject {
let objectID: UUID = UUID()
var objectType: ObjectType?
var room: String?
var roomPictogram: RoomPictograms?
var dateOfPurchase: Date?
var checkTimeInterval: Int?
var lastChecked: Date?
var checkDate: Date?
var replacementDate: Date?
var home: Home?
init(objectType: ObjectType?, room: String?, roomPictogram: RoomPictograms?, dateOfPurchase: Date? = nil, checkTimeInterval: Int?, lastChecked: Date?, checkDate: Date?, replacementDate: Date?, home: Home?) {
self.objectType = objectType
self.room = room
self.roomPictogram = roomPictogram
self.dateOfPurchase = dateOfPurchase
self.checkTimeInterval = checkTimeInterval
self.lastChecked = lastChecked
self.checkDate = checkDate
self.replacementDate = replacementDate
self.home = home
}
}
</code>
<code>@Model final class HomeObject: ObservableObject { let objectID: UUID = UUID() var objectType: ObjectType? var room: String? var roomPictogram: RoomPictograms? var dateOfPurchase: Date? var checkTimeInterval: Int? var lastChecked: Date? var checkDate: Date? var replacementDate: Date? var home: Home? init(objectType: ObjectType?, room: String?, roomPictogram: RoomPictograms?, dateOfPurchase: Date? = nil, checkTimeInterval: Int?, lastChecked: Date?, checkDate: Date?, replacementDate: Date?, home: Home?) { self.objectType = objectType self.room = room self.roomPictogram = roomPictogram self.dateOfPurchase = dateOfPurchase self.checkTimeInterval = checkTimeInterval self.lastChecked = lastChecked self.checkDate = checkDate self.replacementDate = replacementDate self.home = home } } </code>
@Model
final class HomeObject: ObservableObject {

let objectID: UUID = UUID()
var objectType: ObjectType?
var room: String?
var roomPictogram: RoomPictograms?
var dateOfPurchase: Date?
var checkTimeInterval: Int?
var lastChecked: Date?
var checkDate: Date?
var replacementDate: Date?
var home: Home?

init(objectType: ObjectType?, room: String?, roomPictogram: RoomPictograms?, dateOfPurchase: Date? = nil, checkTimeInterval: Int?, lastChecked: Date?, checkDate: Date?, replacementDate: Date?, home: Home?) {
    
    self.objectType = objectType
    self.room = room
    self.roomPictogram = roomPictogram
    self.dateOfPurchase = dateOfPurchase
    self.checkTimeInterval = checkTimeInterval
    self.lastChecked = lastChecked
    self.checkDate = checkDate
    self.replacementDate = replacementDate
    self.home = home
    
}
}

And the code for saving the model:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> func addItem(_ homes: [Home], _ modelContext: ModelContext, _ dismiss: DismissAction) {
var replacementDate: Date = .now
if dateOfPurchaseBool == false {
dateOfPurchase = .now
replacementDate = .now.addingTimeInterval(findReplaceTimeInterval(objectType))
} else {
replacementDate = dateOfPurchase.addingTimeInterval(findReplaceTimeInterval(objectType))
}
let checkTimeInterval = findTimeInterval(objectType)
var checkDate: Date {
var components = DateComponents()
components.month = checkTimeInterval
return Calendar.current.date(byAdding: components, to: .now)!
}
let newObject = HomeObject(objectType: objectType, room: objectPlacement, roomPictogram: roomImage, dateOfPurchase: dateOfPurchase, checkTimeInterval: checkTimeInterval, lastChecked: .now, checkDate: checkDate, replacementDate: replacementDate, home: findHome(HomeViewModel().selectedHome!, homes))
modelContext.insert(newObject)
modelContext.insert(RoomModel(rooms: objectPlacement))
let timeintervalMonth = checkDate.timeIntervalSinceNow + 100
Task {
var localNotification = LocalNotification(identifier: newObject.objectID.uuidString,
title: "Time to check",
body: "(objectType) in (objectPlacement)",
timeInterval: timeintervalMonth,
repeats: false)
localNotification.subtitle = ""
localNotification.bundleImageName = ""
localNotification.userInfo = ["nextView" : NextView.homeObjectDetailView.rawValue]
localNotification.userInfoMoode = ["object" : newObject.objectID.uuidString]
localNotification.categoryIdentifier = "snooze"
await NotificationViewModel().schedule(localNotification: localNotification, newObject)
}
dismiss()
}
</code>
<code> func addItem(_ homes: [Home], _ modelContext: ModelContext, _ dismiss: DismissAction) { var replacementDate: Date = .now if dateOfPurchaseBool == false { dateOfPurchase = .now replacementDate = .now.addingTimeInterval(findReplaceTimeInterval(objectType)) } else { replacementDate = dateOfPurchase.addingTimeInterval(findReplaceTimeInterval(objectType)) } let checkTimeInterval = findTimeInterval(objectType) var checkDate: Date { var components = DateComponents() components.month = checkTimeInterval return Calendar.current.date(byAdding: components, to: .now)! } let newObject = HomeObject(objectType: objectType, room: objectPlacement, roomPictogram: roomImage, dateOfPurchase: dateOfPurchase, checkTimeInterval: checkTimeInterval, lastChecked: .now, checkDate: checkDate, replacementDate: replacementDate, home: findHome(HomeViewModel().selectedHome!, homes)) modelContext.insert(newObject) modelContext.insert(RoomModel(rooms: objectPlacement)) let timeintervalMonth = checkDate.timeIntervalSinceNow + 100 Task { var localNotification = LocalNotification(identifier: newObject.objectID.uuidString, title: "Time to check", body: "(objectType) in (objectPlacement)", timeInterval: timeintervalMonth, repeats: false) localNotification.subtitle = "" localNotification.bundleImageName = "" localNotification.userInfo = ["nextView" : NextView.homeObjectDetailView.rawValue] localNotification.userInfoMoode = ["object" : newObject.objectID.uuidString] localNotification.categoryIdentifier = "snooze" await NotificationViewModel().schedule(localNotification: localNotification, newObject) } dismiss() } </code>
    func addItem(_ homes: [Home], _ modelContext: ModelContext, _ dismiss: DismissAction) {
    
    var replacementDate: Date = .now
    
    if dateOfPurchaseBool == false {
        dateOfPurchase = .now
        replacementDate = .now.addingTimeInterval(findReplaceTimeInterval(objectType))
    } else {
        replacementDate = dateOfPurchase.addingTimeInterval(findReplaceTimeInterval(objectType))
    }
    
    let checkTimeInterval = findTimeInterval(objectType)
    var checkDate: Date {
        var components = DateComponents()
        components.month = checkTimeInterval
        return Calendar.current.date(byAdding: components, to: .now)!
    }
    
    let newObject = HomeObject(objectType: objectType, room: objectPlacement, roomPictogram: roomImage, dateOfPurchase: dateOfPurchase, checkTimeInterval: checkTimeInterval, lastChecked: .now, checkDate: checkDate, replacementDate: replacementDate, home: findHome(HomeViewModel().selectedHome!, homes))
    
    modelContext.insert(newObject)
    modelContext.insert(RoomModel(rooms: objectPlacement))
    
    let timeintervalMonth = checkDate.timeIntervalSinceNow + 100

        
            Task {
                var localNotification = LocalNotification(identifier: newObject.objectID.uuidString,
                                                          title: "Time to check",
                                                          body: "(objectType) in (objectPlacement)",
                                                          timeInterval: timeintervalMonth,
                                                          repeats: false)
                localNotification.subtitle = ""
                localNotification.bundleImageName = ""
                localNotification.userInfo = ["nextView" : NextView.homeObjectDetailView.rawValue]
                localNotification.userInfoMoode = ["object" : newObject.objectID.uuidString]
                localNotification.categoryIdentifier = "snooze"
                await NotificationViewModel().schedule(localNotification: localNotification, newObject)
            }
        
        
        dismiss()
    
}

When the app is crashing this is what i get underneath the UUID variable:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{
@storageRestrictions(accesses: _$backingData, initializes: _objectID)
init(initialValue) {
_$backingData.setValue(forKey: .objectID, to: initialValue)
_objectID = _SwiftDataNoType()
}
get {
_$observationRegistrar.access(self, keyPath: .objectID)
return self.getValue(forKey: .objectID)
}
set {
_$observationRegistrar.withMutation(of: self, keyPath: .objectID) {
self.setValue(forKey: .objectID, to: newValue)
}
}
</code>
<code>{ @storageRestrictions(accesses: _$backingData, initializes: _objectID) init(initialValue) { _$backingData.setValue(forKey: .objectID, to: initialValue) _objectID = _SwiftDataNoType() } get { _$observationRegistrar.access(self, keyPath: .objectID) return self.getValue(forKey: .objectID) } set { _$observationRegistrar.withMutation(of: self, keyPath: .objectID) { self.setValue(forKey: .objectID, to: newValue) } } </code>
{
@storageRestrictions(accesses: _$backingData, initializes: _objectID)
init(initialValue) {
    _$backingData.setValue(forKey: .objectID, to: initialValue)
    _objectID = _SwiftDataNoType()
}
get {
    _$observationRegistrar.access(self, keyPath: .objectID)
    return self.getValue(forKey: .objectID)
}
set {
    _$observationRegistrar.withMutation(of: self, keyPath: .objectID) {
        self.setValue(forKey: .objectID, to: newValue)
    }
}

}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật