Re: [swift-users] Migrating to Swift 3 Dispatch

2016-10-16 Thread Rien via swift-users
I’am not familiar with “timer dispatch source”. Do you want to run some closure at time X? Does this help? let dpt = DispatchTime.now() + delta * Double(NSEC_PER_SEC) queue.asyncAfter(deadline: dpt) { … } Regards, Rien. > On 16 Oct 2016, at 20:25, Thierry Passeron via s

Re: [swift-users] comparison Non-Optional and Optional without unwrap

2016-10-18 Thread Rien via swift-users
Because the comparison function “==“ has the signature: func ==(lhs: T?, rhs: T?) -> Bool An optional parameter accepts non-optionals. In a sense non-optionals are “promoted” to optionals when used for an optional parameter. Rien. > On 18 Oct 2016, at 10:58, Седых Александр via swift-users >

Re: [swift-users] Segmentation fault: 11 after updating codebase to Swift 3.0

2016-10-21 Thread Rien via swift-users
I had a similar problem with Xcode 7.2. The work around I found then was to remove all source files from the project in the “target membership” except for the main.swift file. Then compile again, which will (of course) fail with normal errors. Then I added the files back in, presto, no more segmen

Re: [swift-users] Set-uniqueness of instances with distinct hashValue

2016-10-23 Thread Rien via swift-users
If you change the “==“ function to: func == (lhs: X, rhs: X) -> Bool { return (lhs.x == rhs.x) && (lhs.hashValue == rhs.hashValue) } then the example works as expected. Apple says this: “A hash value, provided by a type’s hashValue property, is an integer that is the same for any two instan

Re: [swift-users] What is "binding" memory?

2016-11-01 Thread Rien via swift-users
The way I understand it, it prepares a memory structure that refers to the ‘raw memory’ such that it can be used to access the referenced memory according to the type ‘bound’ to. Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien

Re: [swift-users] What is "binding" memory?

2016-11-02 Thread Rien via swift-users
> On 02 Nov 2016, at 18:07, Manfred Schubert via swift-users > wrote: > > Am 01.11.2016 um 21:40 schrieb Andrew Trick : >> >> I’m not sure I like the “prepares the memory” language myself. Binding >> memory communicates to the compiler that the memory locations are safe for >> typed access.

Re: [swift-users] What is "binding" memory?

2016-11-03 Thread Rien via swift-users
> On 03 Nov 2016, at 15:16, Manfred Schubert via swift-users > wrote: > > >> Am 02.11.2016 um 18:37 schrieb Rien : >> var rawPtr = UnsafeMutableRawPointer.allocate(bytes: 2, alignedTo: 0) var widePtr = rawPtr.bindMemory(to: Int16.self, capacity: 1) widePtr.poin

Re: [swift-users] What is "binding" memory?

2016-11-04 Thread Rien via swift-users
http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 04 Nov 2016, at 06:24, Andrew Trick wrote: > >> >> On Nov 3, 2016, at 7:41 AM, Rien via swift-users >> wrote: >> >>> On 03 Nov 2016, at 15:16,

Re: [swift-users] What is "binding" memory?

2016-11-04 Thread Rien via swift-users
> On 03 Nov 2016, at 23:58, Manfred Schubert via swift-users > wrote: > > Am 03.11.2016 um 15:41 schrieb Rien : >> >> Ah, but that is not the case. >> >> It is important to differentiate between the “gateway” to the memory and the >> memory area itself. >> Different programming languages/com

Re: [swift-users] Understanding pass-by-value

