[swift-users] Workaround for generics not currently supporting conditional conformance to a protocol

2016-11-15 Thread Tim Vermeulen via swift-users
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

[swift-users] Optimising Set comparisons

2016-11-13 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Subsequences and shared indices

2016-10-13 Thread Tim Vermeulen via swift-users
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

[swift-users] Subsequences and shared indices

2016-10-13 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Implicitly type conversion ?

2016-08-19 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Tim Vermeulen via swift-users
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

[swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Tim Vermeulen via swift-users
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

[swift-users] Why does Array subscript fail at runtime?

2016-07-26 Thread Tim Vermeulen via swift-users
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’

Re: [swift-users] Customizing my custom type's appearance in the debugger

2016-07-11 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Why does RangeReplaceableCollection require an empty initialiser?

2016-07-06 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Why does RangeReplaceableCollection require an empty initialiser?

2016-07-06 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Why does RangeReplaceableCollection require an empty initialiser?

2016-07-06 Thread Tim Vermeulen via swift-users
; >>><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. >

Re: [swift-users] Why does RangeReplaceableCollection require an empty initialiser?

2016-07-06 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Why does RangeReplaceableCollection require an empty initialiser?

2016-07-06 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Why does RangeReplaceableCollection require an empty initialiser?

2016-07-06 Thread Tim Vermeulen via swift-users
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

[swift-users] Why does RangeReplaceableCollection require an empty initialiser?

2016-07-06 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Collection's "past the end" endIndex

2016-07-02 Thread Tim Vermeulen via swift-users
> 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

[swift-users] Collection's "past the end" endIndex

2016-07-02 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Default bounds subscript for BidirectionalCollection

2016-06-28 Thread Tim Vermeulen via swift-users
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

[swift-users] Default bounds subscript for BidirectionalCollection

2016-06-28 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Checking whether an object is uniquely referenced, using a weak reference to it

2016-06-27 Thread Tim Vermeulen via swift-users
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

[swift-users] Checking whether an object is uniquely referenced, using a weak reference to it

2016-06-27 Thread Tim Vermeulen via swift-users
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

Re: [swift-users] Customizing my custom type's appearance in the debugger

2016-06-26 Thread Tim Vermeulen via swift-users
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

[swift-users] Customizing my custom type's appearance in the debugger

2016-06-26 Thread Tim Vermeulen via swift-users
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