I have a model class written in Swift and a backend service controller written in Objective-C.
Let's say the file names are SomeModel.swift and SomeRequestController.m and it's header.
I don't want to import the ProjectName-Swift.h
inside the header file. So I have used forward declaration inside the header file. I import ProjectName-Swift.h
inside SomeRequestController.m
file.
The Swift file looks like following:
import Foundation
@objc class SomeModel: NSObject {
@objc var prop1: String?
@objc var prop2: String?
@objc var prop3: String?
}
I can reach this model class in objective-c in the other parts of the code. Forward declaration makes enable to create an object inside the code. So Xcode finds the class. However when I compile it fails with the message:
Property 'prop1' not found on object of type '__strong id'
How can I solve this without changing the import mechanism?
I have solved the problem. Here, I would like to introduce this specific case for those who may encounter with such a problem in the future.
The objective-c file is in target membership with two projects. The Swift file was in target membership with one of them. I have assigned this Swift file to the second project. It compiles now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.