Code Monkey home page Code Monkey logo

swift-foundation's Introduction

Foundation

Foundation provides a base layer of functionality useful in many applications, including fundamental types for numbers, data, collections, and dates, as well as functions for task management, file system access, and more.

It is designed with these goals in mind:

  • Provide a small set of basic utility types
  • Enable a level of platform independence, to enhance portability
  • Demonstrate useful conventions that can be widely adopted by the Swift ecosystem
  • Support internationalization and localization to make software accessible around the world

This project, swift-foundation, provides a shared implementation of key Foundation API for all platforms.

On macOS, iOS, and other Apple platforms, apps should use the Foundation that comes with the operating system. The Foundation framework includes this code.

On all other Swift platforms, swift-foundation is available as part of the toolchain. Simply import FoundationEssentials or import FoundationInternationalization to use its API. It is also re-exported from swift-corelibs-foundation's Foundation, FoundationXML, and FoundationNetworking modules.

Building and Testing

Note

Building swift-foundation requires the in-development Swift 6.0 toolchain. You can download the Swift 6.0 nightly toolchain from the Swift website.

Before building Foundation, first ensure that you have a Swift toolchain installed. Next, check out the Getting Started section of the Foundation Build Process guide for detailed steps on building and testing.

Project Navigator

Foundation builds in different configurations and is composed of several projects.

  graph TD;
      FF[Foundation.framework]-->SF
      subgraph GitHub
        SCLF[swift-corelibs-foundation]-->SF
        SF[swift-foundation]-->FICU[swift-foundation-icu]
        SF-->SC[swift-collections]
      end   
Loading

Swift Foundation

A shared library shipped in the Swift toolchain, written in Swift. It provides the core implementation of many key types, including URL, Data, JSONDecoder, Locale, Calendar, and more in the FoundationEssentials and FoundationInternationalization modules. Its source code is shared across all platforms.

swift-foundation depends on a limited set of packages, primarily swift-collections and swift-syntax.

Swift Corelibs Foundation

A shared library shipped in the Swift toolchain. It provides compatibility API for clients that need pre-Swift API from Foundation. It is written in Swift and C. It provides, among other types, NSObject, class-based data structures, NSFormatter, and NSKeyedArchiver. It re-exports the FoundationEssentials and FoundationInternationalization modules, allowing compatibility for source written before the introduction of the swift-foundation project. As these implementations are distinct from those written in Objective-C, the compatibility is best-effort only.

swift-corelibs-foundation builds for non-Darwin platforms only. It installs the Foundation umbrella module, FoundationXML, and FoundationNetworking.

Foundation ICU

A private library for Foundation, wrapping ICU. Using a standard version of ICU provides stability in the behavior of our internationalization API, and consistency with the latest releases on Darwin platforms. It is imported from the FoundationInternationalization module only. Clients that do not need API that relies upon the data provided by ICU can import FoundationEssentials instead.

Foundation Framework

A framework built into macOS, iOS, and all other Darwin platforms. It is written in a combination of C, Objective-C, and Swift. The Foundation framework compiles the sources from swift-foundation into its binary and provides one Foundation module that contains all features.

Governance

Foundation's goal is to create the best fundamental data types and internationalization features, and make them available to Swift developers everywhere. It takes advantage of emerging features in the language as they are added, and enables library and app authors to build higher level API with confidence.

This project is part of the overall Swift project. It has a workgroup to (a) oversee community API proposals and (b) to closely coordinate with developments in the Swift project and Apple platforms. The workgroup meets regularly to review proposals, look at emerging trends in the Swift ecosystem, and discuss how the library should evolve.

Contributions

Foundation welcomes contributions from the community, including bug fixes, tests, documentation, and ports to new platforms.

We use the Swift forums for discussion and GitHub Issues for tracking bugs, feature requests, and other work.

Please see the CONTRIBUTING document for more information, including the process for accepting community contributions for new API in Foundation.

swift-foundation's People

Contributors

