> On Jun 22, 2016, at 9:12 AM, Charlie Monroe wrote:
>
> Please consider the following code:
>
> let myString: String? = "Hello"
> let anyValue: Any = myString
> let obj: AnyObject? = anyValue as? AnyObject // nil, since it's
> Optional, String being struct,
>
> I'd call that a bug, not something requiring evolution discussion. We're
> trying to phase this behavior out of dynamic casts, though (see
> https://github.com/apple/swift-evolution/blob/master/proposals/0083-remove-bridging-from-dynamic-casts.md).
Ok, I've filed a bug report.
My suggestion t
> On Jun 22, 2016, at 9:12 AM, Charlie Monroe via swift-evolution
> wrote:
>
> Please consider the following code:
>
> let myString: String? = "Hello"
> let anyValue: Any = myString
> let obj: AnyObject? = anyValue as? AnyObject // nil, since it's
> Optional, String being struct,
>
Please consider the following code:
let myString: String? = "Hello"
let anyValue: Any = myString
let obj: AnyObject? = anyValue as? AnyObject // nil, since it's
Optional, String being struct,
// no implicit bridge to AnyObject.
(myString as AnyObject will
> On Jun 21, 2016, at 10:11 PM, Charlie Monroe
> wrote:
>
> Unfortunately, this is not as easy, because automatic bridging won't be
> applied:
>
> let myString: String? = "Hello"
> let anyValue: Any = myString
>
> myString as? AnyObject // _NSContiguousString
> anyValue as? AnyObject // nil,
> On Jun 22, 2016, at 5:51 PM, John McCall wrote:
>
>
>> On Jun 22, 2016, at 12:15 AM, L. Mihalkovic via swift-evolution
>> wrote:
>>
>> Func asOpt(v:Any) -> Optional {
>> If let val = v as? T {
>> Return val
>> }
>> Return nil
>> }
>> Regards
>> LM
>> (From mobile)
>
> This is j
> On Jun 22, 2016, at 12:15 AM, L. Mihalkovic via swift-evolution
> wrote:
>
> Func asOpt(v:Any) -> Optional {
> If let val = v as? T {
> Return val
> }
> Return nil
> }
> Regards
> LM
> (From mobile)
This is just:
return v as? T
John.
>
> On Jun 22, 2016, at 7:11 AM, Charlie Mo
Nice!
Would you consider this as something that should be part of the language? IMHO
working this out takes much more time than it should and these two functions
would definitely help out a lot.
> On Jun 22, 2016, at 9:15 AM, L. Mihalkovic
> wrote:
>
> Func asOpt(v:Any) -> Optional {
> If
Ext Optional {
Func ifUnwraps(_ h: T->()){
Switch self
Case .Some(let v):
If let t=v as? T { h(t) } // invoke if T matches
Def:
Brk
}
Regards
LM
(From mobile)
> On Jun 22, 2016, at 9:15 AM, L. Mihalkovic
> wrote:
>
> Func asOpt(v:Any) -> Optional {
> If let val = v as?
Func asOpt(v:Any) -> Optional {
If let val = v as? T {
Return val
}
Return nil
}
Regards
LM
(From mobile)
> On Jun 22, 2016, at 7:11 AM, Charlie Monroe via swift-evolution
> wrote:
>
> Unfortunately, this is not as easy, because automatic bridging won't be
> applied:
>
> let myStrin
Unfortunately, this is not as easy, because automatic bridging won't be applied:
let myString: String? = "Hello"
let anyValue: Any = myString
myString as? AnyObject // _NSContiguousString
anyValue as? AnyObject // nil, since String is struct
let array: [String]? = ["Hello"]
let anyArray: Any = a
'as?' should already do this. If you have an Any that contains an Optional
and cast 'any as? T', you'll get the value inside the Optional if there is one,
or the cast will fail if the optional is nil or the type doesn't match.
-Joe
> On Jun 20, 2016, at 11:00 PM, Charlie Monroe via swift-evolut
I've recently written a CoreData editor on iOS which automatically generates UI
based on the model which is described using classes such as PrimitiveProperty,
etc. Since it automatically sets the value on the entity, it needs to convert
the value to AnyObject in order to pass it to setValue(_:fo
13 matches
Mail list logo