Post

Replies

Boosts

Views

Activity

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 `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 Creating a mac app from .jar file
Learning to code in Swift, SwiftUI, or Objective-C will allow you to port the app to the mac if you intend to release it to the mac app store otherwise google how to launch java based app on any OS.
Replies
Boosts
Views
Activity
Dec ’22
Reply to How do you detect an Apple Watch's distance from the Mac?
Hence the reason why they are called private APIs.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Set other font on one Word in Label
Well, continue to add the NS Attrib key for the font and a font reference to the dictionary.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Core Location and Beacon Monitoring in the background.
Contact Apple Developer Support and see the "Code Level Support" option in your account.
Replies
Boosts
Views
Activity
Jan ’23
Reply to how to make jupyter support swift
Talk to the jupyter owners over at their site.
Topic: Programming Languages SubTopic: Swift Tags:
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
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 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 How to reboot from Objective-C?
The dreams and aspirations
Topic: Programming Languages 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 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 `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 `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 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 SecKeychainItem cast to SecCertificate crashes
Because certItem is nil hence the crash on force unwrap.
Replies
Boosts
Views
Activity
Jan ’23