azoy avatar compnerd avatar cthielen avatar etcwilde avatar finagolfin avatar glessard avatar gwynne avatar hristost avatar hyp avatar icharleshu avatar itingliu avatar jacoblukas avatar jmschonfeld avatar joey-gm avatar jrflat avatar kateinoigakukun avatar koher avatar kperryua avatar lamtrinhdev avatar lorentey avatar nnabeyang avatar nonsensery avatar ojun9 avatar oscbyspro avatar parkera avatar ser-0xff avatar stephentyrone avatar themomax avatar tkremenek avatar wadetregaskis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-foundation's Issues

Support lower case UUID serialization

The UUID and NSUUID types have long been slightly out of compliance with RFC 4122, which specifies that the string representation of UUIDs should be in lower case. (I believe NSUUID has always used upper case in part because it predates that RFC?)

The use of upper case creates problems when interacting with external APIs that generate and send UUID values in their responses (in lowercase, as per the RFC) but expect exact string matches for these values in subsequent requests: a round-trip through a Swift using UUID will result in the value being transformed into an upper case spelling.

In my own projects, I've taken to using a LowercaseUUID type which wraps a UUID and overrides uuidString, description, and encode(to:) to apply a .lowercased() transformation in each case. However, it would be preferable if there was a way to specify this behaviour directly within Foundation, and it seems to me that this project presents an opportunity add this or alter the default.

Calling Date.description might result in undefined behaviour

Date’s description function uses a fixed size buffer (26 bytes, see here). This buffer is given to strftime.

Both, dates before β€œ-999-01-01 00:00:00 +0000” and starting at β€œ10000-01-01 00:00:00 +0000”, will require 27 bytes or more (including null byte at the end).

The return value of this function is checked by guard strftime(…) >= 0 (see). While most library functions in C return a negative value on failure, strftime returns 0 if the buffer is not big enough to hold the formatted date. Thus this guard never executes.

The buffer in this case is not guaranteed to contain a ending null byte, as the man page states: β€œOtherwise, 0 shall be returned and the contents of the array are unspecified.” (Highlighting mine)

The undefined content (worst case: 26 bytes forming valid UTF-8, e.g. 26 spaces) is then given to String(validatingUTF8:) which probably will (in the worst case) run behind the end of the buffer, resulting in a crash.

I suggest to either replace the call to strftime by a better API or change the buffer size to be big enough to hold any description of any point in time that Date might represent. In addition to that, the guard should be changed to guard strftime(…) >= 25 given that is the smallest valid size.

test cases:

Date(timeIntervalSinceReferenceDate: TimeInterval(-63145526400)).description == "0000-01-01 00:00:00 +0000"
Date(timeIntervalSinceReferenceDate: TimeInterval(-4200000000000)).description == "-131090-12-30 21:20:00 +0000"
Date(timeIntervalSinceReferenceDate: TimeInterval(4200000000000)).description == "15310-04-10 02:40:00 +0000"

UUID

Umbrella issue tracking UUID

Locale

Umbrella issue tracking Locale.

[SR-15255] Windows: Calling URL(contentsOf:) repeatedly crashes

Previous ID SR-15255
Radar None
Original Reporter @adam-fowler
Type Bug
Environment

Run inside GitHub action using `compnerd/gha-setup-swift`

jobs:
  windows:
    runs-on: windows-latest
    steps:
      - uses: compnerd/gha-setup-swift@main
        with:
          branch: swift-5.5-release
          tag: 5.5-RELEASE
      - uses: actions/checkout@v2
      - run: swift test

I don't have a Windows setup so cannot test locally

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: fad9bd9ca6233534ee2375c19875deab

Issue Description:

The following code crashes on Windows.

func testURLs() throws {
    for _ in 0..<20 {
        if let url = URL(string: "https://raw.githubusercontent.com/jmespath/jmespath.test/master/tests/filters.json") {
            _ = try Data(contentsOf: url)
        }
    }
}

Date

Umbrella issue tracking Date

Implement `Locale.canonicalIdentifier`

Locale's canonicalIdentifier depends on a table in CoreFoundation: https://github.com/apple/swift-corelibs-foundation/blob/main/CoreFoundation/Locale.subproj/CFLocaleIdentifier.c

Without support for constant collections in Swift, a naive port of this would result in a pretty large allocation and memory usage regression. We may be able to take advantage of some of ICU's support for canonicalization, but we will need to verify compatibility with the existing implementation. Some callers may be expecting some of the legacy conversions to continue to work.

