Re: [swift-users] Canonical way to cast C structs

2016-09-20 Thread Bouke Haarsma via swift-users
The Socket API Helper 
(https://swift.org/migration-guide/se-0107-migrate.html#socket-api-helper) 
expect a property ss_len on sockaddr_storage. This property is not available on 
Linux, so the wrappers won’t work without any additional knowledge of the 
internet protocol family. Any ideas on how these wrappers can be fixed for 
Linux?

func withSockAddr(_ body: (_ sa: UnsafePointer, _ 
saLen: socklen_t) throws -> ReturnType) rethrows -> ReturnType {
// We need to create a mutable copy of `self` so that we can pass it to 
`withUnsafePointer(to:_:)`.
var ss = self
return try withUnsafePointer(to: ) {
try $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
try body($0, socklen_t(self.ss_len))
   ^^^
}
}
}

Replacing self.ss_len with MemoryLayout.size would not be correct, as it 
should not be sockaddr's / sockaddr_storage’s size, but sockaddr_in[6]’s size.


> On 17 Sep 2016, at 07:28, Bouke Haarsma  wrote:
> 
> Thanks for your replies. After looking at the helper code you mentioned, it 
> appears that the code in each call will create a mutable copy of a 
> sockaddr_storage. That mutable copy is than rebound/casted to whatever type 
> requested. While it probably would be safer to use, it introduces extra 
> copying overhead as well. The code that I have now (thanks to Quinn’s helper 
> methods):
> 
> let address: sockaddr_storage
> let family = CFDataGetBytePtr(addressData!).withMemoryRebound(to: 
> sockaddr.self, capacity: 1) {
> return $0.pointee.sa_family
> }
> switch family {
> case sa_family_t(AF_INET):
> (_, address) = sockaddr_storage.fromSockAddr { (sin: inout sockaddr_in) in
> sin.sin_family = sa_family_t(AF_INET)
> sin.sin_addr = CFDataGetBytePtr(addressData!).withMemoryRebound(to: 
> sockaddr_in.self, capacity: 1) {
> $0.pointee.sin_addr
> }
> }
> case sa_family_t(AF_INET6):
> (_, address) = sockaddr_storage.fromSockAddr { (sin: inout sockaddr_in6) 
> in
> sin.sin6_family = sa_family_t(AF_INET6)
> sin.sin6_addr = CFDataGetBytePtr(addressData!).withMemoryRebound(to: 
> sockaddr_in6.self, capacity: 1) {
> $0.pointee.sin6_addr
> }
> }
> default:
> return
> }
> 
> Is this as Swifty as it can get? Is there a way to make it less verbose? The 
> problem I see with this code is that the network protocols are still 
> special-cased. 
> 
> The addressData CFData object is described like this:
> 
>> A CFData object holding the contents of a struct sockaddr appropriate for 
>> the protocol family of s (struct sockaddr_in or struct sockaddr_in6, for 
>> example), identifying the remote address to which s is connected. This value 
>> is NULL except for kCFSocketAcceptCallBack and kCFSocketDataCallBack 
>> callbacks.
> 
> 
> Thanks,
> Bouke
> 
> 
>> On 14 sep. 2016, at 08:34, Andrew Trick > > wrote:
>> 
>>> 
>>> On Sep 12, 2016, at 12:39 PM, Bouke Haarsma via swift-users 
>>> > wrote:
>>> 
>>> Sorry for all the pings, but it appears that the code below doesn’t work 
>>> after all;
>>> 
 fatal error: can't unsafeBitCast between types of different sizes
