@ThibaultVlacich Thanks for the report. It looks like we can't use empty string on URL, but is fine with NSURL🤔
In the meantime I suggest the following workarounds:
provide a default value: let url = Value.Required<URL>("url", default: URL(string: "http://")!)
use Value.Optional<URL> instead
user Value.Required<NSURL> instead (would fail if the empty NSURL is casted to URL)
In hindsight I should separate ImportableAttributeTypes that can and cannot have "empty" values. Ill look for an elegant way for it.
@JohnEstropia commented on GitHub (May 28, 2017):
@ThibaultVlacich Thanks for the report. It looks like we can't use empty string on `URL`, but is fine with `NSURL` 🤔
In the meantime I suggest the following workarounds:
- provide a default value: `let url = Value.Required<URL>("url", default: URL(string: "http://")!)`
- use `Value.Optional<URL>` instead
- user `Value.Required<NSURL>` instead (would fail if the empty `NSURL` is casted to `URL`)
In hindsight I should separate `ImportableAttributeType`s that can and cannot have "empty" values. Ill look for an elegant way for it.
@ThibaultVlacich Okay I "fixed" this in 4.0.1. Basically some types will now require the default: argument.
letflag=Value.Required<Bool>("flag")// OK. Defaults to falseletage=Value.Required<Int>("age")// OK. Defaults to 0letname=Value.Required<String>("name")// OK. Defaults to "" (empty string)leturl=Value.Required<URL>("url")// Compiler errorletblog=Value.Required<URL>("blog",default:URL(string:"http://")!)// OK
These "non-emptyable" types include URL, NSURL, Date, NSDate, UUID, and NSUUID.
@JohnEstropia commented on GitHub (May 28, 2017):
@ThibaultVlacich Okay I "fixed" this in 4.0.1. Basically some types will now require the `default:` argument.
```swift
let flag = Value.Required<Bool>("flag") // OK. Defaults to false
let age = Value.Required<Int>("age") // OK. Defaults to 0
let name = Value.Required<String>("name") // OK. Defaults to "" (empty string)
let url = Value.Required<URL>("url") // Compiler error
let blog = Value.Required<URL>("blog", default: URL(string: "http://")!) // OK
```
These "non-emptyable" types include `URL`, `NSURL`, `Date`, `NSDate`, `UUID`, and `NSUUID`.
Yup, I recommend that as well. But now the compiler checks it for us :)
Closing this issue, thanks again!
@JohnEstropia commented on GitHub (May 29, 2017):
Yup, I recommend that as well. But now the compiler checks it for us :)
Closing this issue, thanks again!
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @ThibaultVlacich on GitHub (May 28, 2017).
I'm trying the new "no .xcdatamodeld" functionality of CoreStore 4, and I have a crash when declaring a
Valueof typeURLHere is the interesting part of my model:
And here's the full crash stack trace, it crashes on
ImportableAttributeType.swift, line 568:@JohnEstropia commented on GitHub (May 28, 2017):
@ThibaultVlacich Thanks for the report. It looks like we can't use empty string on
URL, but is fine withNSURL🤔In the meantime I suggest the following workarounds:
let url = Value.Required<URL>("url", default: URL(string: "http://")!)Value.Optional<URL>insteadValue.Required<NSURL>instead (would fail if the emptyNSURLis casted toURL)In hindsight I should separate
ImportableAttributeTypes that can and cannot have "empty" values. Ill look for an elegant way for it.@JohnEstropia commented on GitHub (May 28, 2017):
@ThibaultVlacich Okay I "fixed" this in 4.0.1. Basically some types will now require the
default:argument.These "non-emptyable" types include
URL,NSURL,Date,NSDate,UUID, andNSUUID.@ThibaultVlacich commented on GitHub (May 28, 2017):
Thanks. I've choose to mark my url as Optional, a bit cleaner I think :)
@JohnEstropia commented on GitHub (May 29, 2017):
Yup, I recommend that as well. But now the compiler checks it for us :)
Closing this issue, thanks again!