Re: [swift-users] Data races with copy-on-write

2017-12-05 Thread Jens Alfke via swift-users
> On Dec 5, 2017, at 6:24 AM, Michel Fortin via swift-users > wrote: > > The array *storage* is copy on write. The array variable (which essentially > contains a pointer to the storage) is not copy on write. If you refer to the > same array variable from multiple

Re: [swift-users] Was the String contains(_:) method changed in Swift 4?

2017-11-08 Thread Jens Alfke via swift-users
> On Nov 8, 2017, at 2:24 AM, Geordie Jay via swift-users > wrote: > > Would you be able to clarify where the line is between “tricky” and “not > tricky” and if possible the reasoning behind making this distinction? Because > as an outsider this seems to me like an

[swift-users] Optimal String conversion to/from UTF-8 w/o null-termination?

2017-11-03 Thread Jens Alfke via swift-users
I’m working with a C API that represents strings as UTF-8 data tagged with a length but **without a trailing NUL byte**. In other words, its string type is basically a tuple {const char*, size_t}. I need to convert this representation to and from Swift 4 strings. This needs to be efficient,

Re: [swift-users] How do I turn an array into a bitmap image?

2017-03-15 Thread Jens Alfke via swift-users
> On Mar 15, 2017, at 11:07 AM, Nevin Brackett-Rozinsky via swift-users > wrote: > > Ideally I’d like to create the bitmap image without having to allocate a > second buffer. The sole purpose of the Float array is for creating this > image, so I’d like to directly use

Re: [swift-users] How do I turn an array into a bitmap image?

2017-03-15 Thread Jens Alfke via swift-users
> On Mar 15, 2017, at 9:56 AM, Nevin Brackett-Rozinsky via swift-users > wrote: > > For one of my programs, I need to take an array of Floats and use the > underlying bytes as the RGBA data for a bitmap image. In particular, the 32 > bits of each Float must be treated

Re: [swift-users] It seems like we really need an #include preprocessor directive?

2017-03-11 Thread Jens Alfke via swift-users
> On Mar 11, 2017, at 10:21 PM, David Sweeris wrote: > >> (I see absolutely nothing wrong with inheritance, and it solves exactly this >> sort of problem. Yes, structs can’t inherit, but they can contain a common >> struct as a member, which is quite similar and addresses

Re: [swift-users] It seems like we really need an #include preprocessor directive?

2017-03-11 Thread Jens Alfke via swift-users
> On Mar 11, 2017, at 12:12 PM, Edward Connell via swift-users > wrote: > > It seems that an easy workaround would be an #include statement. > The boiler plate can be put in a separate file and included wherever it's > needed. IMHO this seems like a surefire ‘design

Re: [swift-users] What is the intended response to Array change notification for dependents?

2017-03-07 Thread Jens Alfke via swift-users
> On Mar 7, 2017, at 9:28 AM, Michael Gardner via swift-users > wrote: > > The general approach would be to run a diff between your old and new arrays. > Something like https://github.com/jflinter/Dwifft > could help, though I

Re: [swift-users] What is the intended response to Array change notification for dependents?

2017-03-07 Thread Jens Alfke via swift-users
> On Mar 7, 2017, at 8:45 AM, Edward Connell wrote: > > My project is on Linux, so pure Swift. > So you don't think this is an issue of intentional library design, but a > recognized problem that hasn't been addressed yet? Exactly. —Jens

Re: [swift-users] What is the intended response to Array change notification for dependents?

2017-03-07 Thread Jens Alfke via swift-users
> On Mar 7, 2017, at 8:08 AM, Edward Connell wrote: > > My question is, what was their design intent? Rebuild all dependents every > time? Swift started out by piggybacking on facilities provided by Foundation. Over time it’s becoming self-sufficient, but it’s a work in

Re: [swift-users] What is the intended response to Array change notification for dependents?

2017-03-07 Thread Jens Alfke via swift-users
On Mar 6, 2017, at 11:36 PM, Rien via swift-users wrote: > On 07 Mar 2017, at 03:56, Edward Connell via swift-users > > wrote: > > I would like to have an Array implementation where I get more information > than just

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] 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

[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] 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

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] 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: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] 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] 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] Using C++ libraries in Swift projects?

2017-01-13 Thread Jens Alfke via swift-users
> On Jan 13, 2017, at 9:37 AM, Ethin Probst wrote: > > So you don't know how I could directly port this to Swift--or make an > indirect port? It’s not clear to me what you’re asking. Do you just want to write to a log file from Swift? Or do you want to specifically