2016-11-04 Thread Rien via swift-users
> On 04 Nov 2016, at 13:59, Ryan Lovelett via swift-users > wrote: > > struct Foo { > init(from buffer: Data) { > bar = integer(withBytes: Array(buffer[4..<6])) > baz = integer(withBytes: Array(buffer[6..<8])) > ... > } > > let d = Data(count: Int(3e+8)) > let f = Foo(from: d) >

Re: [swift-users] Understanding pass-by-value

2016-11-04 Thread Rien via swift-users
> On 04 Nov 2016, at 17:48, Ryan Lovelett wrote: > >> I often end up “printing” the addresses or using GDB to take an inside >> look. > > That is a really simple interrogation technique I wish I had thought of > that! Thank you! > >> One thing that tripped me up: if you use inout variables, th

Re: [swift-users] The value of enums

2016-11-06 Thread Rien via swift-users
As usual: it depends. I use enums with associated values quite a lot. In my experience there is quite a thin line between very convenient and too much. I have several cases where I started off with enums with associated values, only to later convert them to classes. As long as the enums only hav

Re: [swift-users] Details of defer statement in Swift

2016-11-09 Thread Rien via swift-users
The manual says this: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html A defer statement is used for executing code just before transferring program control outside of the scope that the defer statement appears in. The scope o

Re: [swift-users] Overload Resolution of Binary Operators

2016-11-14 Thread Rien via swift-users
I seem to remember that while it is possible to define, the compiler will yield an error if you try to use the functions (“cannot resolve”). Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 1

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Rien via swift-users
How about using: UnsafeMutablePointer ? Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 16 Dec 2016, at 09:10, Richard Wei via swift-users > wrote: > > Capturing makes it immutable, whic

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Rien via swift-users
> >> What is the type of self? If it is a class, try [unowned self]. >> >> Zhaoxin >> >> >> >> >> >> >> On Fri, Dec 16, 2016 at 4:33 PM, Rien via swift-users >> wrote: >> How about using: >> >>

Re: [swift-users] Weird protocol behaviour.

2016-12-22 Thread Rien via swift-users
IMO the error message says it all: Playground execution failed: error: MyPlayground8.playground:9:5: error: cannot invoke 'foo' with an argument list of type '(P)' foo(x) ^ MyPlayground8.playground:9:5: note: expected an argument list of type '(A)' foo(x) ^ I.e. you are passing

Re: [swift-users] Weird protocol behaviour.

2016-12-23 Thread Rien via swift-users
a >> discussion on -evolution. >> >>> On Dec 22, 2016, at 2:17 PM, Howard Lovatt via swift-users >>> wrote: >>> >>> I suspect a compiler bug since A is a P. The equivalent in Java works: >>> >>> interface P {} >>> c

Re: [swift-users] Weird protocol behaviour.

2016-12-23 Thread Rien via swift-users
Nattinger wrote: >>> I recall seeing a request on the -evolution list for something like `T := >>> X` to indicate it could be X itself or anything inheriting / implementing >>> it, so it’s certainly known behavior, if not desired. IMO it’s a bug and >>> `:`

Re: [swift-users] Using 'SomeProtocol' as a concrete type conforming to protocol 'SomeProtocol' is not supported

2016-12-29 Thread Rien via swift-users
I think you made your type (enum) unnecessary complex, the following works: protocol Element { } enum ElementNode { case element(Element) case empty } var childElements = [ElementNode]() Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http:

Re: [swift-users] Using 'SomeProtocol' as a concrete type conforming to protocol 'SomeProtocol' is not supported

2016-12-29 Thread Rien via swift-users
As to the why question: (just guessing here) By the time the compiler want to know what type will be in the array, it cannot do so. The enum is a generic and thus without full type information (it only has partial type information). Regards, Rien Site: http://balancingrock.nl Blog: http://swif

Re: [swift-users] How much memory does withMemoryRebound bind

2016-12-29 Thread Rien via swift-users
I used the code from http://blog.obdev.at/representing-socket-addresses-in-swift-using-enums/ in my package SwifterSockets (see github link below) It does not answer your question exactly, but I think it is a rather better approach to sockaddr usage. Regards, Rien Site: http://balancingrock.n

Re: [swift-users] How much memory does withMemoryRebound bind

2016-12-29 Thread Rien via swift-users
Ah, ok. In that case, I believe it is correct because sockaddr_storage is in fact big enough to hold either the IPv4 or IPv6 structure. When bits go unused, that causes no harm. And when “addr” goes out of scope, it will be completely deallocated, so no memory leak either. Regards, Rien Site:

Re: [swift-users] Weird protocol behaviour.

2016-12-30 Thread Rien via swift-users
not desired. IMO it’s a bug and `:` >> should be fixed to include the root type, whether or not that requires a >> discussion on -evolution. >> >>> On Dec 22, 2016, at 2:17 PM, Howard Lovatt via swift-users >>> wrote: >>> >>> I suspect a

Re: [swift-users] Weird protocol behaviour.

2016-12-30 Thread Rien via swift-users
> >> it, so it’s certainly known behavior, if not desired. IMO it’s a bug and > >> `:` should be fixed to include the root type, whether or not that requires > >> a discussion on -evolution. > >> > >>> On Dec 22, 2016, at 2:17 PM, Howard Lovatt via swift-u

[swift-users] UnsafePointer and C-String

2017-01-03 Thread Rien via swift-users
The documentation at https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html shows that it is possible to use String where an UnsafePointer is needed. API calls to C that need a char* are translated to UnsafePointer. It follows that w

Re: [swift-users] UnsafePointer and C-String

2017-01-03 Thread Rien via swift-users
Thanks Jeremy & Ole, That was indeed my expectation, but I had not thought of looking in the source code! Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 03 Jan 2017, at 16:31, Ole Begemann

Re: [swift-users] Compiler should issue a warning when a subclass implementation with default values matches a parent implementation without them

2017-01-04 Thread Rien via swift-users
As you know. there is no ambiguity, no warnings needed. (The parameter is part of the identifier of the function) Imo, this request falls into the category “do as I think, not as I say”. That is a discussion without end. Personally I am against ANY warnings of this kind. The reason is that I wan

Re: [swift-users] getResourceValue

2017-01-05 Thread Rien via swift-users
What is your real question? Obviously the doc says that this is fine, so what are you asking? what is your problem? Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 05 Jan 2017, at 20:36, J.E

Re: [swift-users] getResourceValue

2017-01-06 Thread Rien via swift-users
URL is the same as NSURL in Swift 3 Foundation -> NSURL -> getResourceValue. If you use xcode, open up the Help -> Documentation and API reference The do a search for getResourceValue. Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swif

Re: [swift-users] getResourceValue

2017-01-06 Thread Rien via swift-users
Hmm, that is interesting to know. I had not realised that URL is in fact NOT a NSURL but a new type that is based on NSURL (and can be toll-free bridged I assume?). I also presume that the same is true for Data/NSData, Date/NSDate etc? (Failure on my part, as I did of course know that the .path

Re: [swift-users] getResourceValue

2017-01-06 Thread Rien via swift-users
Thanks Rod, very enlightening! Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 06 Jan 2017, at 15:19, Rod Brown wrote: > > >> On 7 Jan 2017, at 12:50 am, Rien wrote: >> >> Hmm, that is i

Re: [swift-users] Exclamation mark's in swift parameter listings?

2017-01-09 Thread Rien via swift-users
It means that a call to that function with an optional will unwrap the optional before it is used. That is quite neat when dealing with C-API’s because often you will receive a pointer from a C-function which is optional to account for the fact that it can be NULL (= nil). By using a forced unw

Re: [swift-users] Exclamation mark's in swift parameter listings?

2017-01-10 Thread Rien via swift-users
://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 10 Jan 2017, at 18:14, Joe Groff wrote: > > >> On Jan 9, 2017, at 11:19 PM, Rien via swift-users >> wrote: >> >> It means that a call to th

[swift-users] C-function not found by linker

2017-01-11 Thread Rien via swift-users
My project uses openSSL and that works fine. I needed one specific function that cannot be accessed from Swift directly, so I created a C-file for that. (both .h and .c file) The function is found during compilation. But is then reported as “unused” and the linker reports “missing function”. A

Re: [swift-users] C-function not found by linker

2017-01-11 Thread Rien via swift-users
://github.com/Swiftrien Project: http://swiftfire.nl > On 11 Jan 2017, at 10:28, Rien via swift-users wrote: > > My project uses openSSL and that works fine. > > I needed one specific function that cannot be accessed from Swift directly, > so I created a C-file for that. (both .h and

[swift-users] Migrating to SPM, best practise?

2017-01-18 Thread Rien via swift-users
I have a small sockets based framework on Github (SwifterSockets). It was created before SPM existed. The next update is planned, and I want to move to SPM. 1) How to create a package around the old xcode project? 2) I am unsure how to move from the old git structure to the new. What would be the

