Re: [swift-users] Parameter Validation

2015-12-07 Thread Jens Alfke via swift-users
> On Dec 7, 2015, at 11:39 AM, Jan Neumüller via swift-users > wrote: > > I fail to see any overhead here. Its the absolute minimum to get checked > values. Anything less is not checking. There’s no overhead if the function already ‘throws’ / returns errors. But not

Re: [swift-users] Using Swift for interpreted shell scripts?

2015-12-15 Thread Jens Alfke via swift-users
Swift doesn’t seem like a good fit for the kinds of tasks people write shell-scripts for. It’s a system/app programming language, like C/C++. Scripting languages have extremely dynamic typing, super-high-level APIs, and no separate compile/link stage. There’s no reason you couldn’t convert

Re: [swift-users] Newbie Question

2016-01-05 Thread Jens Alfke via swift-users
> On Jan 4, 2016, at 9:07 AM, Sherri McGurnaghan via swift-users > wrote: > > I am trying to do something super simple using Swift - we are changing our > infrastructure and the new environment requires me to work with Swift. > Needless to say, I am a complete newbie

Re: [swift-users] "business applications market" flame

2016-01-06 Thread Jens Alfke via swift-users
> On Jan 6, 2016, at 1:12 PM, Don Wills wrote: > > It also means that every third party API provider will *never* be able to > change any method signature from failable to non-failable or vice-versa. > That is a really bad thing! API consistency is a good

Re: [swift-users] "business applications market" flame

2016-01-06 Thread Jens Alfke via swift-users
> On Jan 6, 2016, at 5:04 PM, Dru Satori wrote: > > Oh, on OS X, swift works fine with PostgreSQL and ODBC datasources via Obj-C > frameworks, that isn’t the challenge. It would be interesting to see how far Swift’s syntax can be pushed to create a cleaner syntax for

Re: [swift-users] Optionals and method overloading with Any

2016-01-06 Thread Jens Alfke via swift-users
> On Jan 6, 2016, at 7:16 PM, Don Wills via swift-users > wrote: > > Swift method lookup obviously chose the second mth func if it exists, but why? >From the behavior here, it looks like the compiler is first looking for a >matching method, then if it can’t find one it

Re: [swift-users] uppdate and read files on ubuntu

2015-12-29 Thread Jens Alfke via swift-users
> On Dec 29, 2015, at 1:22 PM, Jonas Fredriksson via swift-users > wrote: > > second, to read a file I tried fopen from Glibc but i requires > "UnsafePointer". how do I declare that, ie var file: > UnsafePointer? You probably wouldn’t declare a variable of that type.

Re: [swift-users] Cross Compiling Swift for Bare Metal?

2015-12-20 Thread Jens Alfke via swift-users
> On Dec 20, 2015, at 12:22 AM, Dmitri Gribenko via swift-users > wrote: > > Regarding the microcontroller that you referenced, I think it would be an > overly ambitious goal to try to make everything work with 256 Kb of flash and > 32 Kb of RAM. I would recommend to

Re: [swift-users] [swift-dev] Cross Compiling Swift for Bare Metal?

2015-12-21 Thread Jens Alfke via swift-users
> On Dec 20, 2015, at 3:03 PM, William Dillon via swift-users > wrote: > > Though it might sound a little silly (because why not run linux), but > starting with a beagle bone black would not be a terrible way to begin with > bare metal work. It has plenty of RAM, you

Re: [swift-users] More Swift-like initializers and enums in UIKit

2015-12-23 Thread Jens Alfke via swift-users
> On Dec 23, 2015, at 9:03 AM, Nick O'Neill via swift-users > wrote: > > Did I miss a spot where I can submit a PR for this or is there a chance the > Swift headers for these UIKit APIs could be made open source in the future? As with all things Apple that aren’t open

Re: [swift-users] Design and performance of Vector2/3/4 and Matrix

2015-12-18 Thread Jens Alfke via swift-users
> On Dec 18, 2015, at 12:07 PM, David Turnbull via swift-users > wrote: > > In order to be performant, scalars, vectors, and matrices must all be values > types aka structs. This way, for example, an Array can be > passed directly to OpenGL without any

Re: [swift-users] typealias in a protocol: can only be used as generic constraint?

2015-12-29 Thread Jens Alfke via swift-users
> On Dec 28, 2015, at 3:43 PM, Jonathan Bailey via swift-users > wrote: > > In the following code, I get an error on the line indicated (4th from the > bottom) that "Protocol 'APIEndPoint' can only be used as a generic constraint > because it has Self or associated

Re: [swift-users] Reason for Swift not having readwrite reflection