>>> 
>>> So the question remains on how to perform the casts using Swift?
>>> 
>>> —
>>> Bouke
>> 
>> Hi Bouke,
>> 
>> Please see this migration guide:
>> https://swift.org/migration-guide/se-0107-migrate.html 
>> 
>> 
>> It explains a few things that are not self-explanatory and includes some 
>> helper code for dealing with the socket API.
>> 
>> Given how your code is structured, I would start with a raw pointer, then 
>> replace all the ‘withMemoryRebound’ calls to ‘bindMemory’, and you should be 
>> fine:
>> 
>> var rawSockAddr = UnsafeRawPointer(CFDataGetBytePtr(data))
>> 
>> switch …
>> case …:
>>   let ipv4 = rawSockAddr.bindMemory(to: sockaddr_in.self, capacity: 1)
>> 
>> You might also be able to avoid CFData and use Swift’s Data directly, but 
>> any Swifty API you use will encourage you to restructure your code so that 
>> pointer access is confined to a closure, like Data.withUnsafeBytes, or 
>> UnsafePointer.withMemoryRebound(to:capacity:). You should never return the 
>> pointer argument from these closure. The closure taking APIs are designed to 
>> keep your data alive while you access it and make sure you’re not mixing 
>> pointers of different types to the same memory.
>> 
>> -Andy
>> 
 On 12 sep. 2016, at 21:37, Bouke Haarsma > wrote:
 
 
 Sorry, missed the first line when copying:
 
 let generic = unsafeBitCast(CFDataGetBytePtr(data), to: sockaddr.self)
 switch generic.sa_family {
 case sa_family_t(AF_INET):
 let ipv4 = unsafeBitCast(generic, to: 

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

2016-09-20 Thread Bouke Haarsma via swift-users

Hi all,

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).


The following works on OSX, but doesn't work on Linux;

   let readStream: CFReadStream = ...
   readStream as InputStream
   // error: cannot convert value of type 'CFReadStream' to expected 
argument type 'InputStream'


In some other places I need to bridge a String to a CFString, the 
following works on OSX, but doesn't work on Linux;


   let string: String = ...
   string as CFString
   // error: error: 'String' is not convertible to 'CFString'; did you 
mean to use 'as!' to force downcast?


Thanks.

--
-Bouke


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


Re: [swift-users] How to create an iOS project by SPM?

2016-09-20 Thread Leo via swift-users
Got it, thanks a lot
--

> On Wednesday, Sep 21, 2016 at 10:23, Shawn Erickson  (mailto:shaw...@gmail.com)> wrote:
> Search the list archives. A question about SPM and iOS came up in the last 
> month or two. It is desired but not yet supported since iOS signing, etc. is 
> heavily dependent on Xcode. It seems like something may be in the works in 
> side Apple to make it happen but can't be commented on publicly... or that 
> could just be my interpretation of the email.
> On Tue, Sep 20, 2016 at 6:35 PM zh ao via swift-users  (mailto:swift-users@swift.org)> wrote:
> > I don't think it will be in the near future. I have not used it yet. Does 
> > it support Objective-C cross compiling? If it supports Swift only, it may 
> > not be designed to do that.
> >
> > Zhaoxin
> >
> > Get Outlook for iOS (https://aka.ms/o0ukef)
> >
> >
> >
> > On Wed, Sep 21, 2016 at 9:24 AM +0800, "Leo"  > (mailto:join_shi...@yahoo.com)> wrote:
> >
> > > Thanks for your mail.
> > > Have any news about supporting iOS?
> > > --
> > >
> > > > On Wednesday, Sep 21, 2016 at 06:45, zh ao  > > > (mailto:owe...@gmail.com)> wrote:
> > > > I don't think you could. According to the release note of Xcode 8, 
> > > > Swift Package Manager can only be used in macOS command line.
> > > >
> > > > Zhaoxin
> > > >
> > > > Get Outlook for iOS (https://aka.ms/o0ukef)
> > > >
> > > >
> > > >
> > > > On Wed, Sep 21, 2016 at 12:12 AM +0800, "Leo SHI via swift-users" 
> > > >  wrote:
> > > >
> > > > > Hi guys, I started to use SPM after installing Xcode 8, It’s a good 
> > > > > tool for me. But I can create MacOS project only. How to create an 
> > > > > iOS project by SPM? Thanks Leo 
> > > > > ___ swift-users mailing 
> > > > > list swift-users@swift.org (mailto:swift-users@swift.org) 
> > > > > https://lists.swift.org/mailman/listinfo/swift-users 
> > > > > ___
> > swift-users mailing list
> > swift-users@swift.org (mailto: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] Ubuntu 16.04 support?

2016-09-20 Thread Bouke Haarsma via swift-users

On 2016-09-20 16:37:18 +, Lane Schwartz via swift-users said:

In addition to the installation instructions per swift.org, I also 
needed to install "libpython2.7-dev". When starting the Swift REPL it 
threw the following error;


...swift/usr/bin/lldb: error while loading shared libraries: 
libpython2.7.so.1.0: cannot open shared object file: No such file or 
directory


Installing that package resolved that issue. However the REPL loads, it 
throws errors like this:


ubuntu-1604:~$ swift
Welcome to Swift version 3.0 (swift-3.0-RELEASE). Type :help for assistance.
 1> import Foundation
 2> NSURL(string: "http://swift.org;)
error: Couldn't lookup symbols:
 type metadata accessor for Foundation.NSURL
 Foundation.NSURL.__allocating_init (string : Swift.String) -> 
Swift.Optional


I've downgraded to 14.04 LTS.


Thanks.


On Tue, Sep 20, 2016 at 11:28 AM, Ron Olson via swift-users 
 wrote:

I downloaded the Ubuntu 15 release.

On 20 Sep 2016, at 11:26, Lane Schwartz wrote:

Thanks, Ron. Which binary release did you download? The ubuntu 15 
release? Or the 14 release?


On Tue, Sep 20, 2016 at 11:12 AM, Ron Olson via swift-users 
 wrote:
I can verify that the 3.0 Release works under 16; I downloaded it this 
morning and it works fine.



On 20 Sep 2016, at 11:10, Lane Schwartz via swift-users wrote:

I see that there are swift packages for Ubuntu 14 and 15, but not 16. Is
Swift 3.0 known to work with Ubuntu 16? Can either of the aforementioned
binary releases be used, or is compilation from source required?

Thanks,
Lane
___
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



--
When a place gets crowded enough to require ID's, social collapse is not
far away.  It is time to go elsewhere.  The best thing about space travel
is that it made it possible to go elsewhere.
                -- R.A. Heinlein, "Time Enough For Love"


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




--
When a place gets crowded enough to require ID's, social collapse is not
far away.  It is time to go elsewhere.  The best thing about space travel
is that it made it possible to go elsewhere.
                -- R.A. Heinlein, "Time Enough For Love"
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users



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


Re: [swift-users] How to create an iOS project by SPM?

2016-09-20 Thread Shawn Erickson via swift-users
Search the list archives. A question about SPM and iOS came up in the last
month or two. It is desired but not yet supported since iOS signing, etc.
is heavily dependent on Xcode. It seems like something may be in the works
in side Apple to make it happen but can't be commented on publicly... or
that could just be my interpretation of the email.
On Tue, Sep 20, 2016 at 6:35 PM zh ao via swift-users 
wrote:

> I don't think it will be in the near future. I have not used it yet. Does
> it support Objective-C cross compiling? If it supports Swift only, it may
> not be designed to do that.
>
> Zhaoxin
>
> Get Outlook for iOS 
>
>
>
>
> On Wed, Sep 21, 2016 at 9:24 AM +0800, "Leo" 
> wrote:
>
> Thanks for your mail.
>> Have any news about supporting iOS?
>> --
>>
>> On Wednesday, Sep 21, 2016 at 06:45, zh ao  wrote:
>> I don't think you could. According to the release note of Xcode 8, Swift
>> Package Manager can only be used in macOS command line.
>>
>> Zhaoxin
>>
>> Get Outlook for iOS 
>>
>>
>>
>>
>> On Wed, Sep 21, 2016 at 12:12 AM +0800, "Leo SHI via swift-users" <
>> swift-users@swift.org> wrote:
>>
>> Hi guys,
>>>
>>> I started to use SPM after installing Xcode 8, It’s a good tool for me. But 
>>> I can create MacOS project only.
>>> How to create an iOS project by SPM?
>>>
>>> Thanks
>>>
>>> Leo
>>> ___
>>> swift-users mailing 
>>> listswift-users@swift.orghttps://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] How to create an iOS project by SPM?

2016-09-20 Thread zh ao via swift-users
I don't think it will be in the near future. I have not used it yet. Does it 
support Objective-C cross compiling? If it supports Swift only, it may not be 
designed to do that. 
Zhaoxin

Get Outlook for iOS




On Wed, Sep 21, 2016 at 9:24 AM +0800, "Leo"  wrote:










   Thanks for your 
mail.Have any news about supporting iOS?--
On Wednesday, Sep 21, 2016 at 06:45, zh ao  wrote:
I don't think you could. According to the release note of Xcode 8, Swift 
Package Manager can only be used in macOS command line.
Zhaoxin

Get Outlook for iOS




On Wed, Sep 21, 2016 at 12:12 AM +0800, "Leo SHI via swift-users" 
 wrote:










Hi guys,

I started to use SPM after installing Xcode 8, It’s a good tool for me. But I 
can create MacOS project only.
How to create an iOS project by SPM?

Thanks

Leo
___
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] How to create an iOS project by SPM?

2016-09-20 Thread Leo via swift-users
Thanks for your mail.
Have any news about supporting iOS?
--

> On Wednesday, Sep 21, 2016 at 06:45, zh ao  (mailto:owe...@gmail.com)> wrote:
> I don't think you could. According to the release note of Xcode 8, Swift 
> Package Manager can only be used in macOS command line.
>
> Zhaoxin
>
> Get Outlook for iOS (https://aka.ms/o0ukef)
>
>
>
> On Wed, Sep 21, 2016 at 12:12 AM +0800, "Leo SHI via swift-users" 
>  wrote:
>
> > Hi guys, I started to use SPM after installing Xcode 8, It’s a good tool 
> > for me. But I can create MacOS project only. How to create an iOS project 
> > by SPM? Thanks Leo ___ 
> > 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] Referencing different objects implementing a protocol where the protocol has 'associatedtype'

2016-09-20 Thread Brent Royal-Gordon via swift-users
> On Sep 18, 2016, at 6:21 AM, Palfi, Andras via swift-users 
>  wrote:
> 
> Workaround:
> Use 'Thunks'. These are type eraser structs, which implements the same 
> protocol. For each method they referencing (capturing) the original methods 
> and properties of the object. So 'thunks' are technically proxy objects. 
> 
> struct DirtyThunk : SomeProtocol {
> 
>private let _someMethod : (SomeElementType) -> Void
> 
>init(delegate : D) where D.ElementType==SomeElementType {
>_someMethod = delegate.someMethod
>}
> 
>func someMethod(withElement: SomeElementType) {
>_someMethod(withElement)
>}
> }
> 
> the subscribe method will be modified:
> func subscribe(delegate : D) where 
> D.ElementType==SomeElementType { // would be better without generics as this 
> generates as many methods as many different types used to call it
>let thunk = DirtyThunk(delegate)
>delegates.append(thunk)
>}
> 
> This solution works - however we can never retrieve the original object any 
> more as it is not referenced. The implementation of the “thunks” are also 
> painful a bit. The methods are captured only by the name of the methods 
> without the parameters so leads the problem if different methods have the 
> same prefix.
> 
> I tried to solve using ‘Any’ to reference the delegates but then cannot cast 
> to a proper type to call them.
> 
> 
> Do one know any better solution?

There's a more complex way to write a "type-erased wrapper" (the preferred 
Swift term for a thunk). The trick is that you use a base class which is *not* 
generic on the actual type, plus a derived class which *is* generic on the 
actual type, to hold the actual instance. For example:

private class SomeProtocolBox {
private init() {}

func someMethod(withElement: SomeElementType) { fatalError() }
}

private class ConcreteSomeProtocolBox: 
SomeProtocolBox {
var value: SomeProtocolType

init(_ value: SomeProtocolType) {
self.value = value
}

override func someMethod(withElement: SomeElementType) {
value.someMethod(withElement: withElement)
}
}

public struct AnySomeProtocol: SomeProtocol {
public typealias ElementType = SomeElementType

private var box: SomeProtocolBox

public init(_ value: T) where T.ElementType == 
SomeElementType {
box = ConcreteSomeProtocolBox(value)
}

func someMethod(withElement: SomeElementType) {
box.someMethod(withElement: withElement)
}
}

With this in place, it's not difficult to support recovering the original 
instance as an `Any`:

extension SomeProtocolBox {
var base: Any { fatalError() }
}
extension ConcreteSomeProtocolBox {
override var base: Any { return value }
}
extension AnySomeProtocol {
var base: Any { return box.base }
}

It's also more efficient than the closure-based solution, since it doesn't need 
a separate closure (and context) for each method it indirects.

There's some hope that eventually all of this will be unnecessary and you'll be 
able to use protocols with associated types in more places, possibly with some 
special casting syntax to make sure you're passing the proper type. No idea if 
or when that will actually be implemented, though.

-- 
Brent Royal-Gordon
Architechies

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


Re: [swift-users] How to create an iOS project by SPM?

2016-09-20 Thread zh ao via swift-users
I don't think you could. According to the release note of Xcode 8, Swift 
Package Manager can only be used in macOS command line.
Zhaoxin

Get Outlook for iOS




On Wed, Sep 21, 2016 at 12:12 AM +0800, "Leo SHI via swift-users" 
 wrote:










Hi guys,

I started to use SPM after installing Xcode 8, It’s a good tool for me. But I 
can create MacOS project only.
How to create an iOS project by SPM?

Thanks

Leo
___
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] Generic type for a generic type?

2016-09-20 Thread Jon Shier via swift-users
Swifters:
I’m running into a type inference problem when attempting to pass a 
generic type which is generic to a generic type to a function which expects a 
generic type. I’ll explain:

I have a function:
func add(observer: Observer) where 
Observer.Procedure == Procedure

Which I’m sending a parameter of type:

struct BlockObserver: ProcedureObserver

Which has been provided a type through this function:

func networkProcedureProgressViewObserver() -> BlockObserver> where U == U.DecodedType

However, calling add(observer: networkProcedureProgressViewObserver()) results 
in the error: Generic parameter ‘Observer’ could not be inferred. I’ve tried 
everything I can think of to help the inference but nothing works. Am I correct 
in thinking this is a limitation of the current generics system not being able 
to propagate the type information from NetworkProcedure to 
BlockObserver> to the function?



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


Re: [swift-users] open/public protocol with not overridable default implementation in the future?

2016-09-20 Thread Brent Royal-Gordon via swift-users
> I always wanted a way to make some protocol default implementations not 
> overridable. Now Swift 3 got open vs. public behavior for classes. (Hopefully 
> the inconsistency will be fixed soon and we’ll get open protocols as well.)
> 
> Imagine this scenario with open/public protocols.
> 
> // Module A
> // `open protocol` means that in a diff. module I'll
> // be able to conform to that protocol
> open protocol Proto {}
> 
> extension Proto {
>  // shouldn't this mean that the variable is not overridable  
>  // from a different module? :)
>  public var foo: Int { return 42 }
> }
> 
> // Module B
> struct A : Proto {
> // can I or can I not override `foo` from here?
> }
> 
> I wonder if my thinking is correct here, or do we need something else to make 
> extensions with default implementation to be fixed and not overridable?

Currently, a declaration of `A.foo` would not *override* `Proto.foo`, it would 
*shadow* it. Using `foo` on a variable of type `Proto` will always use 
`Proto`'s implementation. That's why `A.foo`'s declaration will not have the 
`override` keyword. It's a subtle distinction, but a really important one—if 
you're expecting a call to `Proto.foo` to instead go to `A.foo`, you're gonna 
have a bad time.

Personally, I think this is a bad idea, and I'd like to see the compiler reject 
conformances which cause visible shadowing. But that's a different story. As 
long as we're allowing this shadowing to pass unremarked, it makes sense that 
`public` wouldn't prevent it.

-- 
Brent Royal-Gordon
Architechies

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


Re: [swift-users] Double pointer in ObjC function signature importing incorrectly in Swift 3?

2016-09-20 Thread first account 2 via swift-users


Sent from Alto
On Tuesday, 20 September 2016 Jordan Rose via swift-users 
 wrote:
C represents pointers the other way around; that declaration says only the 
outer pointer is nullable. There are two things going on here:

- Swift 2 made all pointers implicitly nullable, without using an optional 
type. Swift 3 makes that explicit.
- Swift 2 had a bug that assumed that all pointers-to-references were optional, 
instead of just those without nullability annotations. Swift 3 "fixes" that…but 
that reveals places where headers used _Nonnull to mean "always produces a 
nonnull pointer", forgetting that it also applies to input.

If this is an API in CloudKit itself, please file a Radar at 
bugreport.apple.com. If it's a third-party library built on CloudKit, you'll 
have to report the issue to them.

Sorry for the trouble!
Jordan


> On Sep 20, 2016, at 10:32, Michael Gardner via swift-users wrote:
> 
> I'm using an Objective-C library that has me provide a callback that takes a 
> double-pointer parameter like this, where only the inner pointer is nullable:
> 
> CKRecord *_Nonnull *_Nullable inOutRecordPtr
> 
> Swift 2 imported this as an AutoreleasingUnsafeMutablePointer, as expected. 
> However, Swift 3 is importing it as AutoreleasingUnsafeMutablePointer?, which 
> breaks the library's API since there's no way to return a new record.
> 
> Is this a Swift 3 bug, or am I missing something?
> ___
> 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] Double pointer in ObjC function signature importing incorrectly in Swift 3?