Re: [swift-users] Exclamation mark's in swift parameter listings?

2017-01-18 Thread Rien via swift-users
cases from each other. > > Slava > >> On Jan 10, 2017, at 9:52 AM, Rien via swift-users >> wrote: >> >> I stand corrected. >> >> I do/did think that there is a difference in the way it handles pointers >> optionals and other optionals, but I now re

[swift-users] SPM & Library with bridging header

2017-01-20 Thread Rien via swift-users
I noticed something strange about Xcode and SPM concerning the capability to generate Libraries. When I try to create a Library in Xcode and then want to add an Objective-C bridging header, that is denied. It claims that bridging is not supported for Libraries. When I create an Xcode project t

Re: [swift-users] SPM & Library with bridging header

2017-01-20 Thread Rien via swift-users
M myself I don’t know if there are any public plans to do so.) > > The recommended solution is to group your Objective-C headers into modules > (usually just frameworks) and import them that way, rather than to jam them > in via a bridging header. > > Sorry for the troub

Re: [swift-users] SPM & Library with bridging header

2017-01-21 Thread Rien via swift-users
20 Jan 2017, at 19:48, Rien via swift-users wrote: > > I may be missing something here, so please bear with me... > > The client of the lib only has to see the headers that describe the lib, not > the headers of the files that were used to create the lib. > Or are you referri

