Re: [swift-users] Generics question - can you handle both optional and non-optional args with the same function?

2018-01-11 Thread Charles Srstka via swift-users
> On Jan 11, 2018, at 7:55 PM, Kenny Leung via swift-users > wrote: > > I’m trying to write a utility method that is kind of the opposite of “x ?? > y”, which means “x != nil ? x : y”. I want “x != nil ? f(x) : nil” A good name for this method might be ‘map’ ;-) > This is not difficult to wr

Re: [swift-users] Discourse forum rollout next week!

2018-01-10 Thread Charles Srstka via swift-users
:thumbsup: Charles > On Jan 10, 2018, at 2:22 PM, Nicole Jacque via swift-users > wrote: > > Hi All- > > First of all, a big thank you to everyone who has provided feedback on our > prototype Discourse forum. We are ready to move forward with the transition! > The schedule will be: > > 1/

Re: [swift-users] Rethrows issue

2018-01-01 Thread Charles Srstka via swift-users
> On Dec 31, 2017, at 1:35 AM, Nevin Brackett-Rozinsky via swift-users > wrote: > > So, I know this doesn’t actually address your issue, but I think it is > important to clarify that “rethrows” does not guarantee anything about the > *type* of error thrown by a function. What “rethrows” implie

Re: [swift-users] Handle deprecated enum cases from a library

2017-11-06 Thread Charles Srstka via swift-users
> On Nov 6, 2017, at 5:47 AM, Dennis Weissmann > wrote: > > Hey Charles, > > Thanks for going through this with me :) > > I'm not sure whether or not this is a compiler bug (that's partially why I > posted it here), although I have the feeling that *something* is definitely > wrong. > > Fun

Re: [swift-users] Handle deprecated enum cases from a library

2017-11-05 Thread Charles Srstka via swift-users
> On Nov 5, 2017, at 10:39 AM, Dennis Weissmann > wrote: > >> You can delete the default case here, and your switch will still be >> exhaustive > That's exactly my problem! It is *not*. > > When I delete the default clause, the compiler warns that the switch is not > exhaustive and fixits sug

Re: [swift-users] Handle deprecated enum cases from a library

2017-11-05 Thread Charles Srstka via swift-users
> On Nov 5, 2017, at 9:27 AM, Dennis Weissmann > wrote: > > Hi Charles, > > I do believe you :) > > The problem is that this doesn't work without a compiler warning if you > switch over every case except for the deprecated ones because then the > compiler warns that "default will never be ex

Re: [swift-users] Handle deprecated enum cases from a library