2016-09-20 Thread Jordan Rose via swift-users
C represents pointers the other way around; that declaration says only the 
outer pointer is nullable. There are two things going on here:

- Swift 2 made all pointers implicitly nullable, without using an optional 
type. Swift 3 makes that explicit.
- Swift 2 had a bug that assumed that all pointers-to-references were optional, 
instead of just those without nullability annotations. Swift 3 "fixes" that…but 
that reveals places where headers used _Nonnull to mean "always produces a 
nonnull pointer", forgetting that it also applies to input.

If this is an API in CloudKit itself, please file a Radar at 
bugreport.apple.com. If it's a third-party library built on CloudKit, you'll 
have to report the issue to them.

Sorry for the trouble!
Jordan


> On Sep 20, 2016, at 10:32, Michael Gardner via swift-users 
>  wrote:
> 
> I'm using an Objective-C library that has me provide a callback that takes a 
> double-pointer parameter like this, where only the inner pointer is nullable:
> 
> CKRecord *_Nonnull *_Nullable inOutRecordPtr
> 
> Swift 2 imported this as an AutoreleasingUnsafeMutablePointer, as 
> expected. However, Swift 3 is importing it as 
> AutoreleasingUnsafeMutablePointer?, which breaks the library's API 
> since there's no way to return a new record.
> 
> Is this a Swift 3 bug, or am I missing something?
> ___
> 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] Bls: reading keyboard input from xcode playgroud