Re: [swift-users] enum compare

2017-01-21 Thread Rien via swift-users
The “==“ operation can only compare concrete instances of the enum. With “type == ACType.other” the right side is not an instance. as the associated value is missing. Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http

Re: [swift-users] enum compare

2017-01-21 Thread Rien via swift-users
Oh, I am not using the correct terminology, sorry. Enum’s don’t have “instances” right? Anyhow, I guess you get my drift… Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 21 Jan 2017, at 14:2

Re: [swift-users] SPM & Library with bridging header

2017-01-21 Thread Rien via swift-users
http://swiftfire.nl > On 22 Jan 2017, at 06:25, Daniel Dunbar wrote: > > What is the glue code you need? > > You can define a C/Obj-C target in the same Swift package, and then use it > from your Swift targets. See: > > https://github.com/apple/swift-package-man

[swift-users] SPM: Specify search paths?

2017-01-24 Thread Rien via swift-users
I am still running into walls with SPM. Is there a way to specify the header and library search paths when using the Swift Package Manager? Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl _

[swift-users] Casting function pointers

2017-01-25 Thread Rien via swift-users
I have a case where a callback has the following signature: @convention(c) (_ ssl: OpaquePointer?, _ num: UnsafeMutablePointer?, _ arg: UnsafeMutableRawPointer?) -> Int32 But to install this callback I have to use a c-function with this signature: SSL_CTX_callback_ctrl (OpaquePointer!, Int32, (

Re: [swift-users] Casting function pointers

2017-01-25 Thread Rien via swift-users
tp://github.com/Balancingrock Project: http://swiftfire.nl > On 25 Jan 2017, at 10:23, Rien via swift-users wrote: > > I have a case where a callback has the following signature: > > @convention(c) (_ ssl: OpaquePointer?, _ num: UnsafeMutablePointer?, _ > arg: UnsafeMutable

Re: [swift-users] Callback in Swift

2017-01-25 Thread Rien via swift-users
> On 25 Jan 2017, at 10:33, John Brownie wrote: > > Thanks, that does it for me, though I had to qualify the Unmanaged with a > type in the first part. > > Rien wrote: >> For the context I passed in: >> >> UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()) >> >> And to get t

Re: [swift-users] Casting function pointers

2017-01-25 Thread Rien via swift-users
Github: http://github.com/Balancingrock Project: http://swiftfire.nl > On 25 Jan 2017, at 19:37, Joe Groff wrote: > > >> On Jan 25, 2017, at 1:23 AM, Rien via swift-users >> wrote: >> >> I have a case where a callback has the following signature: >>

[swift-users] SPM: no such module - System Library Wrapper

2017-01-26 Thread Rien via swift-users
I have created the following packages: 1) SwifterSockets (Swift) 2) COpenSsl (wrapper for system libraries) 3) SecureSockets (Swift, uses SwifterSockets and COpenSsl) Now I want to build a macOS app that uses SecureSockets. I have created the app in the traditional way, via Xcode. In this app I

