[swift-users] discardable function start?

2017-05-08 Thread J.E. Schotsman via swift-users
Hello, I’ve got a compiler warning from hell (actually this is XCGLogger code): @discardableResult open func add(item: String) -> Bool { return itemsToMatch.insert(item).inserted } open func add(items: S) where S.Iterator.Element == String { for item in items {

Re: [swift-users] edit array

2017-04-26 Thread J.E. Schotsman via swift-users
On 26 Apr 2017, at 18:13, Ole Begemann wrote: > There have been requests for something like this on swift-evolution, e.g. > here in the context of the discussion about a `reduce` variant that takes > `inout` arguments: >

Re: [swift-users] edit array

2017-04-26 Thread J.E. Schotsman via swift-users
> On 26 Apr 2017, at 16:54, Rien wrote: > > Agree, though the function should probably be named something like: withEach > instead of forEach. > Maybe worth a proposal on evolution? Let’s wait until the people at the other side of the big lake have had time to react.

Re: [swift-users] edit array

2017-04-26 Thread J.E. Schotsman via swift-users
On 26 Apr 2017, at 16:27, Rien wrote: > To edit the value in the array itself use: > > array[index].number += 1 That requires a for loop. Functional programming lets you write for loops more succinctly. Why can’t $0 not be used as a reference, like array[index] ? I've

[swift-users] edit array

2017-04-26 Thread J.E. Schotsman via swift-users
Simple question: why can’t I edit a variable array with a functional method? For example: struct TestStruct { var number = 0 } var array = [TestStruct](repeatElement(TestStruct(), count: 2)) array.forEach { $0.number += 1 } Jan E.

Re: [swift-users] OptionSet as Sequence

2017-03-13 Thread J.E. Schotsman via swift-users
On 12 Mar 2017, at 23:23, Zhao Xin wrote: > I don't see the needs to call `for domain in domains` with > `domains:OptionSet`. If a parameter want an OptionSet, why not just > use`domains` directly instead of `domain`? You are right, I was writing bad code. When working with

[swift-users] OptionSet as Sequence

2017-03-12 Thread J.E. Schotsman via swift-users
Hello, Recently I wrote code like this: let domains:[FileManager.SearchPathDomainMask] = [.userDomainMask, .localDomainMask, .networkDomainMask] for domain in domains { … } But I would prefer this: let domains:FileManager.SearchPathDomainMask = [.userDomainMask,.localDomainMask,

Re: [swift-users] ambiguous minus operator

2017-02-17 Thread J.E. Schotsman via swift-users
> On 16 Feb 2017, at 18:58, Saagar Jha wrote: > > DispatchTimeInterval.nanoseconds expects an Int, while uptimeNanoseconds is > an UInt64 (an thus so is their difference). You can “fix” this by adding an > explicit cast: Aha! So this was just a confusing compiler

[swift-users] ambiguous minus operator

2017-02-16 Thread J.E. Schotsman via swift-users
Hello, I am trying to define an operator that subtracts dispatch times: #import Dispatch func -( time1: DispatchTime, time2: DispatchTime ) -> DispatchTimeInterval { return DispatchTimeInterval.nanoseconds( time2.uptimeNanoseconds - time1.uptimeNanoseconds ) } Compiler

[swift-users] dispatch queue attributes

2017-02-11 Thread J.E. Schotsman via swift-users
Hello, Once a dispatch queue has been created it is not possible to get its attributes, autorelease frequency and target (unless I am mistaken). Is this by design? Jan E. ___ swift-users mailing list swift-users@swift.org

Re: [swift-users] ranges and min

2017-01-23 Thread J.E. Schotsman via swift-users
> On 23 Jan 2017, at 16:12, Wagner Truppel wrote: > > Is it possible that the enclosing scope exposes a definition of min that > might take precedence over Swift.min unless you namespace the invocation? You are right. The code is part of a Data extension. Data is a

[swift-users] ranges and min

2017-01-23 Thread J.E. Schotsman via swift-users
This doesn’t compile: let data1 = Data(count:4) let data2 = Data(count:5) for i in 0..

[swift-users] disambiguate selector

2017-01-13 Thread J.E. Schotsman via swift-users
Hello, When I wrote this: table.performSelector( onMainThread:#selector(NSTableView.reloadData) ) I got a message “Ambiguous reference to member 'reloadData()” With a little help from Stackoverflow I managed to fix it: #selector(NSTableView.reloadData as (NSTableView) -> ((Void)->Void))) My

Re: [swift-users] getResourceValue

2017-01-06 Thread J.E. Schotsman via swift-users
> On 06 Jan 2017, at 14:39, Rod Brown wrote: > > Hi Jan, > > The Swift 3 URL struct has a modernized version of the NSURL API which works > far better in Swift. This replaces “getResourceValue(…)” with the API you > mentioned: “resourceValues(forKeys:)”. I still

Re: [swift-users] getResourceValue

2017-01-06 Thread J.E. Schotsman via swift-users
thods resourceValues(forKeys: Set) and setResourceValues(URLResourceValues) >> On 05 Jan 2017, at 20:36, J.E. Schotsman via swift-users >> <swift-users@swift.org> wrote: >> >> Hello, >> >> Is getResourceValue a method or URL or only on NSURL? >

[swift-users] minimum deployment target

2016-11-14 Thread J.E. Schotsman via swift-users
Hello, I have some code that is used in both a project with minimum deployment target 10.9 and a project with minimum deployment target 10.11. If I check for availability of API’s on the 10.9 project I get warnings on the 10.11 project saying these checks are unnecessary. Can I conditionalize

[swift-users] find std lib doc

2016-10-12 Thread J.E. Schotsman via swift-users
Is it just me, or is the Standard library document not very discoverable? Try searching developer.apple.com for "(Swift) standard library". No hit! Can’t find it on swift.org either (which isn’t even searchable). In case anybody else needs it, Mateusz Malczak gave me the link:

[swift-users] try? priority

2016-08-04 Thread J.E. Schotsman via swift-users
I was surprised when I got a compiler error for this code: if try? MyThrowingFunction() != nil {…} (MyThrowingFunction does not return an optional value) This compiles: if (try? MyThrowingFunction) != nil {…} (Xcode 7.3.1) Shouldn’t try? have higher priority than != here? Please

Re: [swift-users] NSData and UnsafePointer

2016-07-18 Thread J.E. Schotsman via swift-users
> On 16 Jul 2016, at 22:16, Andrew Trick wrote: > > I don’t know what the recommended idiom is or if the syntax has changed from > Swift 2 to 3, but I would do something like this: > > withExtendedLifetime(data) { > let dataStart = UnsafePointer(data.bytes) >

Re: [swift-users] lazy initialisation

2016-07-04 Thread J.E. Schotsman via swift-users
> On 04 Jul 2016, at 19:21, Zhao Xin wrote: > > You'd better sharing some of you code here first. For example, consider this: class TestStruct1 { let a = 10 let b = 20 let c:Int = {return self.a*self.b}() } Of course this is a