2016-09-20 Thread Mr Bee via swift-users
I knew it's a bug, hence this email.
I need input() function to accept user input from within Playground, not from 
Terminal (command line). I want it on Terminal, I would have used the 
readLine() function which ser 
–Mr Bee
 

   

 Pada Selasa, 20 September 2016 21:13, Zhao Xin  menulis:
 

 I test you code in command line `swiftc main.swift` and in macOS Command Line 
Tool app.
Here is the main.swift:
import Foundation
import Foundation
func input() -> String {    let keyboard  = FileHandle.standardInput    let 
inputData = keyboard.availableData    let strData   = String(data: inputData, 
encoding: .utf8)    return strData!}
func write(_ txt: String) {    print(txt, terminator: "")}
func read() -> String {    let c = CharacterSet.whitespacesAndNewlines    
return input().trimmingCharacters(in: c)}
/* main program */
write("Enter your name: ")let s = read()print("You name is \(s)")
It turns out that the input request was ran before the `write("Enter your name: 
")`. I don't why. Maybe it is a bug?
Here is my output in terminal:
$ swiftc main.swift $ ./main abcEnter your name: You name is abc$ 
As you can see, the program asked me to input my name before it showed the 
notification. In playground, the situation is alike. 
However, if the code is running as a command line tool, created by Xcode -> 
Create a new project -> macOS, command line tool, everything works fine.
Zhaoxin
On Sun, Sep 18, 2016 at 9:16 PM, Mr Bee via swift-users  
wrote:

