I noticed that when there is a generic class, there is a , which I decided must use T for "Type". What does the S mean in . I see it in the function definition for the instance function initialize(from: S) -> (S.Iterator, UnsafeMutableBufferPointer.Index) of UnsafeMutableBufferPointer.
What do <T> and <S> mean as distinguished from each other.
Hard to tell from the description, but it sounds like S is what the person who wrote the code chose to mean "some other type that doesn't have to be T".
See:
func test<T, S>(one : T, two : S) -> String
{
return "\(one) \(two)"
}
print(test(one: Double(1), two: true))
There are a few places where this can be useful, such as Maps or Dictionaries, where the key type can be anything, and the value type can also be some other anything. (Note: T and S can also be the same thing, like with a Dictionary<String,String>.)
Which declaration exactly ?
In doc, I find only:
func initialize<S>(from source: S) -> (S.Iterator, UnsafeMutableBufferPointer<Element>.Index) where Element == S.Element, S : Sequence
ScottMichaud_LT wrote:
it sounds like
Sis what the person who wrote the code chose to mean "some other type that doesn't have to beT".
Right.
Claude31 wrote:
In doc, I find only:
Agreed.
In this declaration:
-
<S>introduces a typeS -
S : Sequenceindicates thatSmust conform toSequence -
Element == S.Elementindicates that the element type of the sequence,S.Element, must matchElement, that is, the element type of theUnsafeMutableBufferPointer
In short, the method in question can populate the buffer from any sequence whose elements match the buffer.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"