Re: [swift-users] How to do Cocoa bindings in Swift? IB rejects optionals

2017-01-17 Thread Jean-Denis Muys via swift-users
ut I'm not > in front of my computer and can't double-check. > > HTH > - Dave Sweeris > > Sent from my iPhone > >> On Jan 16, 2017, at 10:11, Jean-Denis Muys via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Hi, >> &

[swift-users] How to do Cocoa bindings in Swift? IB rejects optionals

2017-01-16 Thread Jean-Denis Muys via swift-users
Hi, I am exploring the use of Swift for a Mac Cocoa application - using Xcode 8.2.1, and it seems I hit a roadblock regarding Cocoa bindings. In this toy Core Data document-based project, I added an NSArrayController in the StoryBoard. I need to bind it a NSManagedObjectContext so that my user

[swift-users] Core Data auto-generated Swift files errors?

2017-01-15 Thread Jean-Denis Muys via swift-users
Hi, Using Xcode 8.2.1 I just created a brand new document-based Cocoa application using Core Data and Swift. I created a single entity in the Document.xcdatamodeld file. I selected "Class Definition" in the CodeGen pop up menu in the inspector. My entity is named PHAudioFile. I then asked Xcode

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

2016-10-12 Thread Jean-Denis Muys via swift-users
Hi, I defined this: func random(from r: Range) -> Int { let from = r.lowerBound let to = r.upperBound let rnd = arc4random_uniform(UInt32(to-from)) return from + Int(rnd) } so that I can do: let testRandomValue = random(from: 4..<8) But this will not let me do: let other

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

2016-10-10 Thread Jean-Denis Muys via swift-users
So I suppose you feel this case is different from the (unsafe)  implicitly unwrapping of optionals with the “!” operator. Why do you feel the situation is different? > On 10 Oct 2016, at 17:34, Ole Begemann wrote: > >> When I declare my closure as @noescape, (the default), I explicitly tell

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

2016-10-10 Thread Jean-Denis Muys via swift-users
Thanks Ole, You are perfectly right regarding the error message. For some reason, I misread it. I am sorry about that. The actual error message, as you point out, makes much more sense! The rest of your explanation makes sense too, except: When I declare my closure as @noescape, (the default),

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

2016-10-10 Thread Jean-Denis Muys via swift-users
return 2*result > } > > let temp1 = closure(1) > let temp2 = closureDoubled(1, closure2: closure) > return temp1+temp2 > } > > Everything works as expected now. So I think the reason is just because of > `closure` was not define in `fun

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

2016-10-09 Thread Jean-Denis Muys via swift-users
Here is a contrived reduction of my problem func mainFunction(closure:(Int) -> Int) -> Int { func closureDoubled(_ n: Int) -> Int { let result = closure(n) return 2*result } let temp1 = closure(1) let temp2 = closureDoubled(1) return temp1+temp2 } The

Re: [swift-users] CharacterSet vs Set

2016-10-03 Thread Jean-Denis Muys via swift-users
ote: > > >> On 3 Oct 2016, at 16:28, Jean-Denis Muys via swift-users >> wrote: >> >> ASCII? Probably not. Latin? perhaps, though not obvious. For example French >> accented letters would probably have to be handled somehow. Greek or >> Cyrillic? Perhaps

Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-03 Thread Jean-Denis Muys via swift-users
Indeed, But that function was just an example. I wanted to learn about how to use the stack to call C functions that will fill some memory area passed as a pointer. Jean-Denis > On 3 Oct 2016, at 09:46, Quinn The Eskimo! via swift-users > wrote: > > > On 3 Oct 2016, at 01:14, Mike Ferendu

Re: [swift-users] CharacterSet vs Set

2016-10-03 Thread Jean-Denis Muys via swift-users
> On 3 Oct 2016, at 09:43, Quinn The Eskimo! via swift-users > wrote: > > > On 2 Oct 2016, at 19:02, Jean-Denis Muys via swift-users > wrote: > >> The problem is, I could not find a simple way to convert from a character to >> a unicodeScalar. > >

[swift-users] clang builtins from Swift?

2016-10-02 Thread Jean-Denis Muys via swift-users
Hi, Xcode seems to think that [some] builtins can be used from Swift. It autocompletes popcount for example, and command-clicking the function opens a bona fide interface file, with the following declaration (among others): public func __builtin_popcount(_: UInt32) -> Int32 However, when I try t

[swift-users] UnsafeMutablePointer on the stack?

2016-10-02 Thread Jean-Denis Muys via swift-users
Hi, I have some issues using the new raw memory API. For instance, let's suppose I want to call the `SecRandomCopyBytes` API to generate a cryptographically secure random 32-bit number. The difficulty is its 3rd argument, which is declared as UnsafeMutablePointer. Here is a function that does that

[swift-users] CharacterSet vs Set

2016-10-02 Thread Jean-Denis Muys via swift-users
I was playing with CharacterSet, and I came up with: let vowels = CharacterSet(charactersIn: "AEIOU") let char: Character = "E" vowels.contains(char) That last line doesn't compile: I get "*cannot convert value of type 'Character' to expected argument type 'UnicodeScalar'*" The problem is, I

[swift-users] Extend int arrays to be hashable?

2016-09-06 Thread Jean-Denis Muys via swift-users
Hello, I am struggling to convince Swift 3 (from Xcode 8 beta 6) to let me use an array of Int as dictionary keys. It doesn’t work out of the box, because an array is not hashable: var answers: [[Int]:Bool] = [:] // error: Type [Int] does not conform to Protocol Hashable One way to work aroun

[swift-users] how to create an array by adding/removing from another array?

2016-08-24 Thread Jean-Denis Muys via swift-users
Hi, Using Swift 3, I am in a situation where I need to construct an output array step by step by picking (and possibly modifying) some item from an input array (“consuming” that item, i.e. removing it from the input array). That very easy to do by mutating “var” variables, using the append() an

Re: [swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread Jean-Denis Muys via swift-users
Here is an outline on how you might achieve that. 1- Create a background GCD queue and a GCD semaphore. 2- dispatch_async your sort routine on that queue 3- add a call to dispatch_semaphore_wait before starting your sort. This will grab the semaphore. 4- at the //wait here point, call dispatch_se