Re: [swift-users] Using C++ libraries in Swift projects?

2017-01-13 Thread Jens Alfke via swift-users
> On Jan 13, 2017, at 8:18 AM, Ethin Probst via swift-users > wrote: > > I was wondering how I could go about using the Boost library project > (among others) in swift? No, it’s generally not feasible to use C++ libraries from any other language. The main reasons are

Re: [swift-users] module (de)-initialization

2016-12-20 Thread Jens Alfke via swift-users
Also, AFAIK there is no mechanism in Swift (yet) to load or unload a module at runtime, so a module load occurs when the program starts up, and an unload occurs when the program exits. So if your module really needs to do something to clean up, it could call the (C standard) function atexit()

[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] Autoreleasepool for Ubuntu

2016-11-02 Thread Jens Alfke via swift-users
> On Nov 2, 2016, at 1:42 PM, Bernardo Breder via swift-users > wrote: > > The algorithm that i send is a example of server code and this code will > execute in a ubuntu environment. When i install in the ubuntu, the swiftc > show me that the autoreleasepool is "use of

Re: [swift-users] Localization in Swift.

2016-11-02 Thread Jens Alfke via swift-users
> On Nov 2, 2016, at 12:50 PM, Dave Abrahams via swift-users > wrote: > > In my opinion, we can and must do much better for Swift. If there's > something about “%” formatting that you particularly value, I'd like to > know about it, so I can make sure it's accomodated.

Re: [swift-users] Localization in Swift.

2016-11-02 Thread Jens Alfke via swift-users
> On Nov 2, 2016, at 11:23 AM, Marco S Hyman via swift-users > wrote: > > On Nov 1, 2016, at 11:42 PM, Zhao Xin via swift-users > wrote: >> >> I have already give a workable implementation above. > > Your implementation assume \(x) is always

Re: [swift-users] Localization in Swift.

2016-11-02 Thread Jens Alfke via swift-users
> On Nov 1, 2016, at 10:56 PM, Zhao Xin wrote: > > I am not talking to eliminate "%" style function. I am talking to add more > compatibility to `NSLocalizedString` with `\(foo)` style. I don’t think the ExpressibleByStringInterpolation protocol provides enough information

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

2016-11-02 Thread Jens Alfke via swift-users
> On Nov 1, 2016, at 9:50 PM, Shyamal Chandra via swift-users > wrote: > > Why don't you make the Playgrounds open source so I can investigate? I’ve been hearing people tell Apple “why don’t you make ___ open source” for as long as the term ‘open source’ has existed.

Re: [swift-users] Localization in Swift.

2016-11-01 Thread Jens Alfke via swift-users
> On Nov 1, 2016, at 10:40 PM, Zhao Xin wrote: > > For example, if I want show the user that I have to ask him to give me > permission of a folder, the `url.path` has no need to translate. We’re getting off-topic, but paths do need to be translated, at least on Mac systems.

Re: [swift-users] Localization in Swift.

2016-11-01 Thread Jens Alfke via swift-users
> On Nov 1, 2016, at 7:52 PM, Zhao Xin wrote: > > The second should be > > let says = > String.localizedStringWithFormat(NSLocalizedString("​blabla%​@​blabla", > comment: "​blabla"), ​String(​count​)​) That’s not quite right, because the conversion of `count` to a string

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.

Re: [swift-users] Build Android GUI apps with Swift 3.0 via a framework/library

2016-10-17 Thread Jens Alfke via swift-users
> On Oct 16, 2016, at 1:35 PM, Tony Constantinides via swift-users > wrote: > > Kotlin does not run on iOS without some custom VM (Robot VM) which would kill > performance. If you mean RoboVM, it claims to use ahead-of-time compilation of Java to native code, so there

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

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

[swift-users] Data reflection metadata?

2016-10-13 Thread Jens Alfke via swift-users
In a recent-ish post on swift-evolution , Chris Lattner mentioned: > …the extensive work on data reflection metadata that was put into Swift 3. > It is key to enabling the Xcode 8 memory visualization /

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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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

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

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

[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

[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

[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] 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] 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`).

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] 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] 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] 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] 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] 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] 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] 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 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] 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] [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] 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] 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
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] 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] 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] 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] 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] 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] 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] @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] 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] 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] 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] == 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] ?? 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

[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] 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] 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] 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] 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 +

[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

  1   2   >