Re: [swift-users] Why this string not work. Any and Optionals in dictionary

2017-01-23 Thread Ole Begemann via swift-users
I have a simple expression with Any and is not work. Why? vardictarray: [[String: Any]] = [["kek": nil]] \\ Nil is not compatible with expected dictionary value type 'Any' `nil` is just a literal value that doesn't have a specific type. Even though you want to put it in a dictionary whose

Re: [swift-users] Check deployment target at runtime or compile time

2017-02-15 Thread Ole Begemann via swift-users
> On 15 Feb 2017, at 20:40, Greg Parker <gpar...@apple.com> wrote: > >> On Feb 15, 2017, at 11:11 AM, Ole Begemann via swift-users >> <swift-users@swift.org> wrote: >> >> In macOS 10.12 and iOS 10.0, class properties were introduced to Objective

[swift-users] Check deployment target at runtime or compile time

2017-02-15 Thread Ole Begemann via swift-users
In macOS 10.12 and iOS 10.0, class properties were introduced to Objective-C [1]. I noticed that the Objective-C runtime treats class properties differently based on the deployment target. Example: // MyClass is an Objective-C class that has a class property let metaclass =

Re: [swift-users] Searching thru many threads; Linux dev

2017-02-17 Thread Ole Begemann via swift-users
On 16/02/2017 04:37, Félix Fischer via swift-users wrote: 1) How do I search through the threads of the mailing list? I'm looking for answers to Q2 The best way I've found for searching the archives is Google. Try something like: linux site:lists.swift.org/pipermail/swift-users

Re: [swift-users] Postponing owned object deinitialization

2017-02-27 Thread Ole Begemann via swift-users
On 27/02/2017 15:17, Nate Chandler via swift-users wrote: Hello all, I'm encountering a behavior around object lifetime and deinitialization that is surprising to me. Here's an approximation of what I'm encountering: I have a class Handle whose deinit must execute on a certain queue (let's

Re: [swift-users] Postponing owned object deinitialization

