Hãy nhìn vào tiêu đề Swift:
extension String : StringInterpolationConvertible {
init(stringInterpolationSegment expr: String)
init(stringInterpolationSegment expr: Character)
init(stringInterpolationSegment expr: UnicodeScalar)
init(stringInterpolationSegment expr: Bool)
init(stringInterpolationSegment expr: Float32)
init(stringInterpolationSegment expr: Float64)
init(stringInterpolationSegment expr: UInt8)
init(stringInterpolationSegment expr: Int8)
init(stringInterpolationSegment expr: UInt16)
init(stringInterpolationSegment expr: Int16)
init(stringInterpolationSegment expr: UInt32)
init(stringInterpolationSegment expr: Int32)
init(stringInterpolationSegment expr: UInt64)
init(stringInterpolationSegment expr: Int64)
init(stringInterpolationSegment expr: UInt)
init(stringInterpolationSegment expr: Int)
}
Tương tự:
func +(lhs: UInt8, rhs: UInt8) -> UInt8
func +(lhs: Int8, rhs: Int8) -> Int8
func +(lhs: UInt16, rhs: UInt16) -> UInt16
func +(lhs: Int16, rhs: Int16) -> Int16
func +(lhs: UInt32, rhs: UInt32) -> UInt32
func +(lhs: Int32, rhs: Int32) -> Int32
func +(lhs: UInt64, rhs: UInt64) -> UInt64
func +(lhs: Int64, rhs: Int64) -> Int64
func +(lhs: UInt, rhs: UInt) -> UInt
func +(lhs: Int, rhs: Int) -> Int
func +(lhs: Float, rhs: Float) -> Float
func +(lhs: Double, rhs: Double) -> Double
func +(lhs: Float80, rhs: Float80) -> Float80
Nếu nó đã có thể viết một chức năng chung cho tất cả các loại số khác nhau, họ sẽ đã làm điều đó, chắc chắn rồi. Vì vậy, câu trả lời cho câu hỏi của bạn phải có số
(Và trong mọi trường hợp họ khó có thể chia sẻ một lớp cha mẹ , vì họ không phải là lớp. Họ là những cấu trúc.)
Bây giờ, tất nhiên , nếu chỉ Int và Double được đề cập đến, bạn có thể mở rộng Int và Double để áp dụng một giao thức chung và đặt giao thức đó theo kiểu mong muốn ...
Họ chia sẻ nhiều giao thức chung - cả hai đều là 'AbsoluteValuable' , 'Comparable',' IntegerLiteralConvertible'. Xem [SwiftDoc] (http://swiftdoc.org/type/Double/hierarchy/) để xem dễ dàng về hệ thống phân cấp đầy đủ. Nhưng để thực sự trả lời câu hỏi này đòi hỏi thêm thông tin về lớp bạn đang khởi tạo - nó thực sự phụ thuộc vào giá trị 'value:' trong 'super.init' là gì. –
Nó đòi hỏi một đôi để khởi tạo, tuy nhiên, tôi figured tôi có thể bọc bất kỳ lớp (bao gồm) tăng gấp đôi trong một đôi và nó sẽ làm việc. – Jeef
'Int' và' Double' là cấu trúc, không phải lớp – newacct