Skip to content

Instantly share code, notes, and snippets.

@danieljfarrell
Last active August 29, 2015 14:17
Show Gist options
  • Save danieljfarrell/4dbe7c322c90318d78dc to your computer and use it in GitHub Desktop.
Save danieljfarrell/4dbe7c322c90318d78dc to your computer and use it in GitHub Desktop.
Generic parameter 'U' cannot be bound to non-@objc protocol type 'SceneObject'
extension Array {
mutating func removeObject<U: Equatable>(object: U) {
var index: Int?
for (idx, objectToCompare) in enumerate(self) {
if let to = objectToCompare as? U {
if object == to {
index = idx
}
}
}
if(index != nil) {
self.removeAtIndex(index!)
}
}
}
protocol SceneObject {
var position : CGPoint { get set }
var anchorPoint : CGPoint { get set }
}
class Scene {
var sceneObjects : [SceneObject] = Array()
func addSceneObject( anObject : SceneObject) {
sceneObjects.append(anObject)
}
func removeSceneSceneObject(anObject : SceneObject) {
sceneObjects.removeObject(anObject) // <-- This failed to compile with the error "Generic parameter 'U' cannot be bound to non-@objc protocol type 'SceneObject'"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment