Re: [swift-users] Type alias with a "where" clause specifying required associated type

2017-09-05 Thread Slava Pestov via swift-users
It’s just placeholder syntax for ‘a value whose type is given by a generic 
parameter in the following signature’.

Slava

> On Sep 5, 2017, at 4:44 AM, Rudolf Adamkovič  wrote:
> 
> I see. TBH, I don’t understand why it says “Any” in the "generalized 
> existentials” but everything else is clear. 
> 
> Thank you Slava!
> 
> R+
> 
>> On 5 Sep 2017, at 01:52, Slava Pestov > > wrote:
>> 
>> Hi Rudolf,
>> 
>> What you are describing is not possible right now. The protocol PointType 
>> cannot be used as a type at all, because it has an associated type 
>> requirement. Also it is not clear what a ‘where’ clause attached to a type 
>> alias would mean.
>> 
>> There has been some discussion of ‘generalized existentials’ on the 
>> evolution list. So eventually, you might be able to say something like this:
>> 
>> typealias Point = Any
>> 
>> Slava
>> 
>>> On Sep 4, 2017, at 6:12 PM, Rudolf Adamkovič via swift-users 
>>> > wrote:
>>> 
>>> I have the following ProceduralDrawing type:
>>> 
>>> public struct ProceduralDrawing where Point.Float 
>>> == Float {
>>> // ... code that used Float and Point ...
>>> }
>>> 
>>> public protocol PointType {
>>> associatedtype Float: FloatingPoint
>>> var x: Float { get }
>>> var y: Float { get }
>>> }
>>> 
>>> I would like to avoid adding Point as a generic parameter but the following 
>>> doesn’t work:
>>> 
>>> public struct ProceduralDrawing {
>>> // ERROR: 'where' clause cannot be attached to a non-generic declaration
>>> typealias Point = PointType where Point.Float == Float
>>> // ... code that uses Float and Point ...
>>> }
>>> 
>>> Is there a way to do this? If not, why?
>>> 
>>> Thanks!
>>> 
>>> R+
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
>> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] XML parsing on Linux, with Swift 3.1

2017-09-05 Thread Taylor Swift via swift-users
The CI builds on Swift 4, i believe it should work fine on master too but
it’s not tested there. Also I don’t think snake_case is C++ convention,
i’ve seen both. I use snake_case because camelCase looks too similar to
UpperCamelCase which is reserved for type names.

On Tue, Sep 5, 2017 at 3:43 AM, Georgios Moschovitis <
george.moschovi...@icloud.com> wrote:

> >
> > Foundation (NS)XML parsing is a little buggy and incomplete, check out
> github.com/kelvin13/swiftxml for a pure swift implementation
>
> Your implementation seems to be Swift4 only?
>
> -g.
>
> PS: Also, I am a bit put-off by some C/C++ coding conventions (e.g.
> snake_case)
>
> >
> >> On Sep 5, 2017, at 1:01 AM, Georgios Moschovitis via swift-users <
> swift-users@swift.org> wrote:
> >>
> >> Hi,
> >>
> >> I would like to parse an RSS feed using Swift 3.1 on Linux.
> >> I tried to use Foundations’s XML but I only managed to get segmentation
> faults.
> >> Is this supposed to work on Linux? I have only seen examples on iOS.
> >>
> >> Apart from that a quick search didn’t reveal any useful XML parsing
> library compatible with Linux.
> >>
> >> Any suggestions?
> >>
> >> -g.
> >> ___
> >> swift-users mailing list
> >> swift-users@swift.org
> >> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] XML parsing on Linux, with Swift 3.1

2017-09-05 Thread Saagar Jha via swift-users

Saagar Jha