2015-12-17 Thread Jens Alfke via swift-users
> On Dec 17, 2015, at 10:54 AM, Gergely Orosz via swift-users > wrote: > > Not having readwrite reflection makes it impossible to create any mocking > frameworks for unit testing I also strongly want reflection, but for a different purpose: data modeling. Core Data’s

Re: [swift-users] Discrepancy between sharing internal Swift symbols with Obj-C when in an app vs a framework target

2016-06-04 Thread Jens Alfke via swift-users
> On Jun 4, 2016, at 11:29 AM, Kevin Lundberg via swift-users > wrote: > > However objc code inside the same framework as the swift code in question > should ideally be able to see internal swift symbols as well, as they are > within the same module. I agree; I didn’t

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-05 Thread Jens Alfke via swift-users
> On Jun 4, 2016, at 6:25 PM, Matthias Zenger via swift-users > wrote: > > I wanted to use NSFileHandle (for a use case that requires streaming) and > realized that this is an API that cannot really be used in Swift because it's > based on Objective-C exceptions.

Re: [swift-users] Discrepancy between sharing internal Swift symbols with Obj-C when in an app vs a framework target

2016-06-04 Thread Jens Alfke via swift-users
> On Jun 3, 2016, at 7:55 PM, Kevin Lundberg via swift-users > wrote: > > swift code in an app target can be accessed from obj-c if it is internal > or public. However, swift code in a framework target can only be > accessed from objc if it is public, not internal.

Re: [swift-users] Printing large hexadecimal values

2016-05-25 Thread Jens Alfke via swift-users
> On May 25, 2016, at 10:16 AM, Ken Burgett via swift-users > wrote: > > I wish to print a 64-bit unsigned integer as 8 hexadecimal digits, and I > can't find any documentation on this. Please advise. print(String(format: “%llx”, n))// typed from

Re: [swift-users] inout params seem to have undefined behavior

2016-06-13 Thread Jens Alfke via swift-users
> On Jun 13, 2016, at 1:43 PM, Joe Groff wrote: > > I see, missed that part. That's a bug—`acopy` should remain a distinct copy > of `a`. I’m guessing that when `a` is copied into `acopy`, the same array contents are shared between them, then when `a` is mutated it gets a

Re: [swift-users] inout params seem to have undefined behavior

2016-06-13 Thread Jens Alfke via swift-users
> On Jun 13, 2016, at 9:45 AM, Joe Groff via swift-users > wrote: > > It's not undefined behavior in that we try to ensure that memory safety is > still preserved when inout parameters alias, but it is *unspecified* when > updates to an inout parameter will be written

Re: [swift-users] Usage of final let?

2016-06-13 Thread Jens Alfke via swift-users
> On Jun 12, 2016, at 10:43 PM, Azuan via swift-users > wrote: > > Read in docs, saying that by using final on variables, you can’t override it > in it’s subclass. Using `final var` makes sense to me. But what is the > purpose of using `final let` since by using `let`,

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-05 Thread Jens Alfke via swift-users
Looks good, but you'll want some error handling. There's no clean way to integrate it with Generator because the protocol doesn't allow the implementation to throw, unfortunately. (I've run into the same problem building a Generator around a database query.) I think the best solution is to add

Re: [swift-users] [Swift 3.0 Preview] Can't Convert to Latest Swift Syntax

2016-06-02 Thread Jens Alfke via swift-users
> On Jun 1, 2016, at 5:32 PM, Jordan Rose via swift-users > wrote: > > The Swift migrator as used in Xcode 7.3 is not open-source, so it’s not > included in the downloadable toolchains. I’m afraid you’ll have to migrate > your project by hand at this point. The

Re: [swift-users] Can Swift 2.3 frameworks be used with a Swift 3.0 app?

2016-06-27 Thread Jens Alfke via swift-users
> On Jun 27, 2016, at 8:30 AM, Daniel Dunbar via swift-users > wrote: > > No, this is not possible. All of the code in a single process needs to be > compiled with the same version of Swift. How long will this be the case? The product I work on is distributed primarily

Re: [swift-users] Can Swift 2.3 frameworks be used with a Swift 3.0 app?

2016-06-27 Thread Jens Alfke via swift-users
> On Jun 27, 2016, at 8:59 AM, zh ao wrote: > > Not with current Swift 3. Currently, the developing team make efforts on > releasing Swift 3 together with iOS 10 and macOS 10.12 in September. I know it’s not with Swift 3. Hopefully people on the dev team are thinking

Re: [swift-users] Memory used by enums

