Skip to content

[SR-15124] UserDefaults string(forKey:) behaves different on Linux and macOS #3362

Closed
@Nef10

Description

@Nef10
Previous ID SR-15124
Radar rdar://problem/82537716
Original Reporter @Nef10
Type Bug
Environment

Swift 5.4

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

md5: 3414fbf73d52305cd8edd91052896a16

Issue Description:

import Foundation
UserDefaults.standard.set(2, forKey: "a")
print(UserDefaults.standard.integer(forKey: "a"))
print(UserDefaults.standard.string(forKey: "a") ?? "it is nil")

On Linux it outputs:
2
it is nil

On macOS:
2
2

The documentation states:

For string values, the string associated with the specified key; for number values, the string value of the number. Returns nil if the default does not exist or is not a string or number value

Which makes the macOS behaviour correct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions