/// The maximum number of elements per segment.
let maxElementsPerSegment = 128
/// An array that should have its elements in segments, to gain the memory advantages of linked lists.
struct SegmentedArray<T> {
/// The count of elements typically in a segment.
static var maxElementsPerSegment: Int { return ???.maxElementsPerSegment }
}
How can I use the global maxElementsPerSegment as part of the definition of the type's version? Or is there no way to undo hiding? (I just renamed the global one for my workaround.)
I guess we need something like C++'s "::" prefix operator.
Now I have to figure out the name of the module from within the module. You have to look what’s set up in the Xcode preferences and copy the string, right?
I think we need to allow “Self” (or maybe a new semi-reserved identifier) within a type to refer to itself, so we don’t have to do wide-range find & replace whenever we rename the type. And a similar identifier for the current module. And finally: identifiers have to be unique within scopes within any function that isn’t nested in a code block. (So your “bar.i” would be banned.)
If maxElementsPerSegment is a global constant or simply at file level you can use the module name to reference it when you need a way to disambiguate:
// at file level
let something = ...
struct MyType {
var something: SameType { return MODULE_NAME.something }
}
In Xcode the module is by default called the same as the target you're working on. I usually rename the app module to App which makes it really when you read App.constant.