Swift 5.8 regression: `Bundle` is no longer `Sendable`

Description

Bundle was Sendable in Swift 5.7.x. Starting with Xcode 14.3 beta 1 and Swift 5.8 I see that that extension has been marked unavailable:

@available(*, unavailable)
extension Bundle : @unchecked Sendable {}

Was that intended?

Environment

  • Swift: swift-driver version: 1.75.1 Apple Swift version 5.8 (swiftlang-5.8.0.117.11 clang-1403.0.22.8.60)
  • Xcode: 14.3 (14E5197f)
  • Deployment target: iOS 12.0

Transition from toolchain Foundation to package

In the Swift 6 timeframe, we should see if we can stop including swift-corelibs-foundation in the Linux toolchain completely, and transition clients to the package.

It's unclear what kind of knock-on effects this may have on existing clients which import Foundation, and Swift package manifests which have an import Foundation themselves for usage of the Bundle type.

Decimal

Umbrella issue to track Decimal.

Consider fate of `Decimal`

Decimal is used by a few core types in Essentials, but it probably also needs some updates to be a better citizen in Swift. In ObjC it is a C struct, so it would be difficult to share the sources exactly.

FormatStyles

Umbrella issue to track all FormatStyle and ParseStrategys.

ISO8601DateFormatter does not handle extreme dates

Description

ISO8601 standard allows representing years before 0000 or after 9999 using a "-" or "+" sign as prefix to four digits (Β±YYYYY). Apparently, there is no option in Swift's current ISO8601DateFormatter that enables such formatting, which causes errors in systems where there is such an agreement with client and server to follow that standard option.

Steps to reproduce

import Foundation

let date = Date(timeIntervalSince1970: 253402300800) // January 1, 10000
let formatter = ISO8601DateFormatter()

let formattedDateString = formatter.string(from: date) // "10000-01-01T00:00:00Z"

print(formattedDateString)

Expected behavior

Expected formattedDateString to be "+10000-01-01T00:00:00Z" (either with the default ISO8601DateFormatter implementation or with an option provided within the ISO8601DateFormatter.Options and setting it on formatter instance explicitly) in order to be compliant with ISO8601.

Environment

  • Swift compiler version info
    • swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
    • Target: arm64-apple-macosx12.0

Calendar

Umbrella issue tracking Calendar

Locale.current returns en_US even when the user's locale settings is different on Linux

I'm using Swift Language on a Linux system

My OS Distro is Fedora 37 on an ARM64 CPU
I'm using Swift version 5.7.3 (swift-5.7.3-RELEASE) from the Fedora repos

I'm using GNOME desktop and have set my user session language to spanish, and my region to Mexico

When I run the locale command on a terminal, I get this output:

LANG=es_ES.UTF-8
LC_CTYPE="es_ES.UTF-8"
LC_NUMERIC=es_MX.UTF-8
LC_TIME=es_MX.UTF-8
LC_COLLATE="es_ES.UTF-8"
LC_MONETARY=es_MX.UTF-8
LC_MESSAGES="es_ES.UTF-8"
LC_PAPER=es_MX.UTF-8
LC_NAME="es_ES.UTF-8"
LC_ADDRESS="es_ES.UTF-8"
LC_TELEPHONE="es_ES.UTF-8"
LC_MEASUREMENT=es_MX.UTF-8
LC_IDENTIFICATION="es_ES.UTF-8"
LC_ALL=

But when I reference Locale.current, either on a compiled program, or from the Swift REPL, I get a "en_US" Locale. For example, if I run print (Locale.current.identifier) on the REPL, i get:

en_US

I think the expected behavior is that Locale.current returns the same locale from my user settings. Or am I missing something?

Un-deprecate contiguous ASCII

The swift stdlib deprecated _isContiguousASCII, but Foundation depends on it for String extensions.

Is there a better entry point to use, or should we remove the deprecation from stdlib?

