Swift 3: Unrecognized selector sent to instance Xcode 8
If you are using swift
3 your selector
should be like this
#selector(self.handleTap(recognizer:))
Swift 3 Xcode 8 - SwiftValue encodeWithCoder - unrecognized selector sent to instance
The problem is that you are trying to archive an optional. Replace this line:
if (object != nil) {
with:
if let object = object {
Unrecognized selector sent to instance error when pressing UIButton in Xcode 8/Swift 3
It seems like you have rename your IBAction
method name earlier it was different and it is connected to the previous name inside your storyboard. So just disconnect your action method and reconnect it appropriately.
Swift unrecognized selector sent to instance error
Two changes for Swift 3:
The selector should look like:
#selector(ClassName.followButtonClick(_:))
The function should have an underscore:
@IBAction func followButtonClick(_ sender: UIButton!) { ...
Notice that these two should be in the same class, otherwise, make sure you initialize the ClassName
class.
If you want the selector method(followButtonClick(_:)
) to be in the UITableViewCell
class. Remove @IBAction
(I don't think you need it there):
func followButtonClick(_ sender: UIButton!) { ...
Unrecognized selector sent to instance 0x7fecc7011000 In Swift
The problem is this outlet:
IBOutlet weak var tableView: UITableView!
You have hooked it up in the storyboard to the wrong object. It is hooked to the cell, not the table view. It looks like you must have hooked it up and then changed the class of the thing it is hooked to.
How to fix 'unrecognized selector sent to instance' in Swift 4
A class which adopts NSCoding
(not NSCoder
) must be a subclass of NSObject
.
class Items: NSObject, NSCoding { ...
But in Swift 4 it's highly recommended to drop the ObjC runtime and use lightweight Codable
protocol to serialize custom structs or classes to Property List
or JSON
.
The class can be reduced to a struct
struct Item : Codable {
var title : String
var completed : Bool
}
Load data :
guard let data = UserDefaults.standard.data(forKey: "list") else {
self.list = []
return
}
do {
self.list = try JSONDecoder().decode([Item].self, from: data)
} catch {
print(error)
self.list = []
}
Save data :
do {
let itemData = try JSONEncoder().encode(list)
UserDefaults.standard.set(itemData, forKey: "list")
} catch {
print(error)
}
A few notes:
- Never declare properties as implicit unwrapped optional which are initialized in
init
methods. Either use regular optional?
or non-optional. - This is Swift: No trailing semicolons.
- Structs and classes are supposed to be named in singular form (
Item
).
Related Topics
Uibutton Remove All Target-Actions
How to Clear or Clean Specific Pod from the Local Cocoapods Cache
What's the State of Developing iOS Apps in Linux
Swiftui Show/Hide Title Issues with Navigationbar
Converting Int to Float Loses Precision for Large Numbers in Swift
iOS 9 Objective-C Screen Size Issues
How Can Split from String to Array by Chunks of Given Size
Returning Object from Callback in Swift
Reading Text and Images from a PDF Document in iOS
Uilabel Text Truncation VS. Line Breaks in Text
Best Way to Use Background Location Updates in iOS (Swift)
How to Use Nsdateformatter to Venezuela
How to Install an Unsigned IPA File on My Device Using an Apple Developer Account
Removing Duplicate Objects from Fetch Based on Object Parameter Updated Swift
Saving and Loading Up a Highscore in Swift Using Nsuserdefaults
iOS 7 Uitableview: How to Remove Space Between Navigation Bar and First Cell