Not really, unfortunately. The standard library is littered with types because
of exactly this (e.g. `MutableRangeReplaceableRandomAccessSlice`).
Conditional conformance can’t come fast enough!
> Hi All,
>
> Does anyone have a good workaround for generics not currently supporting
> conditional
guard a.isSubset(of: b) else { return false }
This should be the most efficient way to do what you’re trying to do.
> Using Swift 3 I have a function that's called extremely frequently and is
> appearing regularly in Profiler runs. The function takes two
> Setinstances and simply attempts to de
rmance issues.
>
>> On Oct 13, 2016, at 5:12 PM, Tim Vermeulen via swift-users
>> mailto:swift-users@swift.org>> wrote:
>>
>> Is it a requirement that collections share indices with its subsequence?
>> Array and ArraySlice do share indices, which is why
Is it a requirement that collections share indices with its subsequence? Array
and ArraySlice do share indices, which is why ArraySlice isn’t zero-based, and
I think this is convenient. But String.CharacterView doesn’t seem to share
indices with its subsequence (which is String.CharacterView as
Any idea why Swift supports implicit casting to AnyHashable, but not to, say,
AnySequence?
> > On Aug 18, 2016, at 9:54 AM, Adel Zhang via
> > swift-userswrote:
> >
> > Any other situation when implicit type casting works?
> I don't know if there's a comprehensive list anywhere. Here are the on
This doesn’t work because `dob` is optional and `stringFromDate` only takes a
non-optional date.
> That’s where I would use the ?? operator:
>
> let dobString = serverDateFormatter.stringFromDate(dob) ?? ""
>
>
> Jeff Kelley
>
> slauncha...@gmail.com(mailto:slauncha...@gmail.com)|@SlaunchaMan
You want `flatMap`:
let dobString = dob.flatMap(serverDateFormatter.stringFromDate)
Or if you want `dobString` to be non-optional:
let dobString = dob.flatMap(serverDateFormatter.stringFromDate) ?? “"
> Currently I do stuff like this:
>
> letdobString:String
> ifletdob = dob {
> dobString =ser
The Collection(Type) protocol requires a subscript that returns a non-optional,
so it’s just not arrays. The idea is that a startIndex and endIndex are
provided, after which you can guarantee that subscripting the collection with
any index in the range startIndex ..< endIndex is valid. This isn’
Hi Enrico,
Thanks for your reply. This means, however, that I can’t easily distribute my
code along with this synthetic child provider in a package or a library,
correct?
> On 29 Jun 2016, at 19:16, Enrico Granata wrote:
>
> Tim,
> the Xcode variables view is controlled by a different mechanis
The same is true for protocols such as `RandomAccessCollection` and
`MutableCollection`.
> On 6 Jul 2016, at 22:07, Tino Heth <2...@gmx.de> wrote:
>
>
>> I thought this was it, but none of the default implementations of
>> RangeReplaceableCollection seem to use this empty initialiser
> I haven
I thought this was it, but none of the default implementations of
RangeReplaceableCollection seem to use this empty initialiser (except for the
two other initialisers and `removeAll(keepingCapacity:)`, the latter of which
can be implemented using `removeSubrange(_:)` instead). This makes me wond
; >>><mailto:owe...@gmail.com>)(mailto:owe...@gmail.com
> > > >>><mailto:owe...@gmail.com>)>wrote:
> > > >>>According to the document of Swift 3, Array has already conformed
> > > >>>protocolRangeReplaceableCollection.
>
You wouldn’t need an empty initialiser to remove all elements from a
collection, right? You could just use `replaceRange` instead.
> Now I understood you concerns. Have you ever thought of if a non-empty
> RangeReplaceableCollection being removed all of its elements, which makes the
> collectio
I’m not allowing generic subscripts. The collection is declared as
`AnyIndexArray` and it
can be subscripted with type `Index`.
Either way, it’s not really important. I’m mostly wondering why
RangeReplaceableCollection needs an empty initialiser.
> Then how you defined the index to conform toS
ion that can be subscripted
with any index (that conforms to Strideable), but behaves like an array
otherwise.
>
> Zhaoxin
>
> On Wed, Jul 6, 2016 at 7:09 PM, Tim Vermeulen via swift-users
> mailto:swift-users@swift.org>> wrote:
> RangeReplaceableCollection has thre
RangeReplaceableCollection has three initialisers: init(), init(_:) and
init(repeating:count:). The latter two are implemented using the empty
initialiser. But why are these initialisers part of this particular protocol?
As far as I can tell, no other methods of this protocol depend on these
in
> On 2 Jul 2016, at 20:40, Jens Alfke wrote:
>
>
>> On Jul 2, 2016, at 9:48 AM, Tim Vermeulen via swift-users
>> mailto:swift-users@swift.org>> wrote:
>>
>> Why is endIndex one greater than the last valid subscript argument, rather
>> than simpl
Why is endIndex one greater than the last valid subscript argument, rather than
simply the last valid subscript argument? I’m sure there are great reasons for
this, but I just can’t think of them myself.
I’m implementing a binary tree and I want to implement BidirectionalCollection.
Each index
o correct your code Tim - but, being a Swift-101 guy,
> I'm confused by endIndex as count. Should it not be count - 1?
>
> Roy
>
> On 28 Jun 2016, at 20:45, Tim Vermeulen via swift-users
> mailto:swift-users@swift.org>> wrote:
>
>> I expected the follow
I expected the following code to compile:
struct Wrapper: BidirectionalCollection {
var elements: [Element]
var startIndex: Int { return 0 }
var endIndex: Int { return elements.count }
func index(after index: Int) -> Int { return index + 1 }
func index(before ind
Thanks for your reply. It didn’t clear up everything, though. The official
documentation says "Weak references do not affect the result of this
function.”, which suggests that weak (and unowned) references intentionally
aren’t counted. The docs only mention the implementation of copy-on-write
b
class EmptyClass {}
var strongReference = EmptyClass()
weak var weakReference = strongReference
print(isUniquelyReferencedNonObjC(&strongReference)) // true
print(isUniquelyReferencedNonObjC(&weakReference)) // false
I expected both print statements to print true.
I realise that this is proba
would
like to see the results in the variables view as well.
> On 27 Jun 2016, at 01:40, Dmitri Gribenko wrote:
>
> On Fri, Jun 24, 2016 at 3:53 PM, Tim Vermeulen via swift-users
> wrote:
>> I’ve implemented a linked list. Now I’d like to be able to view the elements
&g
I’ve implemented a linked list. Now I’d like to be able to view the elements of
a linked list in the debugger just like with an array. In the debugger, an
array is represented like this:
[0] = the first element
[1] = the second element
etc
I wonder if I can do the same for my linked list. I alr
24 matches
Mail list logo