> On Sep 5, 2017, at 01:19, Georgios Moschovitis via swift-users 
>  wrote:
> 
> Indeed it works, but I don’t get it.
> What’s the difference?
> 
> -g.
> 
> PS: Btw, my original code was giving `seg-fault: 11` even on macOS.
> 
>> On 5 Sep 2017, at 10:53 AM, CK TUNG via swift-users > > wrote:
>> 
>> This revised code, as below, works without segmentation fault
>> 
>> import Foundation
>> 
>> class ParserDelegate: NSObject, XMLParserDelegate {
>> 
>> func startParsing(_ xml:String) {
>> let data = xml.data(using: .utf8)!
>> let xmlParser = XMLParser(data: data)
>> xmlParser.delegate = self
>> xmlParser.parse()
>> }
>> 
>> func parserDidStartDocument(_ parser: XMLParser) {
>> print("Starting document")
>> }
>> 
>> func parser(_ parser: XMLParser, didStartElement elementName: String, 
>> namespaceURI: String?, qualifiedName qName: String?, attributes 
>> attributeDict: [String : String]) {
>> print("*** \(elementName)")
>> }
>> }
>> 
>> let xml = "George"
>> let test = ParserDelegate()
>> test.startParsing(xml)
>> 
>> On Sep 05, 2017, at 02:24 PM, Georgios Moschovitis via swift-users 
>> > wrote:
>> 
>>> As an example, this SegFaults:
>>> 
>>> import Foundation
>>> 
>>> class ParserDelegate: NSObject, XMLParserDelegate {
>>> func parserDidStartDocument(_ parser: XMLParser) {
>>> print("Starting document")
>>> }
>>> 
>>> func parser(_ parser: XMLParser, didStartElement elementName: String, 
>>> namespaceURI: String?, qualifiedName qName: String?, attributes 
>>> attributeDict: [String : String] = [:]) {
>>> print("*** \(elementName)")
>>> }
>>> }
>>> 
>>> let xml = "George"
>>> let data = xml.data(using: .utf8)!
>>> let xmlParser = XMLParser(data: data)
>>> xmlParser.delegate = ParserDelegate()

XMLParser’s delegate is unowned, so it’s being deallocated when you exit the 
current scope. Hold on to it with a strong reference:

let delegate = ParserDelegate()
xmlParser.delegate = delegate

>>> xmlParser.parse()
>>> 
 On 5 Sep 2017, at 9:01 AM, Georgios Moschovitis 
 > 
 wrote:
 
 Hi,
 
 I would like to parse an RSS feed using Swift 3.1 on Linux.
 I tried to use Foundations’s XML but I only managed to get segmentation 
 faults.
 Is this supposed to work on Linux? I have only seen examples on iOS.
 
 Apart from that a quick search didn’t reveal any useful XML parsing 
 library compatible with Linux.
 
 Any suggestions?
 
 -g.
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Foundation bug or indended?

2017-09-05 Thread Jordan Rose via swift-users
It's semi-intended. When the compiler imports (NS)Operation into Swift, it uses 
the Swift naming convention…but it also declares a property with the old name, 
'executing', in order to give better error messages if someone tries to use the 
Objective-C name. That's what's colliding with your private 'executing' 
property.

We should improve this experience on the compiler side, either by having a 
'nonoverride' attribute or similar, or just by noting that you wouldn't try to 
override something with a private property not declared 'override' in the first 
place. But since the workaround is so simple it hasn't been a priority.

Sorry for the trouble,
Jordan


