FailableCustomPersistable
public protocol FailableCustomPersistable : _CustomPersistable
A type which can be mapped to and from a type which Realm supports.
This protocol is identical to CustomPersistable
, except with
init?(persistedValue:)
instead of init(persistedValue:)
.
FailableCustomPersistable types are force-unwrapped in
non-Optional contexts, and collapsed to nil
in Optional contexts.
That is, if you have a value that can’t be converted to a URL, reading a
@Persisted var url: URL
property will throw an unwrapped failed exception, and
reading from Persisted var url: URL?
will return nil
.
-
Construct an instance of the this type from the persisted type, returning nil if the conversion is not possible.
This function must not return
nil
when given a default-initalizedPersistedType()
.Declaration
Swift
init?(persistedValue: PersistedType)
-
Construct an instance of the persisted type from this type.
Declaration
Swift
var persistableValue: PersistedType { get }