Re: [swift-users] SPM: no such module - System Library Wrapper

2017-01-26 Thread Rien via swift-users
ave a look at BlueSockets which does the same kind of thing: > > https://github.com/IBM-Swift/BlueSocket > https://github.com/IBM-Swift/BlueSSLService > > There's a wrapper around OpenSSL as well: > > https://github.com/IBM-Swift/OpenSSL.git > > Alex > >>

[swift-users] SPM: how to create cocoa xcode projects?

2017-01-26 Thread Rien via swift-users
Just a quick question, > swift package init —type executable creates an xcode project with a main.swift. I want to create a macOS cocoa based application. How is that best achieved? Or is that not supported yet? Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com G

Re: [swift-users] SPM: how to create cocoa xcode projects?

2017-01-26 Thread Rien via swift-users
es? Rien. > >> On Jan 26, 2017, at 4:24 AM, Rien via swift-users >> wrote: >> >> Just a quick question, >> >>> swift package init —type executable >> >> creates an xcode project with a main.swift. >> >> I want to create

[swift-users] SPM: Library dependency bug?

2017-01-27 Thread Rien via swift-users
I have a system wrapper module/package for openSSL called COpenSsl. I have another package (called SecureSockets) that uses COpenSsl. This works fine. To create a framework, I then added a xcode project to SecureSockets and build the framework. This also works fine. Then I created an App (macO

[swift-users] Custom operators in a framework

2017-02-03 Thread Rien via swift-users
It is possible to define custom operators in a framework, but it is not possible to assign access levels to them. As a consequence they are module internal and cannot be used outside the framework. Each project needs to redefine the custom operators in order to use them in that project. What

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

2017-02-03 Thread Rien via swift-users
I do not think there is a ‘best’ answer. I would go with JSON though. Apple’s JSON solution is fast, but it has some minor limitations and usability is not “up there”. Then again there are third party solutions, for example my own SwifterJSON single-class framework that you can download from g

Re: [swift-users] Custom operators in a framework

2017-02-03 Thread Rien via swift-users
On 03 Feb 2017, at 18:14, Jordan Rose wrote: > > Operator declarations are actually public all the time, not internal. That’s > itself probably a bug, but not the world-limiting one you’re concerned about. > > Jordan > > >> On Feb 3, 2017, at 01:18, Rien via swi

Re: [swift-users] Custom operators in a framework

2017-02-03 Thread Rien via swift-users
tfire.nl >> >> >> >> >> >>> On 03 Feb 2017, at 18:14, Jordan Rose wrote: >>> >>> Operator declarations are actually public all the time, not internal. >>> That’s itself probably a bug, but not the world-limiting one you’re &

Re: [swift-users] Custom operators in a framework

2017-02-03 Thread Rien via swift-users
>>> >>>> And when I use that from another module I get “Operator is not a known >>>> binary operator” >>>> >>>> Once I repeat the "infix operator &=“ at the start of the file it works >>>> fine. >>>> &

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

2017-02-09 Thread Rien via swift-users
> On 09 Feb 2017, at 18:29, Cihat Gündüz via swift-evolution > wrote: > > @Jan: Your arguments are very subjective if not even insulting and derogatory > to many people who invest a lot of time and effort in crafting those things > you despise so openly. Here are just a few example quotes for

[swift-users] UnsafePointer to UInt64

2017-02-16 Thread Rien via swift-users
What would be the easiest (and fastest) way to convert a pointer to an (unsigned)integer? Ptr -> String -> Int seems a bit cumbersome to me :-) Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl

Re: [swift-users] UnsafePointer to UInt64

2017-02-16 Thread Rien via swift-users
> let ptr = UnsafePointer(bitPattern: 123)! > print(ptr) // 0x007b > > // Pointer to Int: > let int = Int(bitPattern: ptr) > print(int) // 123 > > Int has the same size as a pointer on both 32-bit and 64-bit platforms. > > Regards, Martin > >>