> On Sep 4, 2017, at 05:01, Adrian Zubarev via swift-users 
>  wrote:
> 
> Hi there,
> 
> before filing a new issue I would like to ask if this is intended behaviour 
> or a bug:
> 
> The Foundation class Operation which has it’s roots in Objective-C has a few 
> readonly properties like the following one:
> 
> @available(iOS 2.0, *)
> open class Operation : NSObject {
> ...
> open var isExecuting: Bool { get }
> ...
> }
> On the other hand the Objective-C header looks like this:
> 
> NS_CLASS_AVAILABLE(10_5, 2_0)
> @interface NSOperation : NSObject {
> ...
> @property (readonly, getter=isExecuting) BOOL executing;
> ...
> @end
> Now I want to create a custom subclass of Operation and override isExecuting, 
> everything works fine until I try to create a private stored property named 
> executing:
> 
> final class TransitionOperation : Operation {
> // error: cannot override with a stored property 'executing'
> private var executing = false
> 
> override var isExecuting: Bool {
> ...
> }
> }
> I’m a little bit confused here:
> 
> Is this intended behaviour or a bug?
> The Foundation implemented in Swift is not used for iOS deployment, instead 
> the Obj-C one is used right?
> 
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Is it possible to install Swift 4 on El Capitan with Xcode 8?

2017-09-05 Thread Jordan Rose via swift-users


> On Sep 4, 2017, at 20:06, Mr Bee via swift-users  
> wrote:
> 
> 
> 2017-09-05 3:47 GMT+07:00 Fritz Anderson via swift-users 
> >:
> 
> In your position, I’d go to the Downloads part of Swift.org 
>  and fetch the latest build of the Swift 4 toolchain for 
> Mac. (It’s still in flux, but it’ll probably be promoted to latest/stable 
> this month.)
> 
> Install the toolchain. This adds a Toolchains tab to the Components section 
> of the Preferences window. Select Swift 4.0 Snapshot.
> 
> Ok, I'll try it out once Swift 4 is officially released. So, that means Swift 
> 4 will work on Xcode 8, I suppose.

Unfortunately this will only work for pure Swift apps; the support libraries 
for Foundation, UIKit, etc are built against the Xcode 9 SDKs and will not work 
with Xcode 8. I'm afraid you're stuck with Swift 3 if you want to make Cocoa or 
Cocoa Touch apps, at least officially.

Jordan

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] No Generic Decoders?

2017-09-05 Thread Itai Ferber via swift-users

Hi Jon,

This was a conscious choice in the API design, for three main reasons:

1. There is a big difference between the API surface exposed at the 
top-level for encoding and decoding and the middle levels. A method like 
`decode(_ type: T, from data: Data)` is really only appropriate at the 
top level of a given decoder, and likewise, exposing individual encoding 
and decoding containers is really only appropriate at the middle levels. 
We intentionally left these APIs separate to avoid exposing methods in 
inappropriate places (so the `Decoder` protocol doesn’t expose the 
top-level method)
2. Among top-level interfaces, there is variability in what different 
decoders can expose. `JSONDecoder`, for instance, exposes only a 
`decode(_ type: T, from data: Data)` method, while `PropertyListDecoder` 
has another method which also exposes the 
`PropertyListSerialization.PropertyListFormat` of the decoded data, 
which would not be appropriate to expose on `JSONDecoder`. In the 
future, these two might diverge further if we decide to specify the API 
even further, but more importantly, other decoders might find a 
different top-level API to be more appropriate than these methods (e.g. 
a format which only allows top-level dictionaries might want to expose 
only a decode method which accepts a dictionary type)
3. Given that, we found that it would be too confusing to expose 
top-level encoders and decoders as a separate type from 
`Encoder`/`Decoder` for not much benefit


If you find the concept useful for your own work and are willing to 
sacrifice some portability, you can always define a protocol with the 
interface appropriate for your project and have these decoders conform 
to that protocol.


— Itai

On 2 Sep 2017, at 18:47, Jon Shier via swift-users wrote:


Swift Users:
	I’ve been exploring the creation of Decodable response serializers 
for Alamofire. However, there doesn’t actually seem to be any way to 
express the notion of a generic decoder. The Decoder protocol itself 
doesn’t require a `decode(type:from:)` method, and neither 
JSONDecoder or PropertyListDecoder conform to Decoder in the first 
place. Were these facts conscious choices or oversights? It certainly 
seems very useful to be able to treat decoders generically.




