Ah, yes. It is possible to ‘store’ it as a fixed string.
But I would still expect the compiler to treat it as if it were a computed
property.
Given that this is a protocol and a protocol cannot define stored properties.
(yet anyway)
OTOH, what do I know about compilers… lol!
Regards,
Rien
It cannot be ‘stored’ I would think.
I always compute my implementations.
Regards,
Rien
Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl - An HTTP(S) web server framework in Swift
> On 08 Sep 2017, at
I was working with very large NSNumber values and noticed some odd behaviour
when converting these values to integers.
An NSNumber with the value +1e+40 will when converted to Ints produce integers
wit the value zero for Int8, UInt8, Int16, UInt16, Int32 and UInt32.
But for Int64 it will
> On 23 Jun 2017, at 18:42, Tony Parker via swift-users
> wrote:
>
> Hi all,
>
> This has come up a few times in recent threads, and I wanted to gather some
> additional info on your real world use cases. Just reply to me, and any input
> is appreciated:
>
> 1. Does
Yes.
But: Only if it makes the code better.
I think that “understandability engineering” is just as important as “software
engineering”. Maybe more so. After all, code that we understand has a better
chance of working correctly than code that follows all paradigms but once the
developer is
Dang, hit send too soon. Sorry.
This does not address your question, so please ignore… (foot in mouth)!
Regards,
Rien
Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl - An HTTP(S) web server framework in Swift
Are you looking for a general purpose JSON interpreter / API ?
There are many of them around, and in fact I do have my own:
https://github.com/Balancingrock/VJson
With VJson I would write:
let json = VJson.parse(… your json object…)
and then access the metadata as:
let buyCount = (json |
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
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
://swiftfire.nl - A server for websites build in Swift
> On 01 May 2017, at 23:26, Guillaume Lessard <gless...@tffenterprises.com>
> wrote:
>
> Hi Rien,
>
>> On May 1, 2017, at 08:46, Rien via swift-users <swift-users@swift.org> wrote:
>>
>> In m
e>
>>> wrote:
>>>
>>>>
>>>> On May 1, 2017, at 4:46 PM, Rien via swift-users <swift-users@swift.org>
>>>> wrote:
>>>>
>>>> In my code I use a lot of queues. And (very often) I will use [weak self]
>>>>
> On 01 May 2017, at 16:59, Dennis Weissmann <den...@dennisweissmann.me> wrote:
>
>>
>> On May 1, 2017, at 4:46 PM, Rien via swift-users <swift-users@swift.org>
>> wrote:
>>
>> In my code I use a lot of queues. And (very often) I will use [w
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
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?)
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
> On 27 Apr 2017, at 09:54, Rick Mann <rm...@latencyzero.com> wrote:
>
>>
>> On Apr 26, 2017, at 23:37 , Rien via swift-users <swift-users@swift.org>
>> wrote:
>>
>> 1) When you obtain a pointer, it can no longer be ensured by the compi
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
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
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
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
> 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
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
Site: http://balancingrock.nl
>> Blog: http://swiftrien.blogspot.com
>> Github: http://github.com/Balancingrock
>> Project: http://swiftfire.nl
>>
>>
>>
>>
>>
>>> On 24 Mar 2017, at 11:22, Rien via swift-users <swift-users@swift.org>
l ?? "?"
str += "No: \(count), HostIp: " + clientIp + " at port: " + service +
"\n”
Regards,
Rien.
>
> On 23 Mar 2017, at 08:11, Rien via swift-users <swift-users@swift.org> wrote:
>
>> Thanks for that link, used it to track d
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 =
> 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
017 11:05, Rien via swift-users wrote:
>> I am trying to achieve the following:
>>
>> enum FunctionResult {
>> case success(T)
>> case error(String)
>> }
>>
>> func tester(test: (…) -> FunctionResult, onError: (String) -> T) -> T {
>&
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
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:
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
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:
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:
.
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 <swift-users@swift.org> wrote:
>
> It feels a bit strange to write it like that, but
ion = (Int, Bool) -> String?
>
> 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
you’re trying to solve there but you could use it like this
>> with closures:
>>
>> typealias Function = (Int, Bool) -> String?
>>
>> let myGreatFunc1: Function = { _ in return nil /* or whatever you need there
>> */ }
>> let myGreatFunc2: Function = {
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,
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
egards, Martin
>
>> On 16 Feb 2017, at 14:27, Rien via swift-users <swift-users@swift.org> wrote:
>>
>> What would be the easiest (and fastest) way to convert a pointer to an
>> (unsigned)integer?
>>
>> Ptr -> String -> Int
>>
>>
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
> 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
;
>>>> I.e. I have a:
>>>>
>>>> infix operator &=
>>>>
>>>> And when I use that from another module I get “Operator is not a known
>>>> binary operator”
>>>>
>>>> Once I repeat the
ttp://github.com/Balancingrock
>> Project: http://swiftfire.nl
>>
>>
>>
>>
>>
>>> On 03 Feb 2017, at 18:14, Jordan Rose <jordan_r...@apple.com> wrote:
>>>
>>> Operator declarations are actually public all the time, not internal
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
ding on a bunch
of SPM packages?
Rien.
>
>> On Jan 26, 2017, at 4:24 AM, Rien via swift-users <swift-users@swift.org>
>> wrote:
>>
>> Just a quick question,
>>
>>> swift package init —type executable
>>
>> creates an xcode project
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
com> wrote:
>
> Have 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
>
>
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl
> On 25 Jan 2017, at 19:37, Joe Groff <jgr...@apple.com> wrote:
>
>
>> On Jan 25, 2017, at 1:23 AM, Rien via swift-users <swift-users@swift.org>
>> wrote:
>>
>> I have a case
> 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:
>>
>>
tp://github.com/Balancingrock
Project: http://swiftfire.nl
> On 25 Jan 2017, at 10:23, Rien via swift-users <swift-users@swift.org> wrote:
>
> I have a case where a callback has the following signature:
>
> @convention(c) (_ ssl: OpaquePointer?, _ num: UnsafeMutablePointer
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,
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
t;
>> And pkgConfig cannot be used on a non-system module.
>>
>> But without specifying the import search path, SPM cannot compile the c-code.
>>
>> Any suggestions?
>>
>> Regards,
>> Rien
>>
>> Site: http://balancingrock.nl
>>
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
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:
20 Jan 2017, at 19:48, Rien via swift-users <swift-users@swift.org> 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 crea
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
://github.com/Swiftrien
Project: http://swiftfire.nl
> On 11 Jan 2017, at 10:28, Rien via swift-users <swift-users@swift.org> wrote:
>
> My project uses openSSL and that works fine.
>
> I needed one specific function that cannot be accessed from Swift directly,
> so I created
://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 <jgr...@apple.com> wrote:
>
>
>> On Jan 9, 2017, at 11:19 PM, Rien via swift-users <swift-users@swift.org>
>> w
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
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
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:
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,
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
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
M, Howard Lovatt via swift-users
>>> <swift-users@swift.org> wrote:
>>>
>>> I suspect a compiler bug since A is a P. The equivalent in Java works:
>>>
>>> interface P {}
>>> class X implements P {}
>>>
>>> void foo(A
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:
ired. 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
>>> <swift-users@swift.org> wrote:
>>>
>
, at 02:49, Zhao Xin <owe...@gmail.com> wrote:
>>
>> 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
>> <sw
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
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
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
> 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))
>
> 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
> 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:
> 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
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:
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
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
78 matches
Mail list logo