How do you set the default value of a UUID attribute in the core data xcdatamodel. if I set the attribute as non-optional it requires a default value. in code I'd set it using UUID() to assign a value but this doesn't work in the xcdatamodel
How do you set the default value of a UUID attribute in the core data xcdatamodel. if I set the attribute as non-optional it requires a default value. in code I'd set it using UUID() to assign a value but this doesn't work in the xcdatamodel
You can use a string representation of any UUID() value as a default. For example: 0CF044A3-333C-4B22-8FEB-F68B004B6C96 could be a default.
To quickly generate a new UUID a terminal could be used. Just type swift there and then import Foundation and then print(UUID()). This will give you a new random UUID.
It's not necessary to assign a default value in the model.
In the class override awakeFromInsert
override func awakeFromInsert() {
super.awakeFromInsert()
uuid = UUID()
}