Uint conform to FloatinngPoint, but Int no

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: https://github.com/smud/ConfigFile

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?


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?

Sorry, the link is to the original project 4 years old. I will create a repository with the midified code and Repost here

Ok, created a fork of the project and uploaded it...
the repository is https://github.com/Chetral/Smud.git
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...


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

Thanks a lot... now it's near 1am so I think I will check it tomorrow.

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 {

And now it compile correctly.

Thanks again