Hi all,
Another question. I used to use this snippet to read keyboard input from 
XCode's Playground. And it used to work very well. Today, I just updated my 
XCode to v.8 and Swift v.3. After a little bit modification here and there due 
to Swift 3 incompatibility, I got this code compiled without error. But it 
doesn't work. No keyboard input is taken. It just stucks.
Here's the code:
import Foundation
func input() -> String {  let keyboard  = FileHandle.standardInput  let 
inputData = keyboard.availableData  let encoding  = String.Encoding(rawValue: 
String.Encoding.utf8.rawValue)  let strData   = String(data: inputData, 
encoding: encoding)  return strData! as String}
func write(_ txt: String) {  print(txt, terminator: "")}
func read() -> String {  let c = CharacterSet.whitespacesAndNew lines  return 
input().trimmingCharacters(in: c)}

/* main program */

write("Enter your name: ")let s = read() So, does anyone know how to make it 
works (again)? Thank you.
Regards,
–Mr Bee

__ _
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] Double pointer in ObjC function signature importing incorrectly in Swift 3?

2016-09-20 Thread Michael Gardner via swift-users
I'm using an Objective-C library that has me provide a callback that takes a 
double-pointer parameter like this, where only the inner pointer is nullable:

CKRecord *_Nonnull *_Nullable inOutRecordPtr

