Xcode 7.3 uneclared type for Obj C enum in Swift code

In my project, I have Swift extensions on Objective C enums that worked brilliantly in Xcode 7.2.

But with Xcode 7.3, it does not work with the โ€œundeclared typeโ€ in the Swift file, where I extend the enumeration of Obj C.

I built a sample project and it compiles and works well, but I cannot force an existing project to accept the extension over the Obj C listing.

UPDATE:

After reinstalling Xcode 7.2, I can confirm that the project compiles and builds successfully.

After he worked in Xcode 7.2, I again tried to run this project in Xcode 7.3 and again the same problem -> Swift extension on top of Obj C enums cannot be created.

After clearing and deleting the resulting data in Xcode 7.3, I also get the -Swift.h header error because the Swift classes have not been compiled, so the header has not yet been created.

Code designation:

My Obj C enum inside "FriendRequestResult.h":

typedef NS_ENUM(NSInteger, FriendStatus) { FriendStatusRequestedByUser = 1, FriendStatusRequestedByOtherUser, FriendStatusFriends, FriendStatusBlocked, FriendStatusNone, FriendStatusError, }; 

Now, as expected in my AppName-Bridging-Header.h, I:

 #import "FriendRequestResult.h" 

Then I have a quick extension over FriendStatus, which builds in Xcode 7.2, but with the error "use an undeclared type" in Xcode 7.3:

 extension FriendStatus { init(stringValue : String?) { if let stringValue = stringValue { switch stringValue { case "REQUESTED_BY_USER": self = .RequestedByUser case "REQUESTED_BY_OTHER": self = .RequestedByOtherUser case "FRIENDS": self = .Friends case "BLOCKED": self = .Blocked default: self = .None } } else { self = .None } } } 

Actually this extension over enumeration also has some other helper functions, but this should not in any way change the problem.

Of course, if the enumeration extension gives an undeclared type, then the use of this type does not occur everywhere in Swift code with the same "undeclared things". In principle, the enumeration is not visible at all for the Swift part of the project, even if the import is done in the header of the bridge.

This question has been substantially modified from its first version.

+5
source share
2 answers

Solution 1: The listing in the seaparate header file has been moved.

The enum declaration was in the same heading as the class heading, and that was exactly what was between the @interface and @end of this class.

In Xcode 7.2, it did not cause problems, and the header analysis was successful, while in Xcode 7.3 they probably optimized something and changed the way it was analyzed, so he saw my class, but did not list it inside [maybe it declares it private if it is inside the class declaration]

Solution 2: The enum declaration has been moved outside the @interface @end area.

+8
source

To answer your question: โ€œCan I somehow get Xcode to generate the Swift header first? Or can I get Xcode to believe that my enums exist somewhere and that it should check my extensions?โ€

I found 2 ways to order file compilation.

  • Use of the goal and its dependence on your project.
  • Opening the project.pbxproj file and editing the list manually.

Depending on the level of risk and complexity that you are ready to solve, choose one or the other.

I was just trying to extend ENUM, and everything works fine here. One of the problems I had in the past was understanding the naming convention between Obj-C and Swift, but this does not seem to be the problem you are facing. Another problem that I constantly run into is constantly supporting the @ # $% Bridging-Header.h file. Are you sure this is relevant?

+1
source

Source: https://habr.com/ru/post/1245708/


All Articles