2017-11-05 Thread Charles Srstka via swift-users
> On Nov 5, 2017, at 3:14 AM, Dennis Weissmann > wrote: > > Hi Charles, > > You are right (the `default` case would not catch the deprecated values but > only new ones introduced in future releases), but the compiler doesn’t seem > to know that :( > > But now that you say it, one approach co

Re: [swift-users] Handle deprecated enum cases from a library

2017-11-04 Thread Charles Srstka via swift-users
> On Nov 4, 2017, at 9:38 AM, Dennis Weissmann via swift-users > wrote: > > Hi swift-users, > > In a project (iOS 11 only) we use Touch ID for authentication and handle > errors like so: > > private func handleLocalAuthenticationError(_ error: LAError) { > switch error.code { > case .

Re: [swift-users] Swift 4.0 released!

2017-09-19 Thread Charles Srstka via swift-users
> On Sep 19, 2017, at 9:06 PM, Ted Kremenek via swift-users > wrote: > > I am pleased to announce that Swift 4.0 has been officially released: > > https://swift.org/blog/swift-4-0-released/ > > > Swift 4 is available in Xcode 9 (which went live o

Re: [swift-users] How to cast within #keyPath() ?

2017-07-25 Thread Charles Srstka via swift-users
> On Jul 25, 2017, at 11:26 AM, Manfred Schubert wrote: > > >> Am 25.07.2017 um 18:21 schrieb Charles Srstka : >> >> #keyPath(MyView.property) should do it, I’d think. > > I think it wouldn't. It returns "property", but the path needs to be > "view.property”. Ah, you’re right. This should wo

Re: [swift-users] How to cast within #keyPath() ?

2017-07-25 Thread Charles Srstka via swift-users
#keyPath(MyView.property) should do it, I’d think. Charles > On Jul 25, 2017, at 11:16 AM, Manfred Schubert via swift-users > wrote: > > How can I cast a path segment within #keyPath() ? > > For example in the following code: > > —— > > import Cocoa > > class MyView: NSView { >var pro

Re: [swift-users] the pain of strings

2017-06-30 Thread Charles Srstka via swift-users
> On Jun 30, 2017, at 4:44 PM, David Baraff via swift-users > wrote: > > I know, I’ve read tons about about this. I sympathize. Unicode, it’s all > very complex. > > But. > > BUT. > > Python: > shortID = longerDeviceID[-2:]# give me the last two > characters > > Swift:

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Charles Srstka via swift-users
> On Jun 30, 2017, at 1:47 PM, Mike Ferenduros via swift-users > wrote: > > I'm doing a RAII sort of thing with an object, and would like to keep it > alive until an completion-block is called (asynchronously). > > Is it sufficient to say '_ = x' in the completion-block to keep a live > refer

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-26 Thread Charles Srstka via swift-users
> On Jun 26, 2017, at 3:47 PM, Roderick Mann wrote: > >> On Jun 26, 2017, at 10:20 , Charles Srstka wrote: >> >> Rats, I was hoping that one of the reasons about being so explicit what >> we’re going to access and where with bindMemory() and friends would be to >> take care of these sorts of

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-26 Thread Charles Srstka via swift-users
> On Jun 26, 2017, at 3:41 PM, Roderick Mann wrote: > >> >> On Jun 26, 2017, at 10:20 , Charles Srstka > > wrote: >> >> Rats, I was hoping that one of the reasons about being so explicit what >> we’re going to access and where with bindMemory() and friends woul

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-26 Thread Charles Srstka via swift-users
> On Jun 26, 2017, at 12:58 PM, Joe Groff wrote: > >> >> On Jun 26, 2017, at 10:20 AM, Charles Srstka via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Rats, I was hoping that one of the reasons about being so explicit what >>

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-26 Thread Charles Srstka via swift-users
Rats, I was hoping that one of the reasons about being so explicit what we’re going to access and where with bindMemory() and friends would be to take care of these sorts of issues. In that case, the simplest way to do it is probably just this: let crc = (UInt16(myData[myData.endIndex]) << 8) |

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-26 Thread Charles Srstka via swift-users
> On Jun 26, 2017, at 3:55 AM, Daniel Vollmer via swift-users > wrote: > > Hi Rick, > >> On 26. Jun 2017, at 02:37, Rick Mann via swift-users > > wrote: > > [snip] > >> I'd also like to avoid unnecessary copying of the data. All of it is >> immutable for the pur

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-25 Thread Charles Srstka via swift-users
> On Jun 26, 2017, at 12:00 AM, Roderick Mann via swift-users > wrote: > > I mean, it's as straightforward as my example. I have a Data of arbitrary > size (anywhere from 3 to 29 bytes, let's say). The last two bytes form a > UInt16 CRC. I need to get those last two out and compare them agains

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-25 Thread Charles Srstka via swift-users
> On Jun 26, 2017, at 1:11 AM, Charles Srstka via swift-users > wrote: > >> On Jun 26, 2017, at 12:00 AM, Roderick Mann via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> I mean, it's as straightforward as my example. I have a Data

Re: [swift-users] [swift-evolution] Plan to move swift-evolution and swift-users mailing lists to Discourse

2017-06-07 Thread Charles Srstka via swift-users
> On Mar 20, 2017, at 11:39 AM, Jon Shier via swift-evolution > wrote: > > So when is this transition happening? The sooner the better, as Mail > can’t really handle threads with large messages, like the recent evolution > threads about Foundation serialization and decoding. It just stop

Re: [swift-users] Calling default implementation of protocol methods as selectors

2017-06-04 Thread Charles Srstka via swift-users
Here’s what I’d try. (disclaimer: written in Mail, may contain errors, yadda yadda yadda) public class BlockTapGestureRecognizer: UITapGestureRecognizer { private class Target: NSObject { private let closure: (UITapGestureRecognizer) -> () init(closure: @escaping (UIT

Re: [swift-users] Future(of: self.references)?

2017-05-22 Thread Charles Srstka via swift-users
While this makes sense in principle, it is far too easy to accidentally access the wrong member because something was shadowed. The very fact that the core team had to add a special-case warning for NSView.print() to the compiler itself demonstrates how problematic this can be. Oh well. When th

Re: [swift-users] override-like keyword for default implementations

2017-05-16 Thread Charles Srstka via swift-users
> On May 16, 2017, at 4:41 PM, Jordan Rose wrote: > > I object to this characterization. People have tried to bring up such > proposals, and it is invariably pointed out (usually by the same group of us) > that these proposals don't discuss retroactive modeling, and then the thread > dies. I c

Re: [swift-users] override-like keyword for default implementations

2017-05-16 Thread Charles Srstka via swift-users
> On May 16, 2017, at 12:32 PM, Nevin Brackett-Rozinsky via swift-users > wrote: > > There is not. > > At some point in the future, I believe the plan is to eventually allow > default implementations to be written in-line within the protocol declaration > itself. In other words, the fact that

Re: [swift-users] Crasher in Swift<->Objective-C Interop!

2017-05-01 Thread Charles Srstka via swift-users
> On Apr 30, 2017, at 4:43 PM, Brent Royal-Gordon > wrote: > >> On Apr 30, 2017, at 11:57 AM, Charles Srstka via swift-users >> wrote: >> >> What does the community think? Should I file this as a bug on Swift? >> Foundation? AppKit? All three? > &

[swift-users] Crasher in Swift<->Objective-C Interop!

2017-04-30 Thread Charles Srstka via swift-users
Hello all, I’ve discovered a bug that’s causing crashes when Swift code interoperates with AppKit in a certain way. I intend to file a bug report, but I’m not sure whether the bug should be filed as a Swift bug, or as an AppKit bug since a case could probably be made for either, and I thought I

[swift-users] Protocol doesn't conform to itself: Any workaround?

2016-05-30 Thread Charles Srstka via swift-users
So, the pitfall below seems to be fairly well-known, as I was able to find previous references to it on the list: -- protocol P { func foo() } struct S: P { func foo() { print("foo") } } func doSomething(c: C) { for each in c { each.foo() } } let arr: [P] = [S()