vincentneo / CoreGPX

A library for parsing and creation of GPX location files. Purely Swift.
https://www.vincent-neo.com
MIT License
261 stars 57 forks source link

Fix build errors on Linux #92

Closed Gerzer closed 3 years ago

Gerzer commented 3 years ago

The String(format:_:) initializer, the NSMutableString() initializer, and NSMutableString's appendFormat(_:) method are unavailable on Linux, so I replaced them with functionally equivalent alternatives. Additionally, on Linux, the various XML classes in Foundation have been relocated to FoundationXML, so I added a conditional import for it.

vincentneo commented 3 years ago

@Gerzer actually, would using Swift String be even better than using NSMutableString, multi-platform wise?

Not very sure of Swift things happening outside the Apple ecosystem, hence asking for your opinion on this.

Gerzer commented 3 years ago

@Gerzer actually, would using Swift String be even better than using NSMutableString, multi-platform wise?

Not very sure of Swift things happening outside the Apple ecosystem, hence asking for your opinion on this.

Yes, String is much more portable than NSMutableString. For this pull request, I tried to make the minimum number of changes possible, but in the future, it would be a good idea in general to switch to types from the Swift standard library instead of types from Foundation. Of course, sometimes there won't be any equivalents, but for basic things like strings, the Swift standard library offers sufficient functionality and is (almost) fully portable to Linux and other non-Apple platforms.

vincentneo commented 3 years ago

@Gerzer Thanks for the info & pull request! Currently this pull request looks good to me, so I will be merging this pull request, and will eventually try to migrate from NSMutableString to String in the future.