Swift 2 imported this as an AutoreleasingUnsafeMutablePointer, as 
expected. However, Swift 3 is importing it as 
AutoreleasingUnsafeMutablePointer?, which breaks the library's API 
since there's no way to return a new record.

Is this a Swift 3 bug, or am I missing something?
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Ubuntu 16.04 support?

2016-09-20 Thread Lane Schwartz via swift-users
Thanks.


On Tue, Sep 20, 2016 at 11:28 AM, Ron Olson via swift-users <
swift-users@swift.org> wrote:

> I downloaded the Ubuntu 15 release.
> On 20 Sep 2016, at 11:26, Lane Schwartz wrote:
>
> Thanks, Ron. Which binary release did you download? The ubuntu 15 release?
> Or the 14 release?
>
> On Tue, Sep 20, 2016 at 11:12 AM, Ron Olson via swift-users <
> swift-users@swift.org> wrote:
>
>> I can verify that the 3.0 Release works under 16; I downloaded it this
>> morning and it works fine.
>>
>>
>> On 20 Sep 2016, at 11:10, Lane Schwartz via swift-users wrote:
>>
>> I see that there are swift packages for Ubuntu 14 and 15, but not 16. Is
>>> Swift 3.0 known to work with Ubuntu 16? Can either of the aforementioned
>>> binary releases be used, or is compilation from source required?
>>>
>>> Thanks,
>>> Lane
>>> ___
>>> 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
>>
>
>
>
> --
> When a place gets crowded enough to require ID's, social collapse is not
> far away.  It is time to go elsewhere.  The best thing about space travel
> is that it made it possible to go elsewhere.
> -- R.A. Heinlein, "Time Enough For Love"
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>


