Post

Replies

Boosts

Views

Activity

linker failing for unit tests in multiplatform project
I have a multiplatform project in Xcode 13.3.1, but when I try to run a unit by clicking the diamond in the gutter, the linker fails. From the link line in the log, it looks as if it isn't even linking with my app at all. I also noticed that I had to put in my own @testable import NameOfMyApp instead of Xcode generating that line like it does for single-platform projects, so that makes me wonder if this something extra i need to do since this project is multiplatform? Everything compiles fine, but the linker seems to be forgeting to link with my app...
2
1
1.3k
May ’22
How can I write this generic as a var instead of a func?
When an Array has an Element type that is an optional, I'd like to count the non-nil elems. Is there a way to do this with just a var? How can I say that Element is an Optional<T>, without introducing T via the generic func? Thanx. extension Array {     func someCount<T>() -> Int where Element == Optional<T> {         self.reduce(0) { count, elem in count + (elem == nil ? 0 : 1)     } }
1
0
420
Apr ’22
Xcode 13.3 wrongly claiming UI changes on background thread
My App had no such warnings before updating to 13.3, but now it claims I'm updating from a background thread. A simple print will make these warnings stop, so something is wrong:  @MainActor private func runOnMain(_ action: @escaping () async -> ()) async {         //print("", terminator: "")         await action()     } simply uncommenting that print() makes all the warnings go away, so I think 13.3 has an issue here... Is anyone else seeing this?
1
0
646
Mar ’22
function-local struct def can never be Comparable?
If i have a struct inside a function, swift keeps telling me is doesn't conform to Comparable, even though the same definition is fine outside of a function -- why is this? Foo fails Comparable here: func foo() {             struct Foo : Equatable, Comparable {                 let x: Int                 let y: Int                 static func (lhs: Foo, rhs: Foo) - Bool {                     return lhs.x+lhs.y rhs.x+rhs.y                 }             }         }
4
0
625
Mar ’21
How do I downgrade the simulator in Xcode?
My app is working as expected in the simulator on iOS 12.1, but not on my iOS 11.x device, and it is just a layout issue. I'm not aware of any major changes in layout constraints from 11 to 12, so I'm perplexed... I upgraded an older device from iOS 10 to 12 and my app layout works on it, so it seems something changed between iOS 11 and 12 regarding layout, but I don't know what that is...How can I get a simulator running iOS 11.x to debug? I'll start debugging on my actual 11.x device, but I would also like to know how to get a simulator running older iOS versions? xcodebuild -showsdks says I only have 12.1 iphone/simulator 12.1 -- how do I run 11.x in the simulator, or older iOS versions in general in the simulator?
12
2
42k
Nov ’18
How do I make (Int,Int) Hashable?
I was surprised (Int,Int) isn't Hashable. How do I write the obvious extension to make it so?If I try "extension (Int,Int)" the error is that non-nominal type (Int,Int) can't be extended. The word "nominal" appears nowhere in the Swift iBooks provided by Apple, so I can't be absolutely certain that I even know what Xcode is telling here... Using a typealias gives the same error.How do I extend (Int,Int) to make it Hashable so I can use it for dictionary keys? What is a "non-nominal" type, and where can I find that definition?
4
0
7.8k
Sep ’18
sharedRandom always giving me 0
In my AppDelegate, I'm picking a seed like this on my physical iPad Pro:func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool { // Override point for customization after application launch. sysRandom = GKRandomSource.sharedRandom() randDist0 = GKRandomDistribution(randomSource: sysRandom!, lowestValue: 0, highestValue: 0xffffffff) let _ = randDist0!.nextInt() let toss = randDist0!.nextInt() print("App Seed: \(toss)") appSeed0 = tossI keep getting a seed of 0, so I'm clearly not understanding something. The shared random source on my iPad should be giving me a random value, right? I was tossing twice just to be sure... What am I doing wrong here?
2
0
1k
Sep ’18