Reputation: 333
I am using Swift playgrounds trying to make an interactive app in which the user can click on a button to perform an action.
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tapBlurButton(_:)))
func tapBlurButton(_ sender: UITapGestureRecognizer) {
print("Please Help!")
}
It is giving me the error:
'use of unresolved identifier self'
. How can I fix this in Swift 3?
Upvotes: 0
Views: 1567
Reputation: 39
Put those code in class.
class SomeClass: NSObject {
[your code with self]
}
Because there's nothing to say self
and playground.
And How to reference Swift Playground itself?
Upvotes: -1
Reputation: 10772
That code isn't going to work unless it's inside a class that inherits from NSObject
.
If it is in a class and you're still getting that error, it's probably because tapGesture
is a property. Properties generally can't use self
during initialization.
Upvotes: 0