Query on init methods in Data.swift


(Simon Evans) #1

Hi

I was looking at Data.swift and noticed that 2 of the init methods
were different in corelibs-foundation v swift stdlib

https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/Data.swift has

public init?(capacity: Int)
public init?(count: Int)

https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/Data.swift has

public init(capacity: Int)
public init(count: Int)

Which are the correct method signatures? I was just doing a PR to fix
init?(count:) not zeroing the data and I wanted to make sure I had this
correct as well

Thanks
Simon


(Tony Parker) #2

Hi Simon,

The correct one is the non-optional version. We changed it after some discussion about if it made sense for Data to attempt to return nil here, when there are so many ways for memory allocation to fail without returning an optional.

We’re working on updating the swift-corelibs-foundation API to match the overlay over the next few weeks.

- Tony

···

On Aug 2, 2016, at 9:27 AM, Simon Evans via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hi

I was looking at Data.swift and noticed that 2 of the init methods
were different in corelibs-foundation v swift stdlib

https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/Data.swift has

public init?(capacity: Int)
public init?(count: Int)

https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/Data.swift has

public init(capacity: Int)
public init(count: Int)

Which are the correct method signatures? I was just doing a PR to fix
init?(count:) not zeroing the data and I wanted to make sure I had this
correct as well

Thanks
Simon
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Simon Evans) #3

Hi Tony,

Thats good to know, I have actually done a fix to convert them both to non-optional, I will create a PR once the jenkins CI is working again and my PR#501 is merged.

Simon

···

On 8 Aug 2016, at 18:05, Tony Parker <anthony.parker@apple.com> wrote:

Hi Simon,

The correct one is the non-optional version. We changed it after some discussion about if it made sense for Data to attempt to return nil here, when there are so many ways for memory allocation to fail without returning an optional.

We’re working on updating the swift-corelibs-foundation API to match the overlay over the next few weeks.

- Tony

On Aug 2, 2016, at 9:27 AM, Simon Evans via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hi

I was looking at Data.swift and noticed that 2 of the init methods
were different in corelibs-foundation v swift stdlib

https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/Data.swift has

public init?(capacity: Int)
public init?(count: Int)

https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/Data.swift has

public init(capacity: Int)
public init(count: Int)

Which are the correct method signatures? I was just doing a PR to fix
init?(count:) not zeroing the data and I wanted to make sure I had this
correct as well

Thanks
Simon
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev