Re: [swift-users] Can't make an escaping closure argument optional?

2018-01-05 Thread Kevin Nattinger via swift-users
If you remove the @escaping you'll notice it doesn't complain about a non-escaping closure escaping. I could be wrong, but I believe that's because using it as an associated value forces it to escape on the calling side. func esc(_ x: @escaping () -> ()) { x() } func noesc(_ x: () -> ()) {

Re: [swift-users] protocol definition question

2017-12-13 Thread Kevin Nattinger via swift-users
If you want to match [UInt8] specifically, just use the non-sugared definition: extension RawBits where RawValue == Array { } If you want it to match any array, that’s more complicated. As far as I’ve been able to work out, you have to wrap it in a protocol. Most of Array’s usefulness comes fr

Re: [swift-users] dealing with heterogenous lists/dictionary with Codable

2017-10-19 Thread Kevin Nattinger via swift-users
So, what I see as the problem here is contradictory compiler statements: MyPlayground.playground:5:9: note: cannot automatically synthesize 'Encodable' because '[String : Any]' does not conform to 'Encodable' let someDict: [String : Any] ^ warning: MyPlayground.playground:8:18: warni

Re: [swift-users] question on generics

2017-02-22 Thread Kevin Nattinger via swift-users
This seems to work in a playground: import CoreData protocol SomeProtocol {} class Foo where T: SomeProtocol {} > On Feb 22, 2017, at 4:08 PM, Dave Reed via swift-users > wrote: > > I suspect this can't be done (at least not right now), but wanted to check. > > I'd like to declare a class as

Re: [swift-users] default struct initializer internal even if class declared public

2017-01-18 Thread Kevin Nattinger via swift-users
I ran into this issue not half an hour ago; I would also prefer the default initializer to default to the entity’s access level, or at least have some simple way of opting in. > On Jan 18, 2017, at 3:33 PM, Dave Reed via swift-users > wrote: > > I’m teaching an iOS with Swift this semester an

Re: [swift-users] Weird protocol behaviour.

2016-12-22 Thread Kevin Nattinger via swift-users
I recall seeing a request on the -evolution list for something like `T := X` to indicate it could be X itself or anything inheriting / implementing it, so it’s certainly known behavior, if not desired. IMO it’s a bug and `:` should be fixed to include the root type, whether or not that requires

Re: [swift-users] Argument type 'Int' does not conform to expected type 'AnyObject'

2016-09-09 Thread Kevin Nattinger via swift-users
You’ll need to explicitly add the “as NSNumber” now. https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md > On Sep 9, 2016,

Re: [swift-users] generic function called recursively not compiling

2016-08-04 Thread Kevin Nattinger via swift-users
Looks like a bug in the type inference system to me, but I’ll let someone with a better knowledge of the compiler confirm. Meanwhile, you can work around by explicitly casting any of the pieces of the return statement to `[Element]` or using a temporary for one or more of them. let middle =

Re: [swift-users] How do I find really detailed information about changes?

2016-06-22 Thread Kevin Nattinger via swift-users
I could be wrong (haven’t tested, but my impression is that only components you explicitly request in the option set passed to calendar.components will be non-nil. > On Jun 22, 2016, at 9:49 AM, Eric Miller via swift-users > wrote: > > I'm working on migrating from Swift 2.3 to Swift 3.0. >

Re: [swift-users] Printing large hexadecimal values

2016-05-25 Thread Kevin Nattinger via swift-users
%16x pads with spaces instead of zeros, use %016X for uppercase zero-padded output. `man 3 printf` will show the full spec (minus the objc-specific %@), or Apple probably documents it somewhere. It breaks down like this: - x/X is a format saying it’s an int type and should be printed in hex wit

Re: [swift-users] Printing large hexadecimal values

2016-05-25 Thread Kevin Nattinger via swift-users
“%08x” to zero-pad to 8 characters, “%08X" for uppercase A–F % cat main.swift import Foundation let n = 10597059 print(String(format: "%x", n)) print(String(format: "%08x", n)) print(String(format: "%08X", n)) % swift main.swift a1b2c3 00a1b2c3 00A1B2C3 % > On May 25, 2016, at 10:54 AM, Jens Alfk