2015 02-18 xxx-literalconvertible
Post on 17-Jul-2015
1.543 Views
Preview:
TRANSCRIPT
import Foundation
struct Complex: Equatable, IntegerLiteralConvertible, FloatLiteralConvertible { let x: Double let y: Double init(_ x: Double, _ y: Double) { self.x = x self.y = y } init(_ x: Double) { self.x = x self.y = 0 } init(integerLiteral x: IntegerLiteralType) { self.x = Double(x) self.y = 0 } init(floatLiteral x: FloatLiteralType) { self.x = x self.y = 0 } init(r: Double, θ: Double) { self.x = r * cos(θ) self.y = r * sin(θ) } }
func == (z: Complex, w: Complex) -> Bool { return z.x == w.x && z.y == w.y }
func Re(a: Complex) -> Double { return a.x }
func Im(a: Complex) -> Double {
import Foundation
struct Complex: Equatable, IntegerLiteralConvertible, FloatLiteralConvertible { let x: Double let y: Double init(_ x: Double, _ y: Double) { self.x = x self.y = y } init(_ x: Double) { self.x = x self.y = 0 } init(integerLiteral x: IntegerLiteralType) { self.x = Double(x) self.y = 0 } init(floatLiteral x: FloatLiteralType) { self.x = x self.y = 0 } init(r: Double, θ: Double) { self.x = r * cos(θ) self.y = r * sin(θ) } }
func == (z: Complex, w: Complex) -> Bool { return z.x == w.x && z.y == w.y }
func Re(a: Complex) -> Double { return a.x }
func Im(a: Complex) -> Double {
import Foundation
struct Complex: Equatable, IntegerLiteralConvertible, FloatLiteralConvertible { let x: Double let y: Double init(_ x: Double, _ y: Double) { self.x = x self.y = y } init(_ x: Double) { self.x = x self.y = 0 } init(integerLiteral x: IntegerLiteralType) { self.x = Double(x) self.y = 0 } init(floatLiteral x: FloatLiteralType) { self.x = x self.y = 0 } init(r: Double, θ: Double) { self.x = r * cos(θ) self.y = r * sin(θ) } }
func == (z: Complex, w: Complex) -> Bool { return z.x == w.x && z.y == w.y }
func Re(a: Complex) -> Double { return a.x }
func Im(a: Complex) -> Double {
let z = 2 + 3 * i
こういう風に書ける
{
Complex(3, 0) * Complex(0, 1){
z
{
Complex(0, 1)
Complex(2, 0) + Complex(3, 0) * Complex(0, 1)
let z = 2 + 3 * i
こういう風に書ける
{
Complex(3, 0) * Complex(0, 1){Complex(2, 0) + Complex(3, 0) * Complex(0, 1)
z
let z: Complex = Complex(2, 0) + Complex(3, 0) * Complex(0, 1)
{{
Complex(0, 1)
import Foundation
struct Complex: Equatable, IntegerLiteralConvertible, FloatLiteralConvertible { let x: Double let y: Double init(_ x: Double, _ y: Double) { self.x = x self.y = y } init(_ x: Double) { self.x = x self.y = 0 } init(integerLiteral x: IntegerLiteralType) { self.x = Double(x) self.y = 0 } init(floatLiteral x: FloatLiteralType) { self.x = x self.y = 0 } init(r: Double, θ: Double) { self.x = r * cos(θ) self.y = r * sin(θ) } }
func == (z: Complex, w: Complex) -> Bool { return z.x == w.x && z.y == w.y }
func Re(a: Complex) -> Double { return a.x }
func Im(a: Complex) -> Double {
xxxLiteralConvertible• ArrayLiteralConvertible
• BooleanLiteralConvertible
• DictionaryLiteralConvertible
• FloatLiteralConvertible
• NilLiteralConvertible
• IntegerLiteralConvertible
• StringLiteralConvertible
• UnicodeScalarLiteralConvertible
struct Matrix3x3<T>: ArrayLiteralConvertible { init(arrayLiteral elements: T...) { // ... } }
let m: Matrix3x3 = [1, 0, 0, 0, 1, 0, 0, 0, 1];
これぐらいのことはできる
let url: NSURL = “http://yahoo.co.jp”
let image: UIImage = “image.png"
let color: UIColor = 0x722F37
let url: NSURL = “http://yahoo.co.jp”
let image: UIImage = “image.png"
let color: UIColor = 0x722F37
↑ Swift 1.0 でできてたのが、1.1 でできなくなった…
Thanks...
Twitter: taketo1024Blog: http://taketo1024.hateblo.jp/
top related