Re: [swift-users] Rethrows issue

2018-01-01 Thread Howard Lovatt via swift-users
I don’t get why that type checks: 1. rescue always throws inside sync, therefore 2. _syncHelper inside sync always throws, therefore 3. sync always throws, therefore 4. Shouldn’t sync be declared throws not rethrows? -- Howard. On 1 Jan 2018, at 1:10 pm, Charles Srstka via swift-users

Re: [swift-users] A confusing protocol extension behaviour/bug

2018-01-01 Thread Howard Lovatt via swift-users
ard Lovatt via swift-users > wrote: > > Unfortunately the error messages you get with protocols are limited :). The > compiler is doing the right thing, no bug. The problem is that it is really > easy to mak > > -- Howard. > >> On 1 Jan 2018, at 3:40 pm, Toni

Re: [swift-users] A confusing protocol extension behaviour/bug

2018-01-01 Thread Howard Lovatt via swift-users
Unfortunately the error messages you get with protocols are limited :). The compiler is doing the right thing, no bug. The problem is that it is really easy to mak -- Howard. > On 1 Jan 2018, at 3:40 pm, Toni Suter via swift-users > wrote: > > Hi Marc, > > There are several subtleties here

Re: [swift-users] Comprehensive documentation for Collection?

2017-12-15 Thread Howard Lovatt via swift-users
It’s a problem with Apple documentation. swiftdoc.org does list the associated types, but is no longer maintained :(. -- Howard. > On 16 Dec 2017, at 1:17 pm, Nevin Brackett-Rozinsky via swift-users > wrote: > > In Xcode if I write, > > extension Collection { > var secondIndex: Index {

Re: [swift-users] FileManager.copyItem not throwing?

2017-11-11 Thread Howard Lovatt via swift-users
I don’t have any inside knowledge on this, i.e. I am not certain I am correct, but my understanding was that you were meant to let it throw and catch the error rather than test before hand. -- Howard. > On 11 Nov 2017, at 12:51 pm, Marco S Hyman via swift-users > wrote: > > >> Running on m

Re: [swift-users] overloading methods where only difference is optional vs. non-optional type

2017-10-10 Thread Howard Lovatt via swift-users
func funny() -> Int { return 1 } func funny() -> String { return "2" } let i: Int = funny() let s: String = funny() Is fine. Since Swift knows the return type required. However, it can’t infer the type of: let q = funny() -- Howard. > On 11 Oct 2017, at 4:36 am, C. Keith Ray via swift-us

Re: [swift-users] Initialization Catch-22?

2017-09-26 Thread Howard Lovatt via swift-users
I know were you are coming from, but: 1. In other languages it would be the equivalent of an force unwrapped optional and you could get a NullPointerException (or worse - core dump). Using a force unwrapped optional just levels the playing field! 2. You could make it private(set) which would

[swift-users] Threads and weak references

2017-09-22 Thread Howard Lovatt via swift-users
Hi, I was using a weak reference in a concurrent application and and the main thread wasn't seeing an update to a class's property made by another thread. If I replaced the weak reference with a closure, the problem went away. Is there any documentation that describes this behaviour? Thanks in a

Re: [swift-users] Custom operators from a module

2017-09-06 Thread Howard Lovatt via swift-users
ur suggestion of logging a bug, reducing the problem to bug form really helped. -- Howard. On 7 September 2017 at 07:36, Howard Lovatt via swift-users < swift-users@swift.org> wrote: > I have a custom operator defined in a module and in my XCTest I import > that module. In the tests t

Re: [swift-users] Custom operators from a module

2017-09-06 Thread Howard Lovatt via swift-users
gt; Jordan > > >> On Sep 6, 2017, at 02:08, Howard Lovatt via swift-users >> wrote: >> >> Hi All, >> >> I am trying to use a custom operator imported from a module, unfortunately >> you can't add public to the operators definition and therefore

[swift-users] Custom operators from a module

2017-09-06 Thread Howard Lovatt via swift-users
Hi All, I am trying to use a custom operator imported from a module, unfortunately you can't add public to the operators definition and therefore it isn't exported from the module. I can manually redefine the operator in the module where the operator is used, but that isn't very satisfactory - is

Re: [swift-users] Is this a compiler bug?

2017-09-04 Thread Howard Lovatt via swift-users
Thanks for prompt reply - link is: https://bugs.swift.org/browse/SR-5838 -- Howard. On 5 September 2017 at 11:58, Slava Pestov wrote: > Yeah, looks like a bug. Do you mind filing a JIRA? > > Slava > > On Sep 4, 2017, at 8:55 PM, Howard Lovatt via swift-users < >

[swift-users] Is this a compiler bug?

2017-09-04 Thread Howard Lovatt via swift-users
Hi All, Is this a compiler bug? struct Box { var value: T init(_ value: T) { self.value = value } /// Unboxing operator. static func >> (left: Box, right: inout T?) { right = left.value } } var u: String? let b = Box("Test") b >> &u // ERROR: Cannot convert value of t

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-19 Thread Howard Lovatt via swift-users
You are hardly alone struggling with this, it seems to come up every other week! You can write your own custom AnyProtocol type that includes Self, a pain but doable, e.g.: protocol A { func a() -> String } protocol B { func b() -> String } struct AB1: A, B, Hashable { func a() -> Str

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Howard Lovatt via swift-users
I would be tempted to use classes for this if you can use single inheritance. If you need multiple inheritance then use an enum and hand code the dispatch, a lot more work :(. E.G.: protocol A { func a() -> String } protocol B { func b() -> String } struct AB1: A, B, Hashable { func a(

Re: [swift-users] Is it possible to specify error type thrown in a protocol method

2017-07-06 Thread Howard Lovatt via swift-users
On balance I think I prefer result types. Java's fully typed throws and Swift's semi-typed throws are fine though. I can't see Swift supporting result types because they already have throws. -- Howard. > On 6 Jul 2017, at 4:27 pm, Tim Wang wrote: > > Thanks Howard, it's a good workaround.

Re: [swift-users] Is it possible to specify error type thrown in a protocol method

2017-07-05 Thread Howard Lovatt via swift-users
You could use a result type, e.g.: https://github.com/antitypical/Result Or roll your own result type. I think the reason that Swift doesn't support what you want is because of rethrows. When you declare a method as rethrows it can throw anything because the closure it is re-throwing can throw a

[swift-users] UIDocumentBrowserViewController Bug in Xcode 9 Beta 2?

2017-06-30 Thread Howard Lovatt via swift-users
Hi, I am having problems with UIDocumentBrowserViewController Bug in Xcode 9 Beta 2, was working with beta 1. The symptom is that you can't create a new document, on most pages the + icon is missing or greyed out. On the browse page it is present and not greyed out, but doesn't work. EG If you s

[swift-users] Robust Codable coding

2017-06-23 Thread Howard Lovatt via swift-users
Hi All, I have started to use Codable and was looking for some advice. I want to make the persisted data structure robust so that if I change the properties as the code develops the new code can deserialise an old saved file. This is what I am currently doing: struct Project: Codable { va

Re: [swift-users] any wisdom about sharing "common" overloads/extensions in base libraries?

2017-06-20 Thread Howard Lovatt via swift-users
Jordon Rose from Apple said: "It's tracked by SR-3908 . (The description's a little different but it's the same underlying issue.)" -- Howard. On 21 June 2017 at 12:07, David Baraff wrote: > > On Jun 20, 2017, at 6:59 PM, Howard Lovatt > wrote: > > T

Re: [swift-users] any wisdom about sharing "common" overloads/extensions in base libraries?

2017-06-20 Thread Howard Lovatt via swift-users
There is a *bug* that the Swift people know about, but you are **meant** to be able to do this: ModuleA A.swift public protocol P { func m() -> String } extension Int: P { public func m() -> String { return "AP.m" } } ModuleB B.swift public protocol P { func m() -> String } extension I

Re: [swift-users] Restricting associated values

2017-06-18 Thread Howard Lovatt via swift-users
To me Angle is a unit with two common representations: radians and degrees. It's not an enum because it doesn't have two values, it has one value that you can view in two ways. Therefore I would make an Angle struct, something like: //: Angle struct instead of angle enum import Foundation str

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

2017-05-16 Thread Howard Lovatt via swift-users
In the proposal I just posted in reply to Jordan Rose all these examples would work as expected, though the syntax and/or semantics would be slightly different: Example 1 In R.swift protocol R { func f() } // f is abstract In P.swift protocol P {} // f cannot be in protocol and extension exte

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

2017-05-16 Thread Howard Lovatt via swift-users
Here is a proposal I put forwards last month that addresses the issue (and others), the original versions did not allow retroactive modeling but following feedback it was incorporated. PS Bitten by this problem two days ago, copied some example Swift 2 code into a Swift 3 project and an obj-c meth

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-09 Thread Howard Lovatt via swift-users
and hence doesn't require wrapping. The append method is a little slower though. -- Howard. On 10 May 2017 at 04:32, Michael Gottesman wrote: > Could you file a bug report? bugs.swift.org? > > Michael > > On May 9, 2017, at 12:59 AM, Howard Lovatt via swift-users < >

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-09 Thread Howard Lovatt via swift-users
My mistake. If I create a new array I get the problem. EG: import Foundation func elapsed(s: DispatchTime, e: DispatchTime) -> Double { return Double(e.uptimeNanoseconds - s.uptimeNanoseconds) / 1_000_000_000 } let s = 250_000_000 var a = [UInt8]() a.reserveCapacity(s) let sa = DispatchTime

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-09 Thread Howard Lovatt via swift-users
I find trimming relative to appending OK on my 6 year old MacBook Pro. EG: import Foundation func elapsed(s: DispatchTime, e: DispatchTime) -> Double { return Double(e.uptimeNanoseconds - s.uptimeNanoseconds) / 1_000_000_000 } let s = 250_000_000 var a = [UInt8]() a.reserveCapacity(s) let s

Re: [swift-users] How to use a protocol to infer a generic type with constraints

2017-05-02 Thread Howard Lovatt via swift-users
Another +1 from me, a real pain -- Howard. > On 3 May 2017, at 4:05 am, David Sweeris via swift-users > wrote: > > >> On May 2, 2017, at 10:16 AM, Edward Connell via swift-users >> wrote: >> >> Does anyone have an idea when this is going to be fixed? Or when support >> will be implemented

[swift-users] Are all extensions from all modules exported on mass?

2017-04-19 Thread Howard Lovatt via swift-users
Hi, If I have the *same* extension in two *different* modules, ModuleA and ModuleB, and ModuleC uses both modules, but in *seperate* files, then there is still ambiguity about which extension to call: ModuleA A.swift public protocol P { func m() -> String } extension Int: P { public func m(

Re: [swift-users] The case of broken polymorphism or "Cannot convert value of type to expected argument type"?

2017-02-20 Thread Howard Lovatt via swift-users
It is confusing in Swift what can be covariant and what is invariant, consider: // Covarant arrays work class A {} class B: A {} let a = A() // A let b = B() // B var arrayA = [a] // Array arrayA[0] = b // OK // And arrays of arrays var arrayArrayA = [arrayA] /

Re: [swift-users] Associativity of && and || operator

2017-02-20 Thread Howard Lovatt via swift-users
To me it would be surprising if && grouped differently than * or &; since it is closely associated with boolean-and, which in turn is the equivalent operation to multiply in Boolean logic. On Fri, 17 Feb 2017 at 7:56 pm, rintaro ishizaki via swift-users < swift-users@swift.org> wrote: > Hello all

Re: [swift-users] [swift-evolution] for-else syntax

2017-02-05 Thread Howard Lovatt via swift-users
LoopControls.returnValue(42.0) } // for _ in a { return 42.0 } } catch LoopControls.returnValue(let value) { return value } On Sun, 5 Feb 2017 at 2:32 pm, Rob Mayoff via swift-users < swift-users@swift.org> wrote: > On Fri, Feb 3, 2017 at 7:15 PM, Howard Lovatt via swift-users < &

Re: [swift-users] [swift-evolution] for-else syntax

2017-02-03 Thread Howard Lovatt via swift-users
Why not add to the library: extension Sequence { func forEach(_ eacher: (Iterator.Element) throws -> Void, elser: () throws -> Void) rethrows { var hasIterated = false for element in self { hasIterated = true try eacher(element) } guard h

Re: [swift-users] Static type when expecting dynamic type

2017-02-02 Thread Howard Lovatt via swift-users
a fix shortly. > > Slava > > On Feb 2, 2017, at 9:04 AM, Jordan Rose via swift-users < > swift-users@swift.org> wrote: > > Seems like a bug, and moreover it seems like a regression from Swift 3.0. > Mind filing a report at bugs.swift.org? > > Thanks! > Jordan >

[swift-users] Static type when expecting dynamic type

2017-02-01 Thread Howard Lovatt via swift-users
Hi All, Anyone know what is going on here: //: Closure picks up static type not dynamic class MutableReference { init() { guard type(of: self) != MutableReference.self else { fatalError("MutableReference is an abstract class; create a derrivative of Mu

Re: [swift-users] [swift-evolution] Best way to handle escaping function that might throw

2017-01-14 Thread Howard Lovatt via swift-users
nt. > > Does that mean that Never should be a subtype of Error (maybe it is > already) ? Else you couldn't say throws(Never) or FSTore > > @Howard > I'm not sure about <>, it should stay reserved for generics, IMHO. > > Pierre > > Le 13 janv. 2017 à 01

Re: [swift-users] [swift-evolution] Best way to handle escaping function that might throw

2017-01-12 Thread Howard Lovatt via swift-users
@Slava, I'm imagining that the compiler does much the same as Anton suggested, e.g. Anton's: struct FStore { let f: () throws -> Void init(_ f: @escaping () throws -> Void) { self.f = f } func call() throws { try f() } } Is much the same as my: struct FStore

Re: [swift-users] [swift-evolution] Best way to handle escaping function that might throw

2017-01-12 Thread Howard Lovatt via swift-users
@Anton, Yes that would work and we would get typed throws, which I like. As an aside, I think E would have to be constrained to be an Error, ``, and maybe `throws` reads better because you are used to types in angle brackets. -- Howard. On 13 January 2017 at 08:32, Anton Zhilin wrote: > The b

Re: [swift-users] [swift-evolution] Best way to handle escaping function that might throw

2017-01-11 Thread Howard Lovatt via swift-users
Yes, I have used Result in the past. In this case I wanted to use throws because that is what functions like map do. Looks like I will have to stick with throwing, not too bad since the overhead is reasonably low. On Wed, 11 Jan 2017 at 8:03 am, T.J. Usiyan wrote: > I suggest using an enum to

Re: [swift-users] [swift-evolution] Best way to handle escaping function that might throw

2017-01-11 Thread Howard Lovatt via swift-users
Another possibility, other than generics, would be to drop rethrows all together and have the compiler infer if a throw is possible or not, including: struct FStore { let f: () throws -> Void func call() throws { try f() } } The compiler can make two versions, one if f can

Re: [swift-users] Weird protocol behaviour.

2016-12-22 Thread Howard Lovatt via swift-users
te 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 > a discussion on -evolution. > > On Dec 22, 2016, at 2:17 PM, How

Re: [swift-users] Weird protocol behaviour.

2016-12-22 Thread Howard Lovatt via swift-users
I suspect a compiler bug since A is a P. The equivalent in Java works: interface P {} class X implements P {} void foo(A x) {} void bar() { final P x = new X(); foo(x); } -- Howard. > On 23 Dec 2016, at 3:19 am, Rien via swift-users > wrote: > > IMO the error message says it all

Re: [swift-users] Dimensional analysis

2016-11-30 Thread Howard Lovatt via swift-users
Another feature I would like would be a dimensions wrapper for an array. So that I can mark all values in the array as having the same units, rather than mark each individual element as having a particular unit. It is conceivable that wrapping each element, both performance and memory wise, is OK

Re: [swift-users] Changing precedence of / operator for my protocol?

2016-11-29 Thread Howard Lovatt via swift-users
Why not define some other symbol so that you can get the precedence you want? -- Howard. On 30 November 2016 at 09:28, Greg Parker via swift-users < swift-users@swift.org> wrote: > > > On Nov 29, 2016, at 2:55 AM, Rick Mann via swift-users < > swift-users@swift.org> wrote: > > > > Working on d

Re: [swift-users] Dimensional analysis

2016-11-29 Thread Howard Lovatt via swift-users
Great idea to have dimensions library. I use Quantity in Mathematica all the time and it is great. Even if some of the checks are at runtime it is still useful, better to throw an assert rather than nothing. All the rest of your list, in addition to compile time check, I also use. -- Howard. >

Re: [swift-users] hello, first time poster and accelerate question

2016-11-21 Thread Howard Lovatt via swift-users
Take a look at the Surge library. On Tue., 22 Nov. 2016 at 4:24 am, Kenny Leung via swift-users < swift-users@swift.org> wrote: > If only you could write this directly in Swift and have it use accelerate… > > -Kenny > > > > On Nov 18, 2016, at 8:07 PM, Jacob Bandes-Storch via swift-users < > swif

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

2016-11-17 Thread Howard Lovatt via swift-users
able) { > return false > } > } > return true > } > } > > Because I can't cast to an Equatable, because Equatable uses Self. > > Am I missing something? > > -- Howard. > > -- How

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

2016-11-16 Thread Howard Lovatt via swift-users
table) { > return false > } > } > return true > } > } > > Because I can't cast to an Equatable, because Equatable uses Self. > > Am I missing something? > > -- Howard. > > -- Howard. >

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

2016-11-15 Thread Howard Lovatt via swift-users
ward. -- Howard. On 16 November 2016 at 16:35, David Sweeris wrote: > > > On Nov 15, 2016, at 21:39, Howard Lovatt via swift-users < > swift-users@swift.org> wrote: > > > > Hi All, > > > > Does anyone have a good workaround for generics not currently

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

2016-11-15 Thread Howard Lovatt via swift-users
Hi All, Does anyone have a good workaround for generics not currently supporting conditional conformance to a protocol. As stated in the Generics Manifesto something like this would be nice: extension Array: Equatable where Element: Equatable { static func ==(lhs: Array, rhs: Array) ->

Re: [swift-users] Weak references in generic types

2016-09-01 Thread Howard Lovatt via swift-users
@Karl, You say "In the second example, you’re creating WeakReference. P does not conform to P or to AnyObject.", but P does conform to AnyObject. I suspect it is a compiler limitation/ bug. -- Howard. On Thursday, 1 September 2016, Karl wrote: > > On 1 Sep 2016, at 03:23, H

[swift-users] Subtract a set of a subclass?

2016-08-31 Thread Howard Lovatt via swift-users
I am probably misunderstanding you, but it seems to work for me: class A: Hashable, CustomStringConvertible { var hashValue: Int { return ObjectIdentifier(self).hashValue } var description: String { return "A@\(hashValue)" } } func ==(lhs: A, rhs: A) -> Bool { return lhs.hashValue == r

Re: [swift-users] Weak references in generic types

2016-08-31 Thread Howard Lovatt via swift-users
Playing around I found that if you make the protocol @objc instead of AnyObject then it works :). EG: struct WeakReference { weak var value: T? } @objc protocol P { // Note @objc, class or AnyObject does not work var i: Int { get } } class CP: P { var i: Int = 0 } let weakPs: [WeakRefe

[swift-users] Weak references in generic types

2016-08-29 Thread Howard Lovatt via swift-users
Hi, I am wanting to use weak references in generic data structures; in the example below Array, but in general any generic type. I can almost get it to work :( My experiments started off well; the following works: // Array of weak references OK struct WeakReference { weak var value: T? } cla

Re: [swift-users] Object size on heap

2016-03-23 Thread Howard Lovatt via swift-users
on malloc family >> functions to make inquiries: >> >> let required_size = malloc_size(unsafeAddressOf(*object_reference*)) >> let actual_size = malloc_good_size(required_size) >> >> >> Kate Stone k8st...@apple.com >>  Xcode Low Level Tools >

Re: [swift-users] Object size on heap

2016-03-23 Thread Howard Lovatt via swift-users
ired_size = malloc_size(unsafeAddressOf(*object_reference*)) > let actual_size = malloc_good_size(required_size) > > > Kate Stone k8st...@apple.com >  Xcode Low Level Tools > > On Mar 23, 2016, at 3:59 PM, Howard Lovatt via swift-users < > swift-users@swift.org> wrote: >

Re: [swift-users] Object size on heap

2016-03-23 Thread Howard Lovatt via swift-users
Thanks, I will give that a try -- Howard. On 24 March 2016 at 03:17, Jens Alfke wrote: > > On Mar 22, 2016, at 11:04 PM, Howard Lovatt via swift-users < > swift-users@swift.org> wrote: > > I am writing custom collection classes and trying to assess which one is >

Re: [swift-users] Object size on heap

2016-03-22 Thread Howard Lovatt via swift-users
I am writing custom collection classes and trying to assess which one is better, both in terms of performance and memory usage. Won't be used in 'real' code, just to guide development. -- Howard. On 23 March 2016 at 03:52, Jordan Rose wrote: > > On Mar 22, 2016, at 8:47, Joe Groff via swift-u

Re: [swift-users] Object size on heap

2016-03-22 Thread Howard Lovatt via swift-users
Many thanks -- Howard. On 23 March 2016 at 02:47, Joe Groff wrote: > > On Mar 21, 2016, at 9:31 PM, Howard Lovatt > wrote: > > How do you call swift_class_getInstanceExtents, it doesn't show in Xcode? > > > It's not provided as API by default. You can do this as an unsupported > hack: > > @_

Re: [swift-users] Object size on heap

2016-03-21 Thread Howard Lovatt via swift-users
How do you call swift_class_getInstanceExtents, it doesn't show in Xcode? -- Howard. On 22 March 2016 at 06:07, Joe Groff wrote: > > > On Mar 19, 2016, at 1:53 PM, Howard Lovatt via swift-users < > swift-users@swift.org> wrote: > > > > Hi, > > > &g

Re: [swift-users] Strange type error

2016-03-21 Thread Howard Lovatt via swift-users
Hi, I don't understand your comment, can you explain some more please? Thanks, -- Howard. On Monday, 21 March 2016, zh ao wrote: > You protocol is not defined properly. > > On Mon, Mar 21, 2016 at 7:08 AM, Howard Lovatt via swift-users < > swift-users@swift.or

[swift-users] Strange type error

2016-03-20 Thread Howard Lovatt via swift-users
HI, Does anyone know what is happening here: protocol Subscriptable { associatedtype Element associatedtype Index var firstIndex: Index { get } var lastIndex: Index { get } subscript(index: Index) -> Element { get set } } struct AllSubscriptable: Subscriptable { t

[swift-users] Object size on heap

2016-03-19 Thread Howard Lovatt via swift-users
Hi, Is there a way to find out how big an object is on the heap? Cheers, — Howard. PS I did search swift-users but no luck :( ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

Re: [swift-users] Recommendation for thread-safe dictionary

2015-12-10 Thread Howard Lovatt via swift-users
I would do something like: import Foundation class Task { // Must be a class to prevent Swift copy semantics eliminating the result private static let queue = dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0) private let group = dispatch_group_create()