Jon Shier
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Type alias with a "where" clause specifying required associated type

2017-09-05 Thread Rudolf Adamkovič via swift-users
I see. TBH, I don’t understand why it says “Any” in the "generalized 
existentials” but everything else is clear. 

Thank you Slava!

R+

> On 5 Sep 2017, at 01:52, Slava Pestov  wrote:
> 
> Hi Rudolf,
> 
> What you are describing is not possible right now. The protocol PointType 
> cannot be used as a type at all, because it has an associated type 
> requirement. Also it is not clear what a ‘where’ clause attached to a type 
> alias would mean.
> 
> There has been some discussion of ‘generalized existentials’ on the evolution 
> list. So eventually, you might be able to say something like this:
> 
> typealias Point = Any
> 
> Slava
> 
>> On Sep 4, 2017, at 6:12 PM, Rudolf Adamkovič via swift-users 
>> > wrote:
>> 
>> I have the following ProceduralDrawing type:
>> 
>> public struct ProceduralDrawing where Point.Float 
>> == Float {
>> // ... code that used Float and Point ...
>> }
>> 
>> public protocol PointType {
>> associatedtype Float: FloatingPoint
>> var x: Float { get }
>> var y: Float { get }
>> }
>> 
>> I would like to avoid adding Point as a generic parameter but the following 
>> doesn’t work:
>> 
>> public struct ProceduralDrawing {
>> // ERROR: 'where' clause cannot be attached to a non-generic declaration
>> typealias Point = PointType where Point.Float == Float
>> // ... code that uses Float and Point ...
>> }
>> 
>> Is there a way to do this? If not, why?
>> 
>> Thanks!
>> 
>> R+
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] XML parsing on Linux, with Swift 3.1

2017-09-05 Thread Georgios Moschovitis via swift-users
Indeed it works, but I don’t get it.
What’s the difference?

-g.

PS: Btw, my original code was giving `seg-fault: 11` even on macOS.

> On 5 Sep 2017, at 10:53 AM, CK TUNG via swift-users  
> wrote:
> 
> This revised code, as below, works without segmentation fault
> 
> import Foundation
> 
> class ParserDelegate: NSObject, XMLParserDelegate {
> 
> func startParsing(_ xml:String) {
> let data = xml.data(using: .utf8)!
> let xmlParser = XMLParser(data: data)
> xmlParser.delegate = self
> xmlParser.parse()
> }
> 
> func parserDidStartDocument(_ parser: XMLParser) {
> print("Starting document")
> }
> 
> func parser(_ parser: XMLParser, didStartElement elementName: String, 
> namespaceURI: String?, qualifiedName qName: String?, attributes 
> attributeDict: [String : String]) {
> print("*** \(elementName)")
> }
> }
> 
> let xml = "George"
> let test = ParserDelegate()
> test.startParsing(xml)
> 
> On Sep 05, 2017, at 02:24 PM, Georgios Moschovitis via swift-users 
> > wrote:
> 
>> As an example, this SegFaults:
>> 
>> import Foundation
>> 
>> class ParserDelegate: NSObject, XMLParserDelegate {
>> func parserDidStartDocument(_ parser: XMLParser) {
>> print("Starting document")
>> }
>> 
>> func parser(_ parser: XMLParser, didStartElement elementName: String, 
>> namespaceURI: String?, qualifiedName qName: String?, attributes 
>> attributeDict: [String : String] = [:]) {
>> print("*** \(elementName)")
>> }
>> }
>> 
>> let xml = "George"
>> let data = xml.data(using: .utf8)!
>> let xmlParser = XMLParser(data: data)
>> xmlParser.delegate = ParserDelegate()
>> xmlParser.parse()
>> 
>>> On 5 Sep 2017, at 9:01 AM, Georgios Moschovitis 
>>> > 
>>> wrote:
>>> 
>>> Hi,
>>> 
>>> I would like to parse an RSS feed using Swift 3.1 on Linux.
>>> I tried to use Foundations’s XML but I only managed to get segmentation 
>>> faults.
>>> Is this supposed to work on Linux? I have only seen examples on iOS.
>>> 
>>> Apart from that a quick search didn’t reveal any useful XML parsing library 
>>> compatible with Linux.
>>> 
>>> Any suggestions?
>>> 
>>> -g.
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] XML parsing on Linux, with Swift 3.1

