Sajjon
(Alexander Cyon)
1
Using Xcode 15 beta 3 on an M1 running Ventura 13.5 I'm trying C++ interop, but fail to iterate through a std::vector, I get compilation error:
For-in loop requires
'
std.__1.vector<
basic_string<
Int8,
char_traits<Int8>,
allocator<Int8>
>,
allocator<
basic_string<
Int8,
char_traits<Int8>,
allocator<Int8>
>
>
>
'
to conform to 'Sequence'
The C++ property in question is std::vector<std::string> dwellingNames;
I thought this document section "Using" stated that we could do for in
in Swift on std::vector
...? What am I missing?
Perhaps the culprit is that it is a vector of std::string
, is iterating over that not supported?
SWIFT_OBJC_INTEROP_MODE
has been set to objcxx
...
Alex_L
(Alex Lorenz)
2
Such type should automatically conform to CxxRandomAccessCollection
, so that is definitely a bug. Could you file an issue on GitHub - apple/swift: The Swift Programming Language and attach a reproducer (Xcode project is fine).
CC @egor.zhdan
2 Likes
Sajjon
(Alexander Cyon)
3
Thank you for your prompt reply, I was able to create a minimum project demonstrating the issue, here it is: GitHub - Sajjon/CxxRandomAccessCollectionNotWorking: Demo of `CxxRandomAccessCollection` not properly generated
As you can see in code and README, std::vector<int>
is callable from Swift, but std::vector<std::string>
is not.
1 Like
Alex_L
(Alex Lorenz)
4
1 Like