0
votes

I am converting mine whole project from Objective-C to Swift... while converting i am getting this issue as "Cannot convert value of type 'Facility' to expected argument type "Facility!"

The Error is in the last converted file code i have mentioned, that is mentioned in comment.

"Cannot convert “Facility” to expected argument type “Facility!"

The code is:

TheFacility.h File:

#import <Foundation/Foundation.h>

@interface FacilityDataModel : NSObject
- (BOOL)save:(Facility *)facility;
@end

TheFacility.m File:

#import "FacilityDataModel.h"

@implementation Facility
… // many other methods...

- (void)save
{
    FacilityDataModel *facilityDataModel = [[FacilityDataModel alloc] init];
    [facilityDataModel save:self];
}

… // many other methods...
@end

TheFacilityDataModel.m File is having method:

-(BOOL) save: (Facility *) facility
{
    if ([facility m_ID] == nil)
    {
        NSLog(@“Saving Facility Code”);
        return true;
    }
    return false;
}

Now the Converted "Facility.swift" file to swift is:

import Foundation

class Facility: NSObject {
    …
    func save() {
        let facilityDataModel = FacilityDataModel() 
        facilityDataModel.save(self) ///Its showing dialog “Cannot convert “Facility” to expected argument type “Facility!”
    }
    …
}

Note: Please reply with a solution that will not force me to change Objective-C code as i want to have both swift and Objective-C code work together in mine project and cant change that Objective-C code.

I am not converting the DataModel classes to swift as for now... so i have to use this existing Objective-C DataModel class in swift... and that is imported in header file as well... rest all settings are also taken care of and are fine... no other issues except this...

1
show save method for FacilityDataModel in SwiftAndrey Chernukha
I am not converting the datamodel classes so i want to use just this Objective-C datamodel class that is posted...Nirmal
what about let facility:Facility! = self and then facilityDataModel.save(facility) does this work for you?Andrey Chernukha
That shows "Cannot convert value of type 'Facility!' to expected argument type 'Facility!'", thats more confusing...Nirmal
Do you have a class "Facility" declaration in objc code as well?Taier

1 Answers

0
votes

Looks like you have an identically named class in objc code.

You would need to rename one of them since the compiler can't resolve two classes with the same names