2017-02-27 Thread Ole Begemann via swift-users
On 27/02/2017 19:34, Nate Chandler via swift-users wrote: Hi Ole, A quick follow-up--are you suggesting calling withExtendedLifetime inside the closure passed to async, as below? class AsyncHandle { let handle: Handle deinit { let handle: Handle = self.handle q.async

Re: [swift-users] Data withUnsafeBytes

2016-09-04 Thread Ole Begemann via swift-users
The compiler has no way of inferring the type of the generic ContentType parameter because you're not using that parameter anywhere in the body of the closure that could give the compiler a hint. So you have to provide the type manually by explicitly annotating the type of the closure's

Re: [swift-users] Issues with UITableView*

2016-09-12 Thread Ole Begemann via swift-users
> Hmm - interesting to know. Unfortunately, if I do that, then I get > NO indication of selection when I click on ANY row. Perhaps I need > to make some other changes to account for the change in how I get the > cell? You also need to store your cells' selection state someplace outside of the

Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-13 Thread Ole Begemann via swift-users
The more idiomatic way is to look at API design in a new way. Note these points: 1. `Countable` variant is preferred when you want to deal with integer ranges as it more closely matches the element type. 2. Both countable range variants share a common protocol conformance already:

Re: [swift-users] Compiler refuses non-escaping closure calls in nested function

2016-10-10 Thread Ole Begemann via swift-users
The line "let result = closure(n)" is refused by the compiler with the error message "declaration over non closing parameter may allow it to escape". First off, while I know what an escaping or a non-escaping closure is, I find this error message utterly impossible to understand. To begin with,

Re: [swift-users] Compiler refuses non-escaping closure calls in nested function

2016-10-10 Thread Ole Begemann via swift-users
When I declare my closure as @noescape, (the default), I explicitly tell the compiler that, despite the fact closing over it *may* allow it to escape, I, the programmer, guarantee that it will not. I would understand a warning, but I don’t understand that the compiler insists on putting out an

Re: [swift-users] UnsafePointer and C-String

2017-01-03 Thread Ole Begemann via swift-users
What I cannot find though is the guarantee that the buffer where the String is converted to an UTF8 sequence is always null-terminated. I very much suspect it is, and all my tests did find a null-terminated string. Question: Does anybody know for sure that the buffer is always null-terminated?

Re: [swift-users] Why do collections use the debugDescription on their elements?

2017-01-05 Thread Ole Begemann via swift-users
I wonder why the description method of collections use the debugDescription method to print their elements, and not the description method. Dmitri Gribenko gave this reason in December 2015 [1]: Array's description shouldn't be presented to the user in raw form, ever, so the use case here is

Re: [swift-users] Confused/Surprised by IndexingIterator.forEach behavior

2016-12-28 Thread Ole Begemann via swift-users
On 28/12/2016 19:57, Travis Griggs via swift-users wrote: The behavior of the following playground snippet surprised me: var source = [10, 20, 30, 40] var stream = source.makeIterator() stream.next() // 10 stream.next() // 20 stream.forEach { (each) in print("\(each)") } // prints

Re: [swift-users] Unexpected results when using String.CharacterView.Index

2017-03-09 Thread Ole Begemann via swift-users
On 09/03/2017 08:27, Zhao Xin via swift-users wrote: When using subscript of `String.CharacterView`, I got an unexpected error. fatal error: Can't form a Character from an empty String func test() { let s = "Original Script:" let cs = s.characters //let startIndex =

Re: [swift-users] adopting RandomAccessCollection protocol

2017-03-12 Thread Ole Begemann via swift-users
On 12/03/2017 16:58, Don Giovanni via swift-users wrote: I'm trying to adopt the RandomAccessCollection protocol from a class. I deliberately leave out the func index(before:) function because there is already a default implementation of that function in RandomAccessCollection. I do understand

Re: [swift-users] Confusing Error localizedDescription output

2017-03-05 Thread Ole Begemann via swift-users
It's how protocols work in Swift. errorDescription is a protocol requirement of LocalizedError (that is, it's part of the protocol definition, not just added in an extension). Only protocol requirements are dynamically dispatched. Take a look at the implementation of

Re: [swift-users] Proper Way to make Errors in Swift 3

2017-03-05 Thread Ole Begemann via swift-users
Have you tried explicitly casting the value to NSError when you pass it to Objective-C? I think it should work then. let myError: MyError = ... myObjCFunc(myError as NSError) On 02/03/2017 17:29, Ronak via swift-users wrote: Hi everyone, It looks like I’m still having issues exposing

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

2017-07-15 Thread Ole Begemann via swift-users
One way to do this in Swift is a method called type erasure. Type erasure means you create a new type that wraps any value whose concrete type you want to erase. This new type also conforms to the protocol. By convention the type is named Any... (compare AnyIterator and AnySequence in the

Re: [swift-users] edit array

2017-04-26 Thread Ole Begemann via swift-users
On 26.04.2017 17:01, J.E. Schotsman via swift-users wrote: 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

Re: [swift-users] withUnsafeMutableBytes is killing me

2017-04-25 Thread Ole Begemann via swift-users
The withUnsafeMutableBytes method has two generic parameters, ResultType and ContentType: |mutating func withUnsafeMutableBytes(_ body: (UnsafeMutablePointer ) throws -> ResultType) rethrows -> ResultType| In your examples, the type checker can't infer the type of

Re: [swift-users] withUnsafeMutableBytes is killing me

2017-04-25 Thread Ole Begemann via swift-users
On 25.04.2017 12:24, Rick Mann via swift-users wrote: Not the ResultType, you mean, but the input type, right? Yes, sorry, I meant ContentType. Yeah, I finally figured that out, although it doesn't explain another situation I'm experiencing that I didn't include in the post. However, that

Re: [swift-users] package graphroot error

2017-10-11 Thread Ole Begemann via swift-users
On 01.10.17 19:28, Muhammad Tahir Vali via swift-users wrote: Hello, I've updated to swift 4.0 and downloaded a CL tool swiftenv . Mixing and debugging with different versions , I may have messed up my swift environment variables and ultimately deleted my swift-tools. How do I safely default

Re: [swift-users] Swift 4 Strings and flatMap

2017-10-21 Thread Ole Begemann via swift-users
On 21.10.17 02:50, Santiago Gil via swift-users wrote: I just ran into a bug after a Swift 4 migration where we expected [String] and got [Character] from a flatMap since flatMap will flatten the String since it's now a collection.  While I understand why flatMap behaves this way now that