/swift-foundation/Sources/FoundationEssentials/String/String+Essentials.swift:109:70: warning: '_isContiguousASCII' is deprecated
            if encoding == .utf8 || (encoding == .ascii && str._guts._isContiguousASCII) {

Investigate behaviour differences of `strftime` between Windows, Linux and Darwin

Currently, Date.description contains a large stack allocation of 128 bytes:

let bufferSize = 128
return withUnsafeTemporaryAllocation(of: CChar.self, capacity: bufferSize) { buffer in

This allocation is almost certainly larger than necessary, but the behaviour of strftime, the C-library call being wrapped here, should be explored on Windows before we shrink the allocation size.

Inconsistent formatting behavior when BinaryInteger cannot be converted into Int64

ICUNumberFormatter doesn't support UInt64 number formatting. Integers not representable by Int64 are clamped as per documentation.

Under current implementation, however, if a BinaryInteger cannot be converted into Int64, IntegerFormatStyle will first attempt to convert the integer into Decimal (represented by Double) before falling back to clamping. This may result in inconsistent formatting behavior.

One edge case is 9223372036854775808 (Int64.max + 1). This integer can be converted to a floating-point value (9.223372036854776E+18), which will then be formatted into "9" instead of the the clamped number of 9,223,372,036,854,775,807 (Int64.max).

Should we drop the Decimal conversion in IntegerFormatStyle?

  • IntegerFormatStyle: Lines 221-222
  • IntegerFormatStyle.Percent: Lines 253-254
  • IntegerFormatStyle.Currency: Lines 285-286
  • AttributedString: Lines 512-513

Personally, I would prefer to drop the Int64 clamping as well and fall back to the Swift Standard Library's LosslessStringConvertible: String(value). This will allow us to preserve the correct numeric value albeit incorrect format. Ideally, we should have a proper implementation for UInt64 number formatting.

/// Returns a localized string for the given value. Supports up to 64-bit signed integer precision. Values not representable by `Int64` are clamped.
/// - Parameter value: The value to be formatted.
/// - Returns: A localized string for the given value.
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
public func format(_ value: Value) -> String {
if let nf = ICUNumberFormatter.create(for: self) {
let str: String?
// Formatting Int64 is the fastest option -- try that first.
if let i = Int64(exactly: value) {
str = nf.format(i)
} else if let decimal = Decimal(exactly: value) {
str = nf.format(decimal)
} else {
str = nf.format(Int64(clamping: value))
}

} else if let decimal = Decimal(exactly: value) {
str = nf.format(decimal)

} else if let decimal = Decimal(exactly: value) {
str = nf.format(decimal)

} else if let decimal = Decimal(exactly: value) {
numberValue = .decimal(decimal)

`URL` implementation for `file` scheme only

Until we have full parsing of URL strings ported, provide a URL implementation that works with at least file schemes. This should unblock usage of Data and a few other key cases.

[SR-3597] CharacterSet isEmpty method failing

Previous ID SR-3597
Radar None
Original Reporter Nteissler (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, CharacterSet
Assignee None
Priority Medium

md5: 27b6a52ddd0420df6cf1819fe7ce0c67

Issue Description:

I was trying to user CharacterSet to check if a user input string contains any non decimal digit characters. I use CharacterSet.decimalDigits and take the intersection of that with the user input. If this intersection is empty, it presumably means the user hasn't entered valid input. Yet the intersection is not empty.

let digits = CharacterSet.decimalDigits  
let letters = CharacterSet(charactersIn: "abcd") // never prints

let intersection = digits.intersection(letters)  
for c in "abcd".characters {  
  if intersection.contains(UnicodeScalar(String(c))!) {  
    print("contains \(c)") // never prints  
  }  
}

for i in 0...9 {  
  if intersection.contains(UnicodeScalar(String(i))!) {  
    print("contains \(i)")  
  }  
}

print("intersection is empty: (intersection.isEmpty)") // prints false

I even tried looping over all unicode scalars to test for membership, and that doesn't print anything.

for i in 0x0000...0xFFFF {  
  guard let c = UnicodeScalar(i) else {  
    continue  
  }  
  if intersection.contains(c) {  
    print("contains \(c)")  
  }  
}

Why is the set non empty?

Note: using let digits = CharacterSet(charactersIn: "1234567890") works as expected. I know that the decimalDigits contains more than just 0-9, but the intersection should still be empty.

URL

Umbrella issue to track URL.

Reconsider FormatStyle's Codable requirement

I know FormatStyle in "classic" Foundation (what do we call the other Foundation?) is Codable but it's unclear exactly why it needs to be. The Codable requirement can get in the way of implementing our own FormatStyles that use non-codable types - in particular closures.

Unless there's a compelling reason for swift-foundation's FormatStyle to be codable (quick scan through code didn't find anything) other than "it's Codable in Foundation" might it not be a good idea to remove the requirement?

A common challenge formatting certain date intervals

Sometimes, I get a design that requires me to format a date interval for a week in such a way that does not include the day of the next week. There have been multiple times where I have had to manually make this calculation. As far as I can tell, there is no API to simplify formatting a date interval in this manner. What follows is a case for an API on Calendar to make this calculation more idiot-proof.

Consider a UI listing "to dos" between the start of this week but before the start of the next. I would like to have a heading that reads "Monday, 22 May, 2023 - Sunday, 28 May, 2023". But if I format the date interval for the week of year as I get it from Calendar now, I'd get "Monday, 22 May, 2023 - Monday, 29 May, 2023", which makes me think I have an extra day to do things in. To work around this, I can compute different dates, writing:

let date = /* some moment during some week */
let weekOfYearInterval = calendar.dateInterval(of: .weekOfYear, for: date)
let lastSecondOfLastWeekday = calendar.date(byAdding: .second, value: -1, to: date) ?? date // not sure what to coalesce here
let dateIntervalToFormat = DateInterval(start: weekOfYearInterval.start, end: lastSecondOfLastWeekday)

But I do not know if dateIntervalToFormat was calculated correctly. What tricky edge case awaits my users and I after I ship? Perhaps it's good but I'm not a calendar expert. From what little I know, I think any moment matching this predicate will suffice:
moment >= (the start of the day before the start of the next week) && moment < (start of the next week)
...but I am aware that I can also be a clueless idiot.

Formatting these intervals could be more convenient. Some ways they could be more convenient include:

  • a Calendar API for calculating "some moment in a second/minute/hour/day/month/year before/after some date"
  • a property on the formatter that treats the date interval as an inequality, rendering the end date to at some moment before.

The last option doesn't strike me as particularly good because it could create complexity in other formatting cases. Perhaps I lack imagination. So, if I could wish upon a star, a Calendar API for the first option could be:

func dateInterval(of component: Calendar.Component, direction: Calendar.SearchDirection, relativeTo date: Date) -> DateInterval

Then I could write my code above as:

let date = /* some moment during some week */
let weekOfYearInterval = calendar.dateInterval(of: .weekOfYear, for: date)
let lastSecondOfLastWeekday = calendar.dateInterval(of: .second, direction: .backward, relativeTo: weekOfYearInterval.end)
let dateIntervalToFormat = DateInterval(start: weekOfYearInterval.start, end: lastSecondOfLastWeekday.start)

I do not think there could reasonably be an API on Calendar to simplify this code any further. For example, to get it to one line, I'd need something like this:

let date = /* some moment during some week */
let almostCompleteWeekOfYearInterval = calendar.dateInterval(of: .weekOfYear, for: date, endingAtLowerComponents: true, direction: .backwards)

...but oooof πŸ™ˆ

Calendar quarter handling not implemented

I find it highly irritating, that even though the "quarter" date component is public and available, it is not implemented in Calendar. I think this is really not a good developer experience, either it should be implemented or removed from all date component APIs.

Predicate

Umbrella issue for tracking moving Predicate to FoundationPreview

The issue with NumberFormatter() and Locale.current

Description
This bug is related to nil object returned when formatting using number formatter. When we changed the device location to spain it returned all nil values and for other locations it returns the exact expected formatted number.

Steps to reproduce
To reproduce it you have to use the following code snippet
let formatter = NumberFormatter()
formatter.locale = Locale.current
formatter.numberStyle = .decimal
let number = formatter.number(from: amount)

Once you build the app change the device location and you will see that this function returns nil value. For example number = nil

Expected behavior
Once the code snippet is executed it should set number as formatted amount based on the formatter applied.

Environment

  • Swift compiler version info swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
    Target: arm64-apple-macosx13.0
  • Xcode version info 14.3 (14E222b)
  • Deployment target: 11.0

`Decimal.FormatStyle` does not always respect the locale's decimalSeparator

Description
Decimal.FormatStyle does not always respect the locale's decimalSeparator, also, the same error occurs with FloatingPointFormatStyle

Steps to reproduce
1- Set the iPhone region to Germany.
2- Set the iPhone language to English (US).
3- Set the Number Format decimal separator to period instead of the default comma.

Expected behavior

    let number: Decimal = 1.5

    let newFormatter = Decimal.FormatStyle.number
    let newResult = number.formatted(newFormatter) // 1,5 ❌

    let oldFormatter = NumberFormatter()
    oldFormatter.numberStyle = .decimal

    let oldResult = oldFormatter.string(from: number as NSNumber)! // 1.5 βœ…

IMG_2957 Medium

Environment

  • Swift version: 5.7
  • Xcode version: 14.2
  • Deployment target: iOS 16.3

TimeZone

Umbrella issue tracking TimeZone

Bundle

Umbrella issue tracking Bundle.

Improve use of memory binding in FoundationPreview

Most of the code in this project predates SE-0333, and has had to use the assumingMemoryBound(to:) and bindMemory() functions to adapt raw memory buffers to C function calls. Since then, the withMemoryRebound function was added for raw memory buffers and pointers. In most cases, withMemoryRebound is the correct function to use, as it only changes the state of memory binding within its closure, reverting it afterwards.

Data + IO

Sub feature under #220 tracking Data IO related tasks (such as write(to:options:)

Data

Umbrella issue tracking Data and friends

Tasks

Re-enable testAPIStatement

The testAPIStatement test winds up using a Swift string processing symbol that is marked available as of 5.8 but is actually only available in 5.9.

CharacterSet

Umbrella issue for CharacterSet and friends.

This one might be slightly more tricky because the original NSCharacterSet APIs are not exactly great in Swift. We might (should?) also take this chance to rethink about CharacterSet's API surface.

Compiling on Linux throws error

Hello. I tried to compile my new test project with swift-foundation. But in linker step it throws following errors:

#0 265.7 error: link command failed with exit code 1 (use -v to see invocation)
#0 265.7 /usr/bin/ld.gold: error: /usr/lib/swift_static/linux/libicui18nswift.a(decNumber.ao): multiple definition of 'uprv_decNumberClass(decNumber const*, decContext*)'
#0 265.7 /usr/bin/ld.gold: /build/.build/x86_64-unknown-linux-gnu/release/ICUI18N.build/decNumber.cpp.o: previous definition here
#0 265.7 clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

In my project I include swift-foundation using this code

#if canImport(FoundationEssentials)
import FoundationEssentials
import FoundationInternationalization
#else
import Foundation
#endif

What's wrong and how I can fix it?

Sink a stub `Locale` to FoundationEssentials

It would be nice if Essentials could have some basic support for formatting well-known date types like ISO8601 without relying upon the entire data set of ICU.

Locale could be sunk into Essentials with support for only a "system" locale (en_US-POSIX). Following this, we would be able to bring over the FormatStyle and ParseStrategy protocols from Internationalization, which would then unblock a new API for JSONEncoder and JSONDecoder to use them instead of the classic Formatter for their own Date-parsing behaviors.

Test case testSettingLocale fails

Description

testSettingLocale in DateAttributedFormatStyleTests fails as shown in the following image.

γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ 2023-05-15 22 44 03

This is caused by the fact that the result of formatting the string deviates from the actual time by 9 hours.
I am running on a macOS system that is set to a time difference of 9 hours from en_US, and it seems odd that the 9-hour time difference appears even though the Locale is set to en_US in the code.

Is this a problem with Date.FormatStyle?
Is there any information I should look at to fix this issue?

Expected behavior

Successful testing in any execution environment

Environment

OS: macOS 13.3.1(Apple M1οΌ‰
Swift: Swift 5.9
Xcode: Xcode 14.3 (14E222b)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.