XCTAssertEqual failed: ("nan") is not equal to ("nan") in Swift
When I run the following test case, I get XCTAssertEqual failed: ("nan") is not equal to ("nan")
error.
XCTAssertEqual(0.0 / 0.0, Double.nan)
How can I fix this error?
1 answer
do you know?
how many words do you know
See also questions close to this topic
-
SwiftUI, apply drawGesture only when over Image
I'm try to apply the gesture only when the user is over the Image display not when tapped outside the image.
Any suggestion how I can do? this following code draw also when user tap outside the image.
struct ContentView: View { @StateObject var am = AppManager() @State var switchToTakePicture = false @State var paths: [PathContainer] = [] @State var currentDraggingId = UUID() @State var spikoPic = #imageLiteral(resourceName: "spiko-16.jpeg") @State var centerOFimage = CGSize(width: 0, height: 0) var body: some View { GeometryReader { proxy in ZStack { Image(uiImage: spikoPic) .resizable() .scaledToFit() .position(x: proxy.size.width/2, y: proxy.size.height/2) .background(GeometryReader { Color.clear.preference(key: ViewRectKey.self, value: [$0.frame(in: .global)]) }) .gesture(drawGesture) // not correct ForEach(paths) { container in // draw and set the foreground color of the paths to red container.path .stroke(Color.red, lineWidth: 4) } } .onPreferenceChange(ViewRectKey.self) { rects in print(rects.first ?? .zero) } } } var drawGesture: some Gesture { DragGesture(minimumDistance: 0) .onChanged { value in // The point that the gesture started from let start = value.startLocation // The point that the gesture ended to let end = value.location // the properties of the rectangle to be drawn let rectangle: CGRect = .init(origin: end, size: .init(width: start.x - end.x, height: start.y - end.y)) // create a path for the rectangle let path: Path = .init { path in path.addRect(rectangle) } print("rettangolo = \(rectangle) orig \(rectangle.origin) - height \(rectangle.height) width = \(rectangle.width)") // remove the previous rectangle that was drawen in current // process of drawing paths.removeAll { $0.id == currentDraggingId } // append the new rectangle paths.append(.init(id: currentDraggingId, path: path)) } .onEnded { _ in // renew the dragging id so the app know that the next // drag gesture is drawing a completely new rectangle, // and is not continuing the drawing of the last rectangle currentDraggingId = .init() } } }
i want no box outside
-
How to navigate between NavigationLink while leave a part of main window stay the same in SwiftUI
I would like to navigate between different
NavigationLink
s inNavigationView
while some part of the main window stay the same. For example, I want to make a music app and I want to let the play controller always on top, while I can display different navigation contents (songs page, artists page...) using the rest of the window.Like what's showed in the picture below, I want to keep the red part always there while the blue part changes.
My code would be like below, but it won't work correctly. The
AlwaysStayView()
disappears when I click anyNavigationLink
on sidebar. So, how can I correct it or is there any solution (prefer in SwiftUI, but framework like UIKit would also be OK). I would appreciate it.NavigationView { List { NavigationLink { DiscoverView() } label: { Label("Discover", systemImage: "magnifyingglass") } NavigationLink { SongsView() } label: { Label("Songs", systemImage: "music.note") } NavigationLink { ArtistsView() } label: { Label("Artists", systemImage: "music.mic") } } } .listStyle(SidebarListStyle()) VStack { AlwaysStayView() SongsView() } }
-
NumberFormatter and unsigned with UInt64.max
I'm trying to create a string representing
UInt64.max
usingNumberFormatter
. Here's the code:let formatter = NumberFormatter() formatter.usesGroupingSeparator = true formatter.numberStyle = .decimal formatter.positiveFormat = "# ##0.#########" formatter.maximumSignificantDigits = 20 formatter.usesSignificantDigits = false formatter.maximumFractionDigits = 20 formatter.minimumFractionDigits = 0 formatter.alwaysShowsDecimalSeparator = false // formatter.roundingMode = .halfUp let text1 = formatter.string(for: NSNumber(value: Int64.max)) let text2 = formatter.string(for: NSNumber(value: UInt64.max)) print(text1) print(text2)
which prints:
Optional("9,223,372,036,854,780,000")
Optional("-1")but should print
Optional("9223372036854775807")
Optional("18,446,744,073,709,551,615")It looks like
NSNumber
is roundingInt64
and isn't taking theUIn64
. The obj-c version ofNSNumberFormatter
works fine.Am I missing something or is there a problem with
NumberFormatter
? - Broken project in XCODE objective c
-
Lokalise: How to change default NSStringFormatValueTypeKey
The default
NSStringFormatValueTypeKey
property in Lokalise always returns the stringli
. In my code, the stringd
.When exporting the modified stringsdict file from Lokalise to Github, the
NSStringFormatValueTypeKey
is alwaysli
. Currently, there is no way to change this hardcoded value in the Lokalise platform. What is a trick to change the value besides manually changing them in the stringsdict file in Xcode? I want to change the value tod
Export from Lokalise:
<key>plural.day</key> <dict> <key>NSStringLocalizedFormatKey</key> <string>%#@day@</string> <key>day</key> <dict> <key>NSStringFormatSpecTypeKey</key> <string>NSStringPluralRuleType</string> <key>NSStringFormatValueTypeKey</key> <string>li</string> <key>one</key> <string></string> <key>other</key> <string></string> </dict> </dict>
Desired outcome:
<key>plural.day</key> <dict> <key>NSStringLocalizedFormatKey</key> <string>%#@day@</string> <key>day</key> <dict> <key>NSStringFormatValueTypeKey</key> <string>d</string> <key>NSStringFormatSpecTypeKey</key> <string>NSStringPluralRuleType</string> <key>one</key> <string>%d day ago</string> <key>other</key> <string>%d days ago</string> </dict> </dict>
-
Xcode clean build folder command not working
Not sure what happened but suddenly, my xcode clean build folder option under Product -> Clean Build Folder no longer works. Instead it gives me an error:
Could not delete
/Users/...build
because it was not created by the build system.Is there a way I can reset the xcode settings? Or does someone have any idea how to fix this?
-
Referencing static string in Xcode UI test with apostrophe
In my project is a localized string in a *.strings file like this...
"some_key" = "Yada yada won't blah.\nBlah blah?";
In my UI Test, when I record the element and when I print object on the staticTexts dictionary, it's referenced with a string like this...
app.staticTexts["Yada yada won't blah.\nBlah blah?"]
However, in my test I localize the key and the string comes out with an extra escape character for the apostrophe in the contraction which I believe is breaking the label reference...
print("some_key".localized) Yada yada won\'t blah.\nBlah blah?
I've tried replacing "\'" with "'" and even the below code...
let begin = id.substring(start: 0, offsetBy: 15) let end = id.substring(start: 16, offsetBy: 41) id = "\(begin ?? "")'\(end ?? "")"
...but the escape is always there.
How do I keep the break line, but remove the escape on the apostrophe?
I don't control the client code being tested, so I can't change how the text is setup and I can't reference with an accessibility identifier.
-
How can I download apps to iOS Simulator?
with the recent updates appstore is not available in simulator. I want to download apps such as twitter, facebook etc... to implement some UITests. How can I achieve that?