I have a viewcontroller in Swift that works well, and I would like to use it from an Objective-C class. My problem is that I don't know how to use it.
I try to add the delegate in the header of my main Objective-C class.
@interface MainViewController : UIViewController <PlanningSearchDelegate>
But I think as it is a swift class, it doesn't work. The error is:
Cannot find protocol declaration for PlanningSearchDelegate
Then, I tried to add the @objc word in the swift class.
import UIKit
@objc protocol PlanningSearchDelegate
{
func planningSearchDidSelectResult(_ result:DALSearchResult)
}
class PlanningSearchViewController: UIViewController
{
}
extension PlanningSearchViewController: UITableViewDelegate
{
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
let result = _results[indexPath.row]
delegate?.planningSearchDidSelectResult(result)
}
}
But I have an error message:
Method cannot be a member of an @objc protocol because the type of the parameter cannot be represented in Objective-C.
I put the delegate = self in the prepareForSegue of the main Objective-C class without success :
else if ([segue.identifier isEqualToString:@"showSearchViewSegue"])
{
PlanningSearchViewController *searchViewController = segue.destinationViewController;
searchViewController.delegate = self;
}
The error message is:
Property 'delegate' not found on object of type "PlanningSearchViewController *'
Here is the DALSearchResult Class :
import Foundation
class DALSearchResult
{
var contactId: Int
var firstname: String
var lastname: String
var email: String
var phone: String
var city: String
var registrationId: Int?
var slotId: Int?
var vehicleId: Int?
var startDate: Date?
var vehicleName: String?
init(contactId:Int, firstname:String, lastname:String, email:String, phone:String, city:String)
{
self.contactId = contactId
self.firstname = firstname
self.lastname = lastname
self.email = email
self.phone = phone
self.city = city
}
convenience init(registrationId:Int, slotId:Int, vehicleId:Int, contactId:Int, firstname:String, lastname:String, email:String, phone:String, city:String, startDate:Date, vehicleName: String)
{
self.init(contactId: contactId, firstname: firstname, lastname: lastname, email: email, phone: phone, city: city)
self.registrationId = registrationId
self.vehicleId = vehicleId
self.slotId = slotId
self.startDate = startDate
self.vehicleName = vehicleName
}
}
Anyone has an idea ?
Thanks in advance.
DALSearchResult?class DALSearchResult: NSObjectMainViewControllerimplements protocol methodplanningSearchDidSelectResult? >> 2. Does thisif ([segue.identifier isEqualToString:@"showSearchViewSegue"])gets called? 3. Howdelegatevar declared?