-- 
When a place gets crowded enough to require ID's, social collapse is not
far away.  It is time to go elsewhere.  The best thing about space travel
is that it made it possible to go elsewhere.
-- R.A. Heinlein, "Time Enough For Love"
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Ubuntu 16.04 support?

2016-09-20 Thread Lane Schwartz via swift-users
Thanks, Ron. Which binary release did you download? The ubuntu 15 release?
Or the 14 release?

On Tue, Sep 20, 2016 at 11:12 AM, Ron Olson via swift-users <
swift-users@swift.org> wrote:

> I can verify that the 3.0 Release works under 16; I downloaded it this
> morning and it works fine.
>
>
> On 20 Sep 2016, at 11:10, Lane Schwartz via swift-users wrote:
>
> I see that there are swift packages for Ubuntu 14 and 15, but not 16. Is
>> Swift 3.0 known to work with Ubuntu 16? Can either of the aforementioned
>> binary releases be used, or is compilation from source required?
>>
>> Thanks,
>> Lane
>> ___
>> 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
>



-- 
When a place gets crowded enough to require ID's, social collapse is not
far away.  It is time to go elsewhere.  The best thing about space travel
is that it made it possible to go elsewhere.
-- R.A. Heinlein, "Time Enough For Love"
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] How to create an iOS project by SPM?

