Post

Replies

Boosts

Views

Activity

Reply to `focusable()` broken for views that are not already focusable
Your code modified to use a TextField instead of a Text view. import SwiftUI struct ContentView: View {     @FocusState private var focusedItem: Optional<FocusedItem>     @State var inputname: String = ""          var body: some View {         VStack {                          TextField("Test", text: $inputname)             #if os(macOS)                 .focusable(true)             #endif                 .focused($focusedItem, equals: .two)             Button("Toggle Focus") {                 self.focusedItem=(self.focusedItem == nil) ? .two : nil             }.onChange(of: focusedItem) { newValue in                 // Always prints `nil`.                 print(newValue as Any)             }         }     }          enum FocusedItem: Equatable {         case one, two         func other() -> FocusedItem {             switch self {             case .one: return .two             case .two: return .one             }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’23
Reply to [__NSCFType set]: unrecognized selector with NSAttributedString:draw() gets called, based on width of position
The foregroundColor in attributes doesn't take a cgColor context.cgContext.setFillColor(UIColor.black.cgColor) not needed use UIColor.black.setFill() instead. Final changes let imageSize = CGSize(width: 400, height: 100) let testRenderer = UIGraphicsImageRenderer(size: imageSize) let testImage = testRenderer.image { context in     UIColor.black.setFill()     context.fill(CGRect(origin: .zero, size: imageSize))     let paragraphStyle = NSMutableParagraphStyle()     paragraphStyle.alignment = .left     let attributes: [NSAttributedString.Key: Any] = [         .font: UIFont.systemFont(ofSize: 8.0),         .paragraphStyle: paragraphStyle,         .foregroundColor: UIColor.white]     var attributedString = NSAttributedString(string: "This is some text",                                               attributes: attributes)     let drawContext = NSStringDrawingContext()     drawContext.minimumScaleFactor = 0.5     attributedString.draw(with: testRenderer.format.bounds, options: .usesLineFragmentOrigin,                           context: drawContext) } -enjoy!
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’23
Reply to How to announce list updates in SwiftUI?
Yes, these are different design paradigms see the focus example for when there is a change in data and how this is used to trigger a UI element focus under accessibility. https://developer.apple.com/documentation/swiftui/creating_accessible_views/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to Unity IOS build crash
Please post your question on the unity developer forums over at unity.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to Moving user from a notification on a watch extension to the app on the phone
No one has had this issue because Apps are implemented on the watch with the watch version of the iOS UI and functionality. There are no shortcuts.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to Can't Sign in to Xcode ( Server Returned Http error: 404 (Not Found)) Please Help
Any reason why you're running something no longer supported and expect it to work still?
Replies
Boosts
Views
Activity
Jan ’23
Reply to Error while compiling in VS Code but not in Xcode
Just use Xcode
Replies
Boosts
Views
Activity
Jan ’23
Reply to SecKeychainItem cast to SecCertificate crashes
Because certItem is nil hence the crash on force unwrap.
Replies
Boosts
Views
Activity
Jan ’23
Reply to Problem with associatedtype in a protocol - "Member '<method>' cannot be used on value of type 'any <protocol>';
Read https://www.swiftbysundell.com/articles/referencing-generic-protocols-with-some-and-any-keywords/
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to `focusable()` broken for views that are not already focusable
Your code modified to use a TextField instead of a Text view. import SwiftUI struct ContentView: View {     @FocusState private var focusedItem: Optional<FocusedItem>     @State var inputname: String = ""          var body: some View {         VStack {                          TextField("Test", text: $inputname)             #if os(macOS)                 .focusable(true)             #endif                 .focused($focusedItem, equals: .two)             Button("Toggle Focus") {                 self.focusedItem=(self.focusedItem == nil) ? .two : nil             }.onChange(of: focusedItem) { newValue in                 // Always prints `nil`.                 print(newValue as Any)             }         }     }          enum FocusedItem: Equatable {         case one, two         func other() -> FocusedItem {             switch self {             case .one: return .two             case .two: return .one             }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to `focusable()` broken for views that are not already focusable
Using a Text view is not supported with focus. Focus is used for setting the input focus (firstResponder) for input-oriented controls like TextField, TextEditor etc. Read the documentation first, it usually helps.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to Error Domain=NSCocoaErrorDomain Code=257 "The file couldn’t be opened because you don’t have permission to view it"
Just because the path is correct doesn't mean you have permission to access it.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to How to reboot from Objective-C?
What do you want to reboot? The phone? Not Possible The App? Possible but pointless
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to How to reboot from Objective-C?
The dreams and aspirations
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to The compiler is unable to type-check this expression in reasonable time
Move all of your core data operations into its own class. Take a look at the food truck example code. View-only code should exist only in the view.
Replies
Boosts
Views
Activity
Jan ’23
Reply to CPU power is poor when scrolling slow (CPU power / battery efficiency question)
Threading 101 - You are doing too much work on the main thread.
Replies
Boosts
Views
Activity
Jan ’23
Reply to [__NSCFType set]: unrecognized selector with NSAttributedString:draw() gets called, based on width of position
The foregroundColor in attributes doesn't take a cgColor context.cgContext.setFillColor(UIColor.black.cgColor) not needed use UIColor.black.setFill() instead. Final changes let imageSize = CGSize(width: 400, height: 100) let testRenderer = UIGraphicsImageRenderer(size: imageSize) let testImage = testRenderer.image { context in     UIColor.black.setFill()     context.fill(CGRect(origin: .zero, size: imageSize))     let paragraphStyle = NSMutableParagraphStyle()     paragraphStyle.alignment = .left     let attributes: [NSAttributedString.Key: Any] = [         .font: UIFont.systemFont(ofSize: 8.0),         .paragraphStyle: paragraphStyle,         .foregroundColor: UIColor.white]     var attributedString = NSAttributedString(string: "This is some text",                                               attributes: attributes)     let drawContext = NSStringDrawingContext()     drawContext.minimumScaleFactor = 0.5     attributedString.draw(with: testRenderer.format.bounds, options: .usesLineFragmentOrigin,                           context: drawContext) } -enjoy!
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’23