Last active
August 29, 2015 14:17
-
-
Save danieljfarrell/4dbe7c322c90318d78dc to your computer and use it in GitHub Desktop.
Generic parameter 'U' cannot be bound to non-@objc protocol type 'SceneObject'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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