Expected selector for Objective-C method on Enum

254 views
Skip to first unread message

er...@pltech.co.nz

unread,
Oct 26, 2015, 8:17:43 PM10/26/15
to j2objc-discuss
Swift project in Xcode 7 importing a framework translated using j2objc as well as JRE.framework
One of the public headers in the framework declare enums, such as
+ (WeekDayEnum *)DAY_1;
...
+ (WeekDayEnum *)DAY_7;

translated from the Java:
public enum WeekDay {
DAY_1,
...
DAY_7;
}

When I try building the project, these get marked with the error "Expected selector for Objective-C method".

I tried renaming these enums to:
DAY_1,
DAY2,
DAYS_3,
ADAY_4,
DAY_FIVE,
ABDAY_6,
DAY_0;

and retranslating it. With these new names, only DAY_1 and ABDAY_6 report the error. Could it be related to these http://www.gnu.org/software/libc/manual/html_mono/libc.html#The-Elegant-and-Fast-Way ?
If possible, I'd like to resolve this problem without needing to rename the enums. These also worked fine before I switched to using JRE.framework

Tom Ball

unread,
Oct 28, 2015, 6:25:56 PM10/28/15
to j2objc-discuss
The problem is with Swift importing all constants in /usr/include (actually, not all constants, but all defined in the many headers included in /usr/include/module.map):

$ ack DAY_ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/langinfo.h
44:#define DAY_1 7
45:#define DAY_2 8
46:#define DAY_3 9
47:#define DAY_4 10
48:#define DAY_5 11
49:#define DAY_6 12
50:#define DAY_7 13

I had no idea these constants existed, but it wasn't a problem before because Objective C files only #import or #include the headers they need, not all of them. Renaming them as you've done is the best fix, as all j2objc could do is rename them in a way you may not like (normally it appends a '_').

--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

er...@pltech.co.nz

unread,
Oct 28, 2015, 6:51:02 PM10/28/15
to j2objc-discuss
Thanks! Good to know the reason for sure, instead of just speculating

er...@pltech.co.nz

unread,
Oct 28, 2015, 8:08:54 PM10/28/15
to j2objc-discuss
So what this means is that enums cannot share a name with C constants...does that mean they need to be prefixed, like classes? Would the same problem occur if an integrator used another 3rd party library that also defined these constants? What about static fields (translated from Java)?

Tom Ball

unread,
Oct 28, 2015, 8:39:13 PM10/28/15
to j2objc-discuss
Nothing can share a name with a #define, since the definition changes it; it's been that way since the first C preprocessor, and a big reason neither Java nor Swift has one. We can't do much about the Apple's decision to include so many /usr/include headers; it appears that their goal is to eliminate all third-party frameworks and libraries from the iOS and OS X platforms.

On Wed, Oct 28, 2015 at 5:08 PM <er...@pltech.co.nz> wrote:
So what this means is that enums cannot share a name with C constants...does that mean they need to be prefixed, like classes? Would the same problem occur if an integrator used another 3rd party library that also defined these constants? What about static fields (translated from Java)?

er...@pltech.co.nz

unread,
Oct 28, 2015, 9:04:11 PM10/28/15
to j2objc-discuss
I see, thanks. It does look like the only options are renaming them, or using #undef

er...@pltech.co.nz

unread,
Oct 28, 2015, 10:00:32 PM10/28/15
to j2objc-discuss
Since the problem only seems to be with the static accessor method, renaming the accessor method actually works too - but I don't think there's enough use cases to justify adding this functionality
Reply all
Reply to author
Forward
0 new messages