Chetral
(Chetral)
1
Hi all,
I'm tryng to "refresh" an old project about a MUD engine in Swift.
This is the GIT link of the code I have problem to replace in Swift 5: GitHub - smud/ConfigFile: Configuration file parser for Swift
In the [ConfigFile+Subscript.swift] there are subscription for the class ConfigFile.
I got errors in the get-set because Int, Int8... Int64 to not conforms to to FloatingPoint Protocol, but the Unsigned type does.
There's a reason for that?
And there is a simple way to bypass the problem?
Thanks,
Marco
For the love of me, I couldn't get your project structure to work with current Xcode so I don't really know what' going on. But no integer types (including unsigned ones) conform to FloatingPoint. Did you add those conformance yourself?
Chetral
(Chetral)
3
Sorry, the link is to the original project 4 years old. I will create a repository with the midified code and Repost here
Chetral
(Chetral)
4
Ok, created a fork of the project and uploaded it...
the repository is GitHub - Chetral/Smud: MUD Server for Swift
the problem is in this file: Sources/Smud/ConfigUtils/ConfigFile+Subscript.swift
So far I've taken the original project (Smud/smud) and updated the language structure.
The original project is splitted in several Module, since all of them are 4 years old, instead of forking (exist in english?) them all I have directly added them to the project.
Right now the project do not compile due to the problem of this topic, maybe there are some other issues...
Thanks,
Marco
Ok, I see the problem now.
Let's clear the misunderstanding first. The unsigned versions works fine, not because UInt* conform to FloatingPoint. As I said, they are not. The reason it works is because the conform to UnsignedInteger, and you provided that the function in ConfigFile.swift: line 290. Then for Int version, it couldn't find anything, and just guess that another one for FloatingPoint in ConfigFile.swift: line 281 is the closest version (which still doesn't match), hence the error.
Now, I don't know the exact semantic of your ConfigFile, but I have two plausible suggestions:
-
Extend the UnsignedInteger version mentioned above to a more general BinaryInteger, which encompasses both signed and unsigned version.
-
Add new version for Int*. There are a few protocols you can use. SignedInteger, BinaryInteger, FixedWidthInteger, just to name a few.
I'd suggest that you use SignedInteger since that wouldn't overlap with the existing UnsignedInteger and confuse the compiler.
1 Like
Chetral
(Chetral)
6
Thanks a lot... now it's near 1am so I think I will check it tomorrow.
Chetral
(Chetral)
7
As you said.
I added:
// correction for set get -- Swift forum Lantua
public func set(_ name: String, _ value: T?) where T: SignedInteger{
if let value = value {
set(name, String(describing: value))
} else {
reset(name)
}
}
And now it compile correctly.
Thanks again
Marco