Re: [swift-users] ambiguous minus operator

2017-02-16 Thread Rien via swift-users
I don’t know about the candidates But the uptimeNanoseconds is a UInt64 and as such you should probably use substractWithOverflow. var a: UInt64 = 12 var b: UInt64 = 25 let result = UInt64.subtractWithOverflow(a, b) if result.overflow { print("Overflow") } else { let answer = result.0

[swift-users] Function conforming to a typealias

2017-02-18 Thread Rien via swift-users
I want to create a few functions that all have the same signature. The signature is defined in a typealias Is there any way to shortcut the function definition, or alternatively ensure that the function signature will always be equal to the typealias? Examplecode: typealias Mysig = (Int, Bool)

Re: [swift-users] Function conforming to a typealias

2017-02-18 Thread Rien via swift-users
with closures: >> >> typealias Function = (Int, Bool) -> String? >> >> let myGreatFunc1: Function = { _ in return nil /* or whatever you need there >> */ } >> let myGreatFunc2: Function = { _ in return nil } >> >> >> >> >>

Re: [swift-users] Function conforming to a typealias

2017-02-18 Thread Rien via swift-users
gt; let myGreatFunc1: Function = { _ in return nil /* or whatever you need there > */ } > let myGreatFunc2: Function = { _ in return nil } > > > > > -- > Adrian Zubarev > Sent with Airmail > > Am 18. Februar 2017 um 11:47:26, Rien via swift-users (swift-user

Re: [swift-users] Function conforming to a typealias

2017-02-18 Thread Rien via swift-users
. Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl > On 18 Feb 2017, at 12:05, Rien via swift-users wrote: > > It feels a bit strange to write it like that, but yes, that would work.

Re: [swift-users] How to optionally link swift framework into another framework

2017-03-06 Thread Rien via swift-users
You need conditional compilation. Called “Active Compilation Conditions” in the build settings. For example define a ACC of “USE_LOGGING” Then in your code: #if USE_LOGGING import Logging #else struct Logging { func debug(message: string) {} } #endif Regards, Rien Site: http://

Re: [swift-users] How to optionally link swift framework into another framework

2017-03-06 Thread Rien via swift-users
Well, that was a bit short… When you want to use logging, define the ACC “USE_LOGGING” in the build settings. When you don’t want to use logging, don’t define the ACC. PS: You can get my logging framework from github: https://github.com/Balancingrock/SwifterLog Regards, Rien Site: http://bala

Re: [swift-users] How to optionally link swift framework into another framework

2017-03-06 Thread Rien via swift-users
The way I look at it is that Swift wants all symbols resolved when linking. C++ is probably very lenient toward full resolution, and as long as you know that a certain unresolved reference is not used, you can safely ignore the warning. Or maybe the C++ compiler is just very clever and can figure

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

2017-03-06 Thread Rien via swift-users
I don’t think there is a single answer to this. It is all highly dependant on what the application does with the info. Sometimes it will indeed be necessary to rebuild the entire gui, other times it is enough to simply insert a new table cell. Regards, Rien Site: http://balancingrock.nl Blog: h

[swift-users] Generics with variable argument lists

2017-03-09 Thread Rien via swift-users
I am trying to achieve the following: enum FunctionResult { case success(T) case error(String) } func tester(test: (…) -> FunctionResult, onError: (String) -> T) -> T { … } The problem is of course the (…) that simply does not work. I would like to use this generic with a variety of diff

Re: [swift-users] Generics with variable argument lists

2017-03-09 Thread Rien via swift-users
Ah!, yes that would be perfect! Many thanks! Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl > On 09 Mar 2017, at 12:36, Ole Begemann wrote: > > On 09/03/2017 11:05, Rien via sw

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

2017-03-11 Thread Rien via swift-users
> On 11 Mar 2017, at 21:12, Edward Connell via swift-users > wrote: > > Observations about difining an object > • Structs can't inherit and classes shouldn't inherit, final concrete > types should be flat Why? I always default to the position that we should do what works. Get the project

Re: [swift-users] Improving compilation times?

2017-03-23 Thread Rien via swift-users
Thanks for that link, used it to track down the worst compile time offender: This piece of code: public func logAddrInfoIPAddresses(_ infoPtr: UnsafeMutablePointer) -> String { let addrInfoNil: UnsafeMutablePointer? = nil var count: Int = 0 var info: UnsafeMutablePointer = infoP

Re: [swift-users] Improving compilation times?

2017-03-23 Thread Rien via swift-users
str += "No: \(count), HostIp: " + clientIp + " at port: " + service + "\n” Regards, Rien. > > On 23 Mar 2017, at 08:11, Rien via swift-users wrote: > >> Thanks for that link, used it to track down the worst compile time offender: >> >>

Re: [swift-users] Improving compilation times?

2017-03-23 Thread Rien via swift-users
ression-type-checking > > If you use that you’ll see a line for every expression that is type-checked, > with source location information, and the time to type check the expression. > In some cases we may not have valid source information (I believe this > generally happens for thi

Re: [swift-users] Improving compilation times?

2017-03-23 Thread Rien via swift-users
error: unknown argument: '-debug-time-expression-type-checking' >> >> Should I rather compile it on the command line using this option? >> >> Regards, >> Piotr >> >> czw., 23 mar 2017 o 08:54 użytkownik Mark Lacey via swift-users >> napis

[swift-users] @noReturn

2017-03-24 Thread Rien via swift-users
Is there any way to mark a function as “no return”? Reason: The compiler generates an error when the else block from a guard does not terminate the execution by either a return or a fatalError. I want to call out to a function and raise the fatalError in that function. func findReasonAndTermina

Re: [swift-users] @noReturn

2017-03-24 Thread Rien via swift-users
ata() -> Data? > { > return nil > } > > guard let data = buildData() else { findReasonAndTerminate() } > > > On Fri, Mar 24, 2017 at 3:02 AM, Rien via swift-users > wrote: > Is there any way to mark a function as “no return”? > > Reason: The compiler

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Rien via swift-users
IMO this is a boundary problem. How far do you want to go in letting the compiler deduce the actual type? It is possible to make very elaborate constructs that would basically default to a complex tuple/array/dictionary construct with only Any?’s in them. (well, the dict would require a Hashable

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Rien via swift-users
Mar 2017, at 11:22, Rien via swift-users wrote: > > IMO this is a boundary problem. > How far do you want to go in letting the compiler deduce the actual type? > It is possible to make very elaborate constructs that would basically default > to a complex tuple/array/dictionary construc

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Rien via swift-users
g: http://swiftrien.blogspot.com >> Github: http://github.com/Balancingrock >> Project: http://swiftfire.nl >> >> >> >> >> >>> On 24 Mar 2017, at 11:22, Rien via swift-users >>> wrote: >>> >>> IMO this is a boundary problem. >

Re: [swift-users] Importing C system libraries

2017-03-28 Thread Rien via swift-users
I feel your pain ;-) Just embrace the dark side, it takes a little time to get used to, but chances are you won’t regret it. Btw: I still do my development in Xcode, its just that using the SPM (Swift Package Manager) and git from the command line gives a whole extra dimension to my productivi

Re: [swift-users] Swift 3.1 String(

2017-04-05 Thread Rien via swift-users
> On 05 Apr 2017, at 16:26, Maxim Veksler via swift-users > wrote: > > Hi, > > Swift 3.1 compiler seems to introduces a new complier warning regarding > String(describing: ) > > So this line: > Log.info("Update name for user \(fbUser)”) Log.info(“Update name for user \(fbUser ?? “Unknown”)”

Re: [swift-users] Alternative to UnicodeScalar

2017-04-08 Thread Rien via swift-users
Server-side is usually UTF-8 (not always), so often you don’t really need strings. As an aside, time measurements are difficult, especially when IO is involved there may be thread switches or locks. I have written some parsers (UTF-8 based) and not yet encountered performance problems. (though

Re: [swift-users] Alternative to UnicodeScalar

2017-04-08 Thread Rien via swift-users
With the Array operations: append or insert var tmp: [CChar] = [0, 0] for i in 1 ... 100 { tmp.insert(0, at: 0) } Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl - A server for websites build

Re: [swift-users] edit array

2017-04-26 Thread Rien via swift-users
Because you are (trying) to edit a copy. To edit the value in the array itself use: array[index].number += 1 Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl - A server for websites build in Swif

Re: [swift-users] edit array

2017-04-26 Thread Rien via swift-users
Agree, though the function should probably be named something like: withEach instead of forEach. Maybe worth a proposal on evolution? Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl - A server fo

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-26 Thread Rien via swift-users
1) When you obtain a pointer, it can no longer be ensured by the compiler that you won’t write to it. 2) A ‘let’ variable (constant) allows way more optimizations than a ‘var’. I would not be surprised if the majority of ‘let’ constants never see any memory allocation at all. Regards, Rien Sit

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-27 Thread Rien via swift-users
> On 27 Apr 2017, at 09:54, Rick Mann wrote: > >> >> On Apr 26, 2017, at 23:37 , Rien via swift-users >> wrote: >> >> 1) When you obtain a pointer, it can no longer be ensured by the compiler >> that you won’t write to it. >> 2) A ‘let’ v

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-27 Thread Rien via swift-users
To address your question: https://developer.apple.com/reference/foundation/data/1779823-withunsafemutablebytes "Warning The byte pointer argument should not be stored and used outside of the lifetime of the call to the closure." Which is exactly what you are doing, hence the code is unsafe (no

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-27 Thread Rien via swift-users
You will need to take full control over allocation and deallocation. Here is a piece of code from my project SwifterSockets (on github, see the link in my signature) public func tipReceiverLoop( socket: Int32, bufferSize: Int, duration: TimeInterval, receiver: ReceiverProtocol?)

[swift-users] weak self

2017-05-01 Thread Rien via swift-users
In my code I use a lot of queues. And (very often) I will use [weak self] to prevent doing things when ‘self’ is no longer available. Now I am wondering: how does the compiler know that [weak self] is referenced? I am assuming it keeps a reverse reference from self to the [weak self] in order t

Re: [swift-users] weak self

2017-05-01 Thread Rien via swift-users
> On 01 May 2017, at 16:59, Dennis Weissmann wrote: > >> >> On May 1, 2017, at 4:46 PM, Rien via swift-users >> wrote: >> >> In my code I use a lot of queues. And (very often) I will use [weak self] to >> prevent doing things when ‘self’ is no l

Re: [swift-users] weak self

2017-05-01 Thread Rien via swift-users
> On 01 May 2017, at 17:42, Dennis Weissmann wrote: > >> >> On May 1, 2017, at 5:32 PM, Rien wrote: >> >>> >>> On 01 May 2017, at 16:59, Dennis Weissmann >>> wrote: >>> >>>> >>>> On May 1, 2017, at 4:4

Re: [swift-users] weak self

2017-05-01 Thread Rien via swift-users
://swiftfire.nl - A server for websites build in Swift > On 01 May 2017, at 23:26, Guillaume Lessard > wrote: > > Hi Rien, > >> On May 1, 2017, at 08:46, Rien via swift-users wrote: >> >> In my code I use a lot of queues. And (very often) I will use [weak

Re: [swift-users] Making Error sub-enums Equatable

2017-05-08 Thread Rien via swift-users
I’d love to know if there is a better way, but a ‘switch’ or 'if case' is the only way I know. Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl - A server for websites build in Swift > On 08

[swift-users] Generating html code, best practise?

2017-05-19 Thread Rien via swift-users
I want to generate some HTML code with Swift. Of course there are many way to do this, but I am not looking to do an "in-dept all options open” approach. Just some ‘get the html out quickly” type of thing. So I wonder, how do _you_ do this? Simply using Strings is one option, but cumbersome and

Re: [swift-users] Future(of: self.references)?

2017-05-23 Thread Rien via swift-users
I will often use this rule: If a scope need to use ‘self’ at least once, then I will always use ‘self’ in that scope. Otherwise I won’t use ’self’ at all. There are always exceptions though, first and foremost: if the usage of ‘self’ hinders understandability of the code (interferes with self do

  1   2   >