I'm making a photo marker application and need to make a factory pattern for marker. I think it is not very flexible and overall not good.
Would you check my code and suggest what could be improved?
import Foundation
enum MarkerType: String {
case Shape, Image
}
enum MarkerError: ErrorType {
case ImageNoExist
case ShapeNoExist
}
struct ImageMarker {
static func make(type: String) -> UIImageView {
var imageStr: String = ""
switch type {
case "X":
imageStr = "close.png"
break
default: break
}
let image = UIImage(named: imageStr)
let tintedImage = image?.imageWithRenderingMode(.AlwaysTemplate)
let imageView = UIImageView(image: tintedImage)
imageView.tintColor = UIColor.redColor()
return imageView
}
}
struct ShapeMarker {
static func make(type: String) -> UIView {
var shape: UIView = UIView()
switch type {
case "CIRCLE":
//shape = CircleView()
break
default: break
}
return shape
}
}
typealias Factory = (String) -> AnyObject
class MarkerHelper {
class func factoryFor(type: MarkerType) -> Factory {
switch type {
case .Shape:
return ShapeMarker.make
case .Image:
return ImageMarker.make
}
}
}