2017-09-05 Thread CK TUNG via swift-users

This revised code, as below, works without segmentation fault

import Foundation

class ParserDelegate: NSObject, XMLParserDelegate {
    
    func startParsing(_ xml:String) {
        let data = xml.data(using: .utf8)!
        let xmlParser = XMLParser(data: data)
        xmlParser.delegate = self
        xmlParser.parse()
    }
    
    func parserDidStartDocument(_ parser: XMLParser) {
        print("Starting document")
    }
    
    func parser(_ parser: XMLParser, didStartElement elementName: String, 
namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: 
[String : String]) {
        print("*** \(elementName)")
    }
}

let xml = "George"
let test = ParserDelegate()
test.startParsing(xml)

On Sep 05, 2017, at 02:24 PM, Georgios Moschovitis via swift-users 
 wrote:

As an example, this SegFaults:

import Foundation

class ParserDelegate: NSObject, XMLParserDelegate {
func parserDidStartDocument(_ parser: XMLParser) {
print("Starting document")
}

func parser(_ parser: XMLParser, didStartElement elementName: String, 
namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: 
[String : String] = [:]) {
print("*** \(elementName)")
}
}

let xml = "George"
let data = xml.data(using: .utf8)!
let xmlParser = XMLParser(data: data)
xmlParser.delegate = ParserDelegate()
xmlParser.parse()

On 5 Sep 2017, at 9:01 AM, Georgios Moschovitis  
wrote:

Hi,

I would like to parse an RSS feed using Swift 3.1 on Linux.
I tried to use Foundations’s XML but I only managed to get segmentation faults.
Is this supposed to work on Linux? I have only seen examples on iOS.

Apart from that a quick search didn’t reveal any useful XML parsing library 
compatible with Linux.

Any suggestions?

-g.

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] XML parsing on Linux, with Swift 3.1

2017-09-05 Thread Georgios Moschovitis via swift-users
As an example, this SegFaults:

import Foundation

class ParserDelegate: NSObject, XMLParserDelegate {
func parserDidStartDocument(_ parser: XMLParser) {
print("Starting document")
}

func parser(_ parser: XMLParser, didStartElement elementName: String, 
namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: 
[String : String] = [:]) {
print("*** \(elementName)")
}
}

let xml = "George"
let data = xml.data(using: .utf8)!
let xmlParser = XMLParser(data: data)
xmlParser.delegate = ParserDelegate()
xmlParser.parse()

> On 5 Sep 2017, at 9:01 AM, Georgios Moschovitis 
>  wrote:
> 
> Hi,
> 
> I would like to parse an RSS feed using Swift 3.1 on Linux.
> I tried to use Foundations’s XML but I only managed to get segmentation 
> faults. 
> Is this supposed to work on Linux? I have only seen examples on iOS.
> 
> Apart from that a quick search didn’t reveal any useful XML parsing library 
> compatible with Linux.
> 
> Any suggestions?
> 
> -g.

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] XML parsing on Linux, with Swift 3.1

2017-09-05 Thread Georgios Moschovitis via swift-users
Hi,

I would like to parse an RSS feed using Swift 3.1 on Linux.
I tried to use Foundations’s XML but I only managed to get segmentation faults. 
Is this supposed to work on Linux? I have only seen examples on iOS.

Apart from that a quick search didn’t reveal any useful XML parsing library 
compatible with Linux.

Any suggestions?

-g.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users