Initializing an array from sequence or by repeating an element is not implemented

swift

(Marko Havu) #1

Array initializers init<S>(S) and init(repeating: Array.Element, count: Int) don’t seem to be implemented:

  • Array(array[0 ... 3]) gives ‘Parameter should be labeled “of”’
  • [Int](0..<256) gives ‘No overloaded constructor with these parameters for type “Array<Int64!>”, best matching overload is “init(_ sequence: INSFastEnumeration) -> Array<Int64!>!”’, which in turn results in ‘parameter 1 is “Range” should be “INSFastEnumeration”’
  • [UInt8](repeating: 0, count: padding) gives “No matching overload”
  • etc.

(marc hoffman) #2

hmm, I do see

    public init(sequence: ISequence<T>) {

on SwiftArray, in Swift Base Library (https://github.com/remobjects/SwiftBaseLibrary/blob/master/Source/Array.swift). Does that not do what you need? I’ll look at adding init(repeating: count).

Fwiw, contributions to SBL are appreciated :wink:


(marc hoffman) #3

Update:

maybe this just needs to be renamed, to drop the external sequence: name prefix? Ranges should be sequences…


(Marko Havu) #4

Ah yes, that must be it: dropping the prefix should work. Thanks for the GitHub link. You can expect a bunch of pull requests now. :slight_smile:


(marc hoffman) #5

Oddly, I do see a convenience init that takes a sequence, w.o the prefix. weird that that didn’t get used. I;ll need to check more…


(marc hoffman) #6

Excellent!