So I'm trying to make something a Collection. What's slightly odd here is that my Iterator is not a struct, but a class, and in fact, it's derived off a class defined as a subclass of NSObject and implemented completely in Objective-C++. The reason for this is the Iterator needs to hold a C++ std::map<> iterator.
When I call "map" on my collection in swift, it crashes quickly, in I assume a default implementation function needed to run map (specifically, according to Xcode, in protocol witness for Collection.distance(from:to:) in conformance Metadata.Dictionary
. (My collection is named Metadata.Dictionary.)
What's funny is that I can do a
for (key, value) in collection {
...
}
loop just fine, so I thought I had my iterators correct. But as soon as I write
collection.map {
<simple code>
}
I crash even before I get into the body the first time.
I've put print statements in all the relevant functions of my iterator to make sure nothing funny happens, and basically, map gets an iterator to the beginning, an iterator to the end, jumps into the routine in the subject line, and crashes hard.
Anybody got a suggestion on how I got about debugging this?
I assume that there's no rule that says an iterator must be a struct, and making it a class is OK. (I don't like this, but I can't think of any other good way to hold a std::map<> iterator. Suggestions as to how to manage this without making the Iterator a class are greatly appreciated.)