[swift-evolution] [Pitch] Add Null struct to Foundation

michael.peternell at gmx.at michael.peternell at gmx.at
Fri Jun 24 01:21:27 CDT 2016


> Am 24.06.2016 um 07:59 schrieb J. Charles M. N. via swift-evolution <swift-evolution at swift.org>:
> 
> Doesn't Optional.None allready a placeholder for null values in swift?

Not really. What is the type of Optional.none? `let empty = Optional.none` does not compile, it says "Generic parameter 'Wrapped' could not be inferred". NSNull() is a unique concrete value, and it's compatible with Objective C, NSObject and AnyObject. We could of course use `Optional<Int16>.none`, but someone else may use `Optional<AnyObject>.none` instead. The extra type information is just misleading in this case.

> 
> I read some where that nil was the new way to represent null pointer in swift. 

It is, usually. But does it work in this case?

-Michael

> 
> --
> J. Charles 
> 
>> Le 24 juin 2016 à 00:59, Michael Peternell via swift-evolution <swift-evolution at swift.org> a écrit :
>> 
>> I think NSNull() should be used, not a struct. I don't think that a struct would be more performant. Or maybe the performance doesn't matter at all in any real-world usage scenario. But you may write a benchmark of a realistic (!) use-case (!) if you think otherwise... would be interesting to see the results.
>> 
>> Keeping with NSNull() also simplifies objc-interoperability.
>> 
>> -Michael
>> 
>>> Am 23.06.2016 um 06:14 schrieb Alsey Miller via swift-evolution <swift-evolution at swift.org>:
>>> 
>>> Add a struct Null to the Swift 3.0 Foundation value types. As a struct, Null is more performant (no ARC or memory allocation) than NSNull, and will be needed for Swift JSON decoders and libraries that want to use struct value types, and be free from classes for their model layer.
>>> 
>>> 
>>>   Coleman,
>>> 
>>> 
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list