2016-09-20 Thread Leo SHI via swift-users
Hi guys,

I started to use SPM after installing Xcode 8, It’s a good tool for me. But I 
can create MacOS project only.
How to create an iOS project by SPM?

Thanks

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


[swift-users] Ubuntu 16.04 support?

2016-09-20 Thread Lane Schwartz via swift-users
I see that there are swift packages for Ubuntu 14 and 15, but not 16. Is
Swift 3.0 known to work with Ubuntu 16? Can either of the aforementioned
binary releases be used, or is compilation from source required?

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


Re: [swift-users] reading keyboard input from xcode playgroud

2016-09-20 Thread Zhao Xin via swift-users
I test you code in command line `swiftc main.swift` and in macOS Command
Line Tool app.

Here is the main.swift:

import Foundation


import Foundation


func input() -> String {

let keyboard  = FileHandle.standardInput

let inputData = keyboard.availableData

let strData   = String(data: inputData, encoding: .utf8)

return strData!

}


func write(_ txt: String) {

print(txt, terminator: "")

}


func read() -> String {

let c = CharacterSet.whitespacesAndNewlines

return input().trimmingCharacters(in: c)

}


/* main program */


write("Enter your name: ")

let s = read()

print("You name is \(s)")


It turns out that the input request was ran before the `write("Enter your
name: ")`. I don't why. Maybe it is a bug?


Here is my output in terminal:


$ swiftc main.swift

$ ./main

abc

Enter your name: You name is abc

$


As you can see, the program asked me to input my name before it showed the
notification. In playground, the situation is alike.


However, if the code is running as a command line tool, created by Xcode ->
Create a new project -> macOS, command line tool, everything works fine.


Zhaoxin

On Sun, Sep 18, 2016 at 9:16 PM, Mr Bee via swift-users <
swift-users@swift.org> wrote:

> Hi all,
>
> Another question. I used to use this snippet to read keyboard input from
> XCode's Playground. And it used to work very well. Today, I just updated my
> XCode to v.8 and Swift v.3. After a little bit modification here and there
> due to Swift 3 incompatibility, I got this code compiled without error. But
> it doesn't work. No keyboard input is taken. It just stucks.
>
> Here's the code:
>
> import Foundation
>
> func input() -> String {
>   let keyboard  = FileHandle.standardInput
>   let inputData = keyboard.availableData
>   let encoding  = String.Encoding(rawValue: String.Encoding.utf8.rawValue)
>   let strData   = String(data: inputData, encoding: encoding)
>   return strData! as String
> }
>
> func write(_ txt: String) {
>   print(txt, terminator: "")
> }
>
> func read() -> String {
>   let c = CharacterSet.whitespacesAndNewlines
>   return input().trimmingCharacters(in: c)
> }
>
> /* main program */
>
> write("Enter your name: ")
> let s = read()
>
> So, does anyone know how to make it works (again)? Thank you.
>
> Regards,
>
> –Mr Bee
>
>
> ___
> 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