Post

Replies

Boosts

Views

Activity

Xcode 12 Can't figure out the type???
Once again, the most frustrating and weird error message: "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions" struct TimePosition: View { &#9;&#9;var scale: Double &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;GeometryReader { geometry in &#9;&#9;&#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(0..<Int(geometry.size.height)/Int(1/self.scale), id:\.self) { y in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(String(Double(y)/4.0)).position(x: geometry.size.width/2, y: CGFloat(y)).font(.system(size: 8.0)).foregroundColor(.gray) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; } &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } So, how exactly does one break this up?
4
0
2.5k
Jun ’20
ScrollViewReader use bug
This code has a behavior that I think might be a bug, but I wanted to check to see if anyone spots a flaw in my thinking. This code makes a scrollable containing a single view which itself encapsulated a longer-than-the-screen list. Note the UnitPoint on line 9, the y: component seems to be a percentage. The bug is that the point requested must be on the screen. In this case, it seems to be around the 12, but with different numbers I get different results. The only time it seems to be consistent is if the current scroll position is at the very top. struct ListVsScrollview: View { &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;NavigationView { &#9;&#9;&#9;&#9;&#9;&#9;ScrollViewReader { sv in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;VStack{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button("Move") { sv. ;sv.scrollTo(72, anchor: UnitPoint(x: 0.0, y: 0.1)) } &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ScrollView { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Hi").font(.title) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(0...100, id: \.self) { number in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("\(number)").font(.title) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Low").font(.title) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}.id(72) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.navigationBarItems(trailing: EditButton()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } struct ListVsScrollview_Previews: PreviewProvider { &#9;&#9;static var previews: some View { &#9;&#9;&#9;&#9;ListVsScrollview() &#9;&#9;} }
0
0
640
Jun ’20
Xcode 12.5 use C library with swift
Search on this topic on the web is maddening, because nothing really seems to be complete. I'd like to ask for 2 pathways: Library which comes with Xcode/macOS If I look at my target info panel in the project editor, I can add Frameworks and Libraries. I would like to add libpcre. I hit the "+", scroll down and select libpcre.tbd. It dutifully adds an entry. How do I now use this in a swift file, and see the various functions from the pcre library? Library installed from homebrew 2. Say I have decided that pcre version 1 isn't enough, and I need to add libpcre2. I use "brew install pcre2", which installs the needed file in /usr/local/Cellar/pcre2/10.36/ . How do I now show Xcode how to find these libraries, and use them in my swift file? The Test In both cases, my basic test is that I ought to be able to type let recode = pcreTAB and have Xcode show me the various symbols from the included library.
0
0
835
May ’21
MPMusicPlayerController.applicationQueuePlayer opens Music app, which is not the goal.
Using Xcode 14.0 beta on MacOS 12.4 I have a simple app to play items in the Music library. I'm using MPMusicPlayerController.applicationQueuePlayer to play the music. Nowhere in my project do I refer to the systemMusicPlayer, nor do I have any instances of MPMusicPlayerController() alone. Yet even if I quit the Music app, selecting a new song opens the Music app. The code I use: // inside a View var mainPlayer = MPMusicPlayerController.applicationQueuePlayer //at the end of the HStack representing a single song .onTapGesture { mainPlayer.setQueue(with: MPMediaItemCollection(items: [song])) mainPlayer.prepareToPlay() title = song.title ?? "-- No Title --" mainPlayer.play() }
0
0
477
Jun ’22
What exactly does the fixedSize() modifier do?
Here's some code: import SwiftUI struct RRectPlay: View { var body: some View { Canvas { gc, size in gc.translateBy(x: 20.0, y: 20.0) gc.stroke( Path(roundedRect: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0), cornerSize: CGSize(width: 2.0, height: 2.0)), with: .color(.black), lineWidth: 20.0 ) } } } struct RRectPlay_Previews: PreviewProvider { static var previews: some View { RRectPlay() } } It shows a rounded rect, as requested: If I add the fixedSize modifier to the preview: RRectPlay().fixedSize() The rectangle disappears: If I add a border to see what's happened, I get this: It seems like the definiation of "Ideal Size" ought to be something closer to the bounding box of the figure if there are no other items on the screen. Can anyone elucidate me?
1
0
680
Dec ’22
Can UserNotifications be used in a command line program?
I have a cli program which does a thing for a while, and I'd like it to post a notification on the screen when it's done. Note that because it's a standalone program, not an app, it doesn't have a bundle, per se. I tried to use UserNotifications, but I get an immediate error with the line let center = UNUserNotificationCenter.current() With the error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL My entire program to produce this bug: import Foundation import UserNotifications let center = UNUserNotificationCenter.current() print("Hello, World!")
1
1
813
Feb ’23
SizeClasses, really?
I have an app with looks at the @Environment(\.horizontalSizeClass) variable and it's mate vertical. On the iPhone 16 sim, if I'm in portrait orientation, It says my vertical class is .regular and horizontal is .compact. If I rotate to landscape, it says vertical is now compact, and horizontal is still compact. That seems inconsistent. I'm trying to wrap my head around designing for size class, how am I supposed to think about this? What I want is two areas of the screen: The main area, which shows a graphic, and a much smaller control and data area, which has a button or two and a very narrow text display, which in my current app counts from 1 to 4. The button area These areas ought never move from where they are, but their contents ought to rotate in place to reflect the orientation. If portrait, the button area is on the bottom, if landscapeLeft, the button are is to the right, if landscapeRight, the button area is to the left. This currently sort of works if I test for the max of height or width from a Geometry Reader, but it doesn't handle landscapeRight or portraitUpsideDown correctly.
1
0
138
3w