UserDefaults sometimes does not save

Originator:pzabelin
Number:rdar://36054294 Date Originated:14-Dec-2017
Status:Open Resolved:
Product:iOS Product Version:11.2
Classification:Data Loss Reproducible:Often
 
Area:
Foundation

Summary:
We use UserDefaults to store whether user saw the app onboarding. We see that setting is not persistent sometimes.

Steps to Reproduce:
Download and open this project in Xcode 9.2
https://github.com/omadahealth/UserDefaultsBug
or see the attached project.

Expected Results:
UI Test pass all the time

Actual Results:
UI Test fails sometimes (about 1 in 3 times)

Version/Build:
iOS 11.2 Xcode 9.2

Configuration:
iPhone X Simulator and Device.

Comments

Failed in Xcode 13.1

Failed in Xcode Version 13.1 (13A1030d), on 5th run of tests:

t =    11.12s             Find: Elements matching predicate '"onboarding not seen" IN identifiers'

UserDefaultsBug/DefaultsBugUITests/DefaultsBugUITests.swift:20: error: -[DefaultsBugUITests.DefaultsBugUITests test1FromNotSeenToSeen] : Failed to get matching snapshot: No matches found for Elements matching predicate '"onboarding not seen" IN identifiers' from input {( Button, label: 'onboarding seen' )}

By alec.vance at Nov. 2, 2021, 10:03 p.m. (reply...)

49809943 - Same issue with Xcode 10.2 and iOS 12.2

Filed again as 49809943 as it fails on the latest Xcode 10.2


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!