I have a struct and I would like to know if I can access variables using bracket syntax. Here is my struct:
import UIKit
public struct Pixel {
public var value: UInt32
public var red: UInt8
public var green: UInt8
public var blue: UInt8
public var alpha: UInt8
}
public struct RGBAImage {
public var pixels: [ImageProcessor_Sources.Pixel]
public var width: Int
public var height: Int
public init?(image: UIImage)
public func toUIImage() -> UIImage?
}
I would like to access the variable like so pixel["red"], as opposed to pixel.red
var image = RGBAImage(image: image!)!
var pixel = image.pixels[index]
pixel["red"] = 255 // as opposed to pixel.red
Is there any way to do this in Swift?
pixel["aosiubd"]?pixel.red = UInt8(max(0, min(255, rgbArray[0] + diff*intensity)))