2016-04-05 Thread Jens Alfke via swift-users
> On Apr 4, 2016, at 4:57 PM, Jonathan Hull via swift-users > wrote: > > If this enum is going to be used by tens/hundreds of thousands of structs, am > I actually saving any space by breaking out the rarer cases which store more > data or is the footprint just equal

[swift-users] Generators vs. errors

2016-04-12 Thread Jens Alfke via swift-users
What should one do, when implementing a Generator, if the underlying data source can experience errors? Generator.next isn’t allowed to throw, only to return nil at the end of the sequence. The only idea I can think of is to add an `error` property to my Generator implementation, and request

[swift-users] Trouble constraining a generic type in an extension

2016-04-12 Thread Jens Alfke via swift-users
I’ve got a simple generic struct that wraps an instance of its parameter type. public struct check { let actual: T public init(_ a: T) {actual = a} ... Now I want to add a method that only works with a specific type, Bool: public func isTrue(){XCTAssertTrue(actual)} As I’d

Re: [swift-users] Sampling collections

2016-04-10 Thread Jens Alfke via swift-users
> On Apr 10, 2016, at 6:01 PM, Milos Rankovic > wrote: > > As I already stressed, I certainly do not imagine this to be > “Swift-specific”, nor do I see any reason it would need to be. It sounds like you’re asking for a `sample` property to be added to NSArray,

Re: [swift-users] Sampling collections

2016-04-10 Thread Jens Alfke via swift-users
Well, write up a proposal and submit it to swift-evolution and let people discuss it. > I’m sorry we are spending so much time discussing why this may be difficult > for *someone* (because it likely won’t be us) to implement.

Re: [swift-users] Sampling collections

2016-04-10 Thread Jens Alfke via swift-users
> On Apr 10, 2016, at 1:00 PM, Milos Rankovic > wrote: > > The ObjC–Swift bridge is relevant here only in the sense that I would also > like sampling methods added to `NSArray`, `NSSet` or `NSDictionary`… Any library or program can add methods to any class using

[swift-users] Trouble assigning an array of C pointers to a C struct field

2016-04-10 Thread Jens Alfke via swift-users
I’m bridging a C API (that I wrote) to Swift; I’ve got most of it together, but I’m stuck on one part, where I can’t get the bridging code to compile without errors no matter how I write it. The basic problem is I’ve got a dynamically-allocated opaque C pointer type (C4Key*), and there’s a

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-07 Thread Jens Alfke via swift-users
I’m not familiar with this design pattern, but it looks like Entity would just contain an array of Component. That makes add() and remove() straightforward. I’m not sure about your get() method. It sounds as though the implication is that an entity could only contain a single component of a

Re: [swift-users] Why can't I declare subscript ?

2016-04-11 Thread Jens Alfke via swift-users
> On Apr 11, 2016, at 2:08 PM, Trent Nadeau wrote: > > This is a known language limitation. See https://bugs.swift.org/browse/SR-115 > . It looks like someone started to > implement it, but it has been dormant since December. Thanks,

Re: [swift-users] Object size on heap

2016-03-21 Thread Jens Alfke via swift-users
> On Mar 19, 2016, at 4:53 PM, Howard Lovatt via swift-users > wrote: > > Is there a way to find out how big an object is on the heap? Yes, the sizeof() function. —Jens___ swift-users

Re: [swift-users] Collection underestimatedCount() does _?

2016-03-21 Thread Jens Alfke via swift-users
> On Mar 19, 2016, at 1:53 AM, Will Stanton via swift-users > wrote: > > Don’t most collections have O(1) `count` anyway? No; linked lists and trees, which are pretty popular data structures, are generally O(n) to count.

[swift-users] Assigning [Int] to [Any] crashes Swift 2.2

2016-04-13 Thread Jens Alfke via swift-users
Just ran into a weird crash with Swift 2.2 in Xcode 7.3. It reproduces in a playground: import Foundation let a = [88] let b: [Any] = a // CRASH In my real program, the top of the crash backtrace is: * thread #1: tid = 0x460b62, 0x00010669988b libswiftCore.dylib`swift_unknownRetain +

Re: [swift-users] == works for NSObject? but not for Equatable?

2016-04-27 Thread Jens Alfke via swift-users
Oh, never mind — I forgot that you can’t compare two Equatable values directly, only two values of the same concrete type that implements Equatable. I’m still thinking in Objective-C, clearly… —Jens ___ swift-users mailing list swift-users@swift.org

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-20 Thread Jens Alfke via swift-users
> On May 20, 2016, at 9:44 AM, Jan Neumüller via swift-users > wrote: > > What advantage? Streaming IO is a pain in the . I never got what people > like at this stuff Well for one, it abstracts away the source of the data. It could be a file, a TCP socket, an HTTP

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-19 Thread Jens Alfke via swift-users
> On May 19, 2016, at 12:58 AM, Quinn The Eskimo! via swift-users > wrote: > > The reason I ask is that most of the time when I mess around with files I > transfer the entire file to and from memory, which is something that the > Foundation APIs excel at. I believe

Re: [swift-users] Dictionary with optional values

2016-05-19 Thread Jens Alfke via swift-users
> On May 18, 2016, at 7:35 PM, Nathan Day wrote: > > In objective-c I have come across something like this a lot where a > NSDictionary has been created from JSON an a NSNull is used to represent an > actual null in the source JSON versus the absence of the key Yeah, this

Re: [swift-users] Mapping C semantics to Swift

2016-05-20 Thread Jens Alfke via swift-users
> On May 20, 2016, at 7:33 AM, Ken Burgett via swift-users > wrote: > > the required C struct morphs into a Swift class, with a member function > 'as_C_byte_array' which answers an array of the required form. Internally, > this function will shift and mask class

Re: [swift-users] @noescape

2016-05-16 Thread Jens Alfke via swift-users
> On May 16, 2016, at 9:37 AM, Nate Birkholz via swift-users > wrote: > > I understand how @noescape works, and some of its benefits, I *think*, but if > I am correct, it almost seems like it should be added automatically to my > closure definitions until it becomes

Re: [swift-users] Member wise initializer doesn't work with default-initialized const properties

2016-05-18 Thread Jens Alfke via swift-users
> On May 17, 2016, at 7:48 AM, Neil Faiman via swift-users > wrote: > > “You can provide a default value for a stored property as part of its > definition, as described in Default Property Values. You can also set and > modify the initial value for a stored property

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread Jens Alfke via swift-users
> On May 18, 2016, at 11:03 AM, Artyom Goncharov via swift-users > wrote: > > Yes, of course I can use API method but this kind of behaviour for subscript > operator seems inconsistent(or even magical) to me because it is possible to > initialise a dictionary with nil

Re: [swift-users] Server side swift application ?

2016-05-03 Thread Jens Alfke via swift-users
> On May 1, 2016, at 11:48 AM, Tyler Fleming Cloutier via swift-users > wrote: > > libuv and libdispatch overlap on functionality quite a bit, but libdispatch > has the benefit of using a block API instead of a function pointer API, which > makes memory management

Re: [swift-users] Server side swift application ?

2016-05-03 Thread Jens Alfke via swift-users
> On May 3, 2016, at 12:46 PM, Gerard Iglesias wrote: > > A good reading > > https://github.com/robbiehanson/CocoaAsyncSocket > This is highly Mac/iOS-specific code, so it doesn’t make sense for applications targeted

Re: [swift-users] Unicode problem

2016-05-08 Thread Jens Alfke via swift-users
> On May 8, 2016, at 5:27 AM, Nabeel Imtiaz via swift-users > wrote: > > I am having problem with emojis’ rendering. Emojis like \u{F3A4} and \u{F3B5} > print question mark instead. They begin with number “F”. Those are not the correct Unicode values. There should be a

Re: [swift-users] Range.count can abort

2016-04-15 Thread Jens Alfke via swift-users
--Jens [via iPhone] > On Apr 15, 2016, at 4:26 PM, Dmitri Gribenko wrote: > > The distance is signed so that we can represent negative distances. > r.distance(from:to:) should be able to measure distances backwards. Yeah, makes sense in general, just not for this

Re: [swift-users] ?? operator question

2016-04-19 Thread Jens Alfke via swift-users
> On Apr 19, 2016, at 4:09 AM, Marco Feltmann via swift-users > wrote: > > "But wait a sec, how can NSFount(name: "", size: 0) result in an NSNumber?" > you may ask. > I don't now. > The behaviour of NSFonts +fonttWithName:size: for empty/not found font name > is not

Re: [swift-users] Range.count can abort

2016-04-16 Thread Jens Alfke via swift-users
> On Apr 16, 2016, at 12:53 PM, Dmitri Gribenko wrote: > > It needs to be a signed integer. And a signed integer needs a distance type > itself. Yeah, there’s an infinite regress implied there, since a distance type has to be one bit larger than its source type. The

Re: [swift-users] Assigning [Int] to [Any] crashes Swift 2.2

2016-04-14 Thread Jens Alfke via swift-users
> On Apr 14, 2016, at 9:00 AM, Joe Groff wrote: > > This is a known bug. Converting arrays of value type to arrays of protocol > type is not supported—only class covariance is supported with containers—but > the compiler fails to catch some cases. Thanks for the info! I

[swift-users] Range.count can abort

2016-04-18 Thread Jens Alfke via swift-users
I’m writing some code that deals with ranges of “sequence numbers”, which are consecutively-assigned positive 64-bit integers, thus Range in Swift. I’m having trouble handling half-open ranges with no maximum, which are very commonly used for representing all items created since a certain time.

Re: [swift-users] Foundation on Linux `CFBooleanGetTypeID`/`CFGetTypeID`

2016-05-24 Thread Jens Alfke via swift-users
> On May 24, 2016, at 1:39 PM, Ryan Lovelett wrote: > > I have filed a bug https://bugs.swift.org/browse/SR-1610 > > > Obviously please reformat/update accordingly. This was the best I could come > up with. Your issue

Re: [swift-users] Foundation on Linux `CFBooleanGetTypeID`/`CFGetTypeID`

2016-05-24 Thread Jens Alfke via swift-users
> On May 24, 2016, at 11:03 AM, Tony Parker wrote: > > Why not use `func boolValue` instead, if you need a true/false answer? I don’t remember the original code snippet, but there are cases where you need to know what type of number is stored in an NSNumber. An

Re: [swift-users] Foundation on Linux `CFBooleanGetTypeID`/`CFGetTypeID`

2016-05-24 Thread Jens Alfke via swift-users
For completeness I should add that there are other cases where you need to know the exact type: * When formatting a floating-point number, you should use 6 decimal places if it's a float, 16 if it's a double. (If you use all 15 for a float, you end up with results like “0.999”

Re: [swift-users] Is there method indiicate current thread is mainthread in swift?

2016-07-13 Thread Jens Alfke via swift-users
> On Jul 13, 2016, at 7:20 AM, Mark Dalrymple via swift-users > wrote: > > It's a change in Xcode 8.2 - NSThread.isMainThread in ObjC land is now a > class property: ^^ Xcode 8.0 (beta) > In Xcode 8.1(and since iPhone OS 2) it was a regular old-school

Re: [swift-users] Parsing binary data

2016-07-08 Thread Jens Alfke via swift-users
> On Jul 8, 2016, at 2:12 AM, Tino Heth via swift-users > wrote: > > But arrays are no option for me, because my data isn't structured that way: > It's a stream of different elements (timestamp, type, and a payload that > depends on the type), so I have evaluate

Re: [swift-users] Equality is broken, isn't it?

2016-07-06 Thread Jens Alfke via swift-users
> On Jul 6, 2016, at 9:54 AM, Alexey Komnin via swift-users > wrote: > > Here is the code: > >let a: String = "abc" >let b: NSString = "abc" > >assert(a == b) >assert(a.hashValue == b.hashValue, "a.hashValue(\(a.hashValue)) != >

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Jens Alfke via swift-users
> On Aug 1, 2016, at 7:24 PM, Rick Mann wrote: > > But my model has implicit reference semantics: multiple instances of a part > can share a PartDefinition; it is intended that if the PartDefinition > changes, all the referencing instances get the change. Bingo. That’s

Re: [swift-users] Swift 101: JSON or XML?

2017-02-03 Thread Jens Alfke via swift-users
> On Feb 3, 2017, at 5:00 AM, Roy Henderson via swift-users > wrote: > > I would welcome guidance regarding whether I should use JSON or XML to store > the data on the web server? The effort to generate either format will be > similar so my real decision driver is on

Re: [swift-users] How to debug Segmentation Fault

2017-02-01 Thread Jens Alfke via swift-users
> On Feb 1, 2017, at 5:25 PM, I wrote: > > gdb is no longer used on Mac (we have lldb instead), so further discussion of > it would be off-topic here :) Oops, never mind that … I didn’t notice this was swift-users and thought it was one of the Apple mailing lists. *facepalm*

Re: [swift-users] How to debug Segmentation Fault

2017-02-01 Thread Jens Alfke via swift-users
> On Feb 1, 2017, at 5:00 PM, Maxim Veksler via swift-users > wrote: > > My method, though effective is probably barbaric. It's been years since I've > touched code that can actually seg fault, and I'm rusty on how you approach > debugging such cases, I'm wondering

Re: [swift-users] Question about text colouring in NSTextView

2017-02-06 Thread Jens Alfke via swift-users
> On Feb 4, 2017, at 6:03 AM, Valera Tarasov via swift-users > wrote: > > Dear Members, > I need help and have a question about the performance of text coloring in > NSTextView. Your question is related to Apple’s Cocoa UI frameworks, but this list is focused on the

Re: [swift-users] Implementing String(contentOfUrl:usedEncoding)

2017-02-22 Thread Jens Alfke via swift-users
> On Feb 22, 2017, at 9:09 PM, Jens Alfke via swift-users > <swift-users@swift.org> wrote: > > - Otherwise, does it contain any bytes in the range 0x80-0xBF? Oops, that should be “0x80–0x9F”. —Jens___ swift-users mailing list swi

Re: [swift-users] Implementing String(contentOfUrl:usedEncoding)

2017-02-22 Thread Jens Alfke via swift-users
> On Feb 22, 2017, at 6:05 PM, Mohit Athwani via swift-users > wrote: > > I don't understand why we need the usedEncoding parameter? I understand that > it's a pointer but how do we decide what encoding to use? Do we default to > NSUTF8StringEncoding? The original

Re: [swift-users] Plan to move swift-evolution and swift-users mailing lists to Discourse

2017-02-08 Thread Jens Alfke via swift-users
> On Feb 8, 2017, at 4:48 PM, Jan Neumüller via swift-users > wrote: > > May I ask why with so many great open source forums that junk Discourse got > chosen? I'm very perplexed by this decision... I’ve looked at a lot of forum software, and most of the open-source

[swift-users] Can't extend a class to conform to ExpressibleByStringLiteral

2017-02-13 Thread Jens Alfke via swift-users
I’m making extensive use of NSPredicates, which can be initialized from format strings, so I decided to extend the class to implement ExpressibleByStringLiteral. I adapted an example in the book Advanced Swift to get this: extension NSPredicate : ExpressibleByStringLiteral { public

Re: [swift-users] Problem with console apps

2017-02-09 Thread Jens Alfke via swift-users
> On Feb 9, 2017, at 3:33 AM, Andrey Fidrya via swift-users > wrote: > > Neither setbuf(stdout, nil) nor fflush(stdout) helps, so it appears > this is an Xcode issue. In that case you should file bug report at http://bugreport.apple.com .

Re: [swift-users] source for a Swift module's interface

2017-01-16 Thread Jens Alfke via swift-users
> On Jan 16, 2017, at 6:18 PM, Dave Yost via swift-users > wrote: > > In Xcode I can put the caret on Darwin in "import Darwin” and use Jump to > Definition to see a Swift source file for the Darwin module. You can also just hold Command down and click. I use this

Re: [swift-users] Implicitly type conversion ?

2016-08-18 Thread Jens Alfke via swift-users
> On Aug 18, 2016, at 12:54 PM, Adel Zhang wrote: > > Any other situation when implicit type casting works? It would be better if > there is a reference or link. >From the Swift Programming Language book, the section “Optional Type”: The type Optional is an enumeration

Re: [swift-users] Need a way to include swift file into another swift file

2017-02-27 Thread Jens Alfke via swift-users
> On Feb 27, 2017, at 2:45 AM, Rupendra Limbore via swift-users > wrote: > > I am using swift as a CGI script with Apache server (just to explore). Are you treating Swift like a shell-script, by putting a “#!” at the top of the file? That works, but it’s going to be

Re: [swift-users] Pass Value of Variable to a Function

2016-09-06 Thread Jens Alfke via swift-users
> On Sep 6, 2016, at 9:39 PM, Michael Sheaver via swift-users > wrote: > > I know that in some languages, if you prepend the passed parameter with a > '$', as in $propertyName, the receiving function knows to use the contents of > the variable named propertyName (in

Re: [swift-users] strange property observer behavior

2016-09-04 Thread Jens Alfke via swift-users
> On Sep 4, 2016, at 8:11 AM, adelzhang via swift-users > wrote: > > Swfit encourage to override the property observer. But when we change the own > property in Child class's `didSet` observer, that would cause infinite loop: I’m not a Swift guru, but that seems like a

[swift-users] Mapping a Dictionary to a Dictionary?

2016-08-29 Thread Jens Alfke via swift-users
I may be missing something obvious, but I can’t find a library function that maps a Dictionary to another Dictionary, transforming the keys and/or values. The only method I’ve found is the regular map(), which results in an Array. Does this just not exist in the standard library? —Jens

Re: [swift-users] Mapping a Dictionary to a Dictionary?

2016-08-31 Thread Jens Alfke via swift-users
> On Aug 31, 2016, at 10:51 AM, Daniel Tartaglia wrote: > > I use the below to do this: > > dict2 = dict1.map { $0.withUpdate($0.0, value: $0.1) } I don’t see how this can work. Dictionary.map returns an Array, not a Dictionary. Also, in the callback function $0 is the

Re: [swift-users] How to extend a generic type with a Bool constraint?

2016-08-31 Thread Jens Alfke via swift-users
> On Aug 31, 2016, at 10:21 AM, Dan Loewenherz wrote: > > You'll need to specify a protocol where you're currently specifying "Bool". A > generic constraint can't take a concrete type as an argument. OK … this should be described in the book, though. (Any doc writers

[swift-users] How to extend a generic type with a Bool constraint?

2016-08-31 Thread Jens Alfke via swift-users
I have a generic type, and I want to add some methods that are available when the type parameter is Bool. (This is in Xcode 8 beta 6, btw.) public struct foo { ... } extension foo where T: Bool { … } The above fails to compile, with "type 'T' constrained to non-protocol type

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

2016-09-08 Thread Jens Alfke via swift-users
> On Sep 8, 2016, at 6:28 AM, Karl Wagner via swift-users > wrote: > > It is in some sense a language limitation that we cant express what you're > talking about. If we weren't using mailing lists it would be easier to search > for "protocol self-conformance" on

Re: [swift-users] Swift and Xcode along with Playgrounds is full of bugs

2016-09-14 Thread Jens Alfke via swift-users
> On Sep 14, 2016, at 7:50 AM, Patrice Kouame via swift-users > wrote: > > 1. File those bugs and issues in radar, but lower your expectations a bit. > That’s how I usually vent my frustrations. Just imagine the thousands they > have to sift through... > 2. Be

Re: [swift-users] Method of same name is shadowing a property in Swift 3

2016-09-13 Thread Jens Alfke via swift-users
> On Sep 13, 2016, at 3:13 PM, Hooman Mehr wrote: > > I guess the reason this is happening is some attempt at backward > compatibility, but this is clearly causing a serious bug. Have you reported > it? No; I’m not a Swift expert, and am not following the 3.0 transition

[swift-users] Method of same name is shadowing a property in Swift 3

2016-09-13 Thread Jens Alfke via swift-users
One of my co-workers just noticed a problem with the (bridged) API of our Objective-C framework, when used from Swift 3 (but not earlier). We have a class CBLQueryRow that includes the following: @property (readonly) id key; - (nullable id) keyAtIndex: (NSUInteger)index; In

Re: [swift-users] Provide native Decimal data type

2016-09-12 Thread Jens Alfke via swift-users
> On Sep 12, 2016, at 10:10 AM, Teej . via swift-users > wrote: > > …in spite of the CPU’s quirks in handling floating point numbers in a > maddening inaccurate manner. Well, in the CPU’s defense, it’s only inaccurate because the puny humans insist on dividing

Re: [swift-users] Swift and Xcode along with Playgrounds is full of bugs

2016-09-13 Thread Jens Alfke via swift-users
> On Sep 13, 2016, at 6:27 PM, Shyamal Chandra wrote: > > Do you really think that is a viable option again? No, you’re right. Reporting bugs is clearly the least viable option, except for all the other options* (like arguing on mailing lists.) —Jens * With apologies to

Re: [swift-users] Method of same name is shadowing a property in Swift 3

2016-09-13 Thread Jens Alfke via swift-users
> On Sep 13, 2016, at 4:47 PM, Zhao Xin wrote: > > You said your issue only existed in Swift 3. However, you issue still exists > in Xcode 7.3.1, which uses Swift 2.2. I tested your playground code. Interesting. I think the difference is that prior to Swift 3, the original

Re: [swift-users] Swift and Xcode along with Playgrounds is full of bugs

2016-09-13 Thread Jens Alfke via swift-users
> On Sep 13, 2016, at 5:34 PM, Shyamal Chandra via swift-users > wrote: > > Here is a forum question that I posted a while back. The latest post says to > file a bug under the bug report. I have had mixed success with the bug > reporter tool from Apple; most of the

Re: [swift-users] Swift and Xcode along with Playgrounds is full of bugs

2016-09-12 Thread Jens Alfke via swift-users
> On Sep 12, 2016, at 3:03 PM, Shyamal Chandra via swift-users > wrote: > > Instead of moving onto Swift 3, 4, and 5 (with different syntax), why don't > you standardize the library and language operations and functions for the > different package and frameworks

Re: [swift-users] NSInvocation equivalent

2016-10-05 Thread Jens Alfke via swift-users
> On Oct 5, 2016, at 1:50 PM, Bob Miller via swift-users > wrote: > > This is a Swift3 newbie question that I’ve not found a solution to. Has > there been any consensus reached on an equivalent approach to the AppKit > class NSInvocation ? Here’s a simple objC

Re: [swift-users] NSInvocation equivalent

2016-10-05 Thread Jens Alfke via swift-users
> On Oct 5, 2016, at 4:24 PM, Jordan Rose wrote: > > However, there are usually better answers than NSInvocation (both in Swift > and Objective-C). What are you actually trying to do? Yeah, the only time I’d recommend using NSInvocation is when implementing a proxy

Re: [swift-users] Different behaviour when casting Float and Double to NSNumber

2016-10-05 Thread Jens Alfke via swift-users
> On Oct 5, 2016, at 2:30 AM, Lars-Jørgen Kristiansen via swift-users > wrote: > > // Also noticed this: > "\(floatNumber)" // "1e+07" > "\(doubleNumer)" // "1000" Numbers around 10 million are too large to be represented exactly by a 32-bit float — the mantissa is

Re: [swift-users] Different behaviour when casting Float and Double to NSNumber

2016-10-05 Thread Jens Alfke via swift-users
> On Oct 5, 2016, at 11:36 AM, Lars-Jørgen Kristiansen > wrote: > > And thought that i would receive a overflows when stored into 'Float' > error...? It doesn’t overflow. (I think the maximum value of Float is around 1e37.) There just isn’t enough precision to represent

Re: [swift-users] How to bridge between CoreFoundation and SwiftFoundation on Linux?

2016-09-21 Thread Jens Alfke via swift-users
> On Sep 20, 2016, at 9:38 PM, Bouke Haarsma via swift-users > wrote: > > When working with CoreFoundation objects (e.g. CFReadStream, CFWriteStream) > it isn't immediately obvious to me how to bridge them to SwiftFoundation > counterparts (InputStream / OutputStream).

Re: [swift-users] Implicitly type conversion ?

2016-08-18 Thread Jens Alfke via swift-users
> On Aug 18, 2016, at 12:18 PM, adelzhang via swift-users > wrote: > > Why swift don't warn the type mismatch? I am woking on Xcode Version 7.3.1. It’s an implicit type-cast. Any type `X` can always be implicitly converted to type `X?` (i.e. `Optional`).

[swift-users] Ambiguity passing `Any?` to generic constructor

2016-08-29 Thread Jens Alfke via swift-users
I’m making a little utility struct that needs to be able to wrap an arbitrary value, which may be an optional, and be able to tell whether it’s nil. So I declared it like this (I’ve removed the interesting/useful parts of the code leaving just the constructors and one property): public struct

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

2016-08-24 Thread Jens Alfke via swift-users
> On Aug 24, 2016, at 7:07 AM, Jean-Denis Muys via swift-users > wrote: > > However I was wondering if it was possible (preferable?) to do it in a more > “functional” style. Apple’s Foundation framework has Array.arrayByAddingObject (but not ByRemoving). However, this

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

2016-10-03 Thread Jens Alfke via swift-users
> On Oct 2, 2016, at 5:14 PM, Mike Ferenduros via swift-users > wrote: > > Personally I would be surprised if the malloc caused an actual measurable > performance hit tbh. It won’t be noticeable against a call to SecRandom, as noted, but there are other circumstances

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Jens Alfke via swift-users
> On Oct 14, 2016, at 5:16 PM, zh ao via swift-users > wrote: > > In your opinion, `baseURL` is a factor more important than `path`. I can not > unaccept your answer. But I want to know why? Is there a standard on URL > equality? I think this is just a weirdness of

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Jens Alfke via swift-users
> On Oct 14, 2016, at 10:20 PM, Keith Smiley wrote: > > FWIW we've overridden URL's equality function in order to get a "more > realistic" > result. We lowercase everything and compare the scheme, host, port, and query, I hope you don’t lowercase everything — the scheme and

[swift-users] NSJSONSerialization barfs writing a Dictionary parsed from JSON: "Invalid type in JSON write (_SwiftValue)"

2016-11-18 Thread Jens Alfke via swift-users
A developer using the framework I work on just reported an exception which is triggered by NSJSONSerialization (see backtrace below.) Basically an NSDictionary gets parsed from

Re: [swift-users] How to merge two dictionaries?

2016-11-11 Thread Jens Alfke via swift-users
> On Nov 11, 2016, at 12:14 AM, Ray Fix via swift-users > wrote: > > The reason I don’t think it is provided is because it is difficult to know > what to do when keys collide. When you add a single entry to a dictionary with []=, it simply replaces any existing value.

Re: [swift-users] Localization in Swift.

2016-11-01 Thread Jens Alfke via swift-users
> On Nov 1, 2016, at 1:53 AM, Zhao Xin via swift-users > wrote: > > I began to realize that` \(count)` was not dealed well in localization. The > compiler calculated the full string then looking for the translation, instead > of looking for the translation first.

  1   2   >