Post

Replies

Boosts

Views

Activity

Simulate arrow key press in UITextView during UI test
I would like to simulate pressing an arrow key on the hardware keyboard attached to an iPad. In a UI test for a macOS target I can do this: XCUIElement.typeKey(.rightArrow, modifierFlags: [.option, .command]) but this won't compile for a iOS target supporting iPhone and iPad. Is there an alternative? What I would like to achieve in the end is moving the text cursor at the beginning of a particular sentence by pressing Option-Command-Arrow left a certain number of times, but if someone knows a better way, I'd be happy to hear it.
0
0
607
Aug ’23
Determinate spinning NSProgressIndicator doesn't adapt to frame size and gets cut off
The following code should produce 6 spinning progress indicators of varying sizes: 3 indeterminate and 3 determinate ones. The first two of the 3 determinate ones are either entirely or partially cut off, which doesn't happen with the indeterminate ones. What's the problem? var progress = NSProgressIndicator(frame: CGRect(x: 0, y: 0, width: 16, height: 16)) progress.style = .spinning view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 50, y: 0, width: 24, height: 24)) progress.style = .spinning view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 100, y: 0, width: 32, height: 32)) progress.style = .spinning view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 150, y: 0, width: 16, height: 16)) progress.style = .spinning progress.isIndeterminate = false progress.doubleValue = 50 progress.maxValue = 100 view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 200, y: 0, width: 24, height: 24)) progress.style = .spinning progress.isIndeterminate = false progress.doubleValue = 50 progress.maxValue = 100 view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 250, y: 0, width: 32, height: 32)) progress.style = .spinning progress.isIndeterminate = false progress.doubleValue = 50 progress.maxValue = 100 view.addSubview(progress)
Topic: UI Frameworks SubTopic: AppKit Tags:
1
0
735
Aug ’23
Mismatching screenshot display types between App Store Connect website and API
When I open an iOS app in the App Store Connect website and disclose the Apple Watch section, it reads Apple Watch Ultra, Series 8, 6, 3, but the documentation for the API lists different versions: APP_WATCH_ULTRA APP_WATCH_SERIES_7 APP_WATCH_SERIES_4 APP_WATCH_SERIES_3 So the Watch Series don't seem to match. There is a similar issue with iPad Pro. The website reads iPad Pro (6th Gen) 12.9" Display and iPad Pro (2nd Gen) 12.9" Display, but the API reads APP_IPAD_PRO_3GEN_129 APP_IPAD_PRO_129 So again the Gen values don't seem to match. How should I interpret these values?
0
0
487
Aug ’23
App Store Connect API: why do I only have to provide a checksum when uploading app screenshots and not for app event screenshots?
When uploading app screenshots, I have to provide a sourceFileChecksum and uploaded flag: https://developer.apple.com/documentation/appstoreconnectapi/appscreenshotupdaterequest/data/attributes But that's not the case for app event screenshots, I only have to provide the uploadedflag: https://developer.apple.com/documentation/appstoreconnectapi/appeventscreenshotupdaterequest/data/attributes The same is true for app previews and app event video clips. Why is this different?
1
0
473
Jul ’23
Xcode shows compiler errors when accessing class properties and methods only when class is in separate file
When building the code below, two compiler errors appear in AppDelegate.swift: Value of type 'Slice<MyCollection<MySubCollection>>' has no member 'url' No exact matches in call to instance method 'remove' When moving the first 2 classes in ViewController.swift to AppDelegate.swift, the issues go away. Is this expected, or a bug? // AppDelegate.swift // import Cocoa @main class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { var collection: MyCollection<MySubCollection>! let a = collection.first!.url! var subCollection: MySubCollection! collection.remove(subCollection) } } // // ViewController.swift // import Cocoa class MyCollection<Element>: MyCollectionProtocol { var elements = [Element]() } class MySubCollection: MyCollectionProtocol { var elements = [String]() var url: URL? } protocol MyCollectionProtocol: AnyObject, Collection where Index == Int { associatedtype Element var elements: [Element] { get set } } extension MyCollectionProtocol { var startIndex: Index { return elements.startIndex } var endIndex: Index { return elements.endIndex } subscript(position: Index) -> Element { return elements[position] } func index(after i: Index) -> Index { return elements.index(after: i) } } extension MyCollectionProtocol where Element == String { func remove(_ element: Element) { } } extension MyCollectionProtocol where Element: MyCollectionProtocol { func remove(_ element: Element) { } }
2
0
634
Jul ’23
Autosizing text field: NSCell.cellSize(forBounds:) doesn't respect wrapped text unless using attributed string
I'm trying to implement a text field in a table view that automatically adjusts its height to fit the contained text. My current implementation adjusts its intrinsicContentSize in textDidChange(_:). Unfortunately, NSCell.cellSize(forBounds:) doesn't seem to return the correct height unless setting attributedStringValue and allowsEditingTextAttributes = true for the NSTextField. Is this expected, or is there a workaround? Here is the code: class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { var asdf = "asdf fjdskalöf öf fjkldösa jfklödsa kfljsaödkfj klsdajf kldöasj flkjsdöa fkljasö flkjsa öj " override func loadView() { view = NSView(frame: CGRect(x: 0, y: 0, width: 400, height: 400)) let scrollView = NSScrollView() scrollView.translatesAutoresizingMaskIntoConstraints = false let tableView = NSTableView() tableView.usesAutomaticRowHeights = true tableView.addTableColumn(NSTableColumn()) tableView.dataSource = self tableView.delegate = self scrollView.documentView = tableView view.addSubview(scrollView) NSLayoutConstraint.activate([scrollView.topAnchor.constraint(equalTo: view.topAnchor), scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor), scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor)]) } func numberOfRows(in tableView: NSTableView) -> Int { return 1 } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { let view = NSTableCellView() let text = AutoSizingTextField() text.translatesAutoresizingMaskIntoConstraints = false text.cell?.wraps = true // uncommenting the next 2 lines and commenting out the line after them solves the issue // text.attributedStringValue = NSAttributedString(string: asdf, attributes: [.font: text.font!, .foregroundColor: NSColor.labelColor]) // text.allowsEditingTextAttributes = true text.stringValue = asdf view.addSubview(text) NSLayoutConstraint.activate([text.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), text.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), text.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20), text.widthAnchor.constraint(equalToConstant: 200)]) return view } } class AutoSizingTextField: NSTextField { override var intrinsicContentSize: NSSize { var size = super.intrinsicContentSize guard let cell = cell else { return size } var frame = frame frame.size.height = .infinity size.height = cell.cellSize(forBounds: frame).height NSLog("intrinsicContentSize \(size)") return size } override func textDidChange(_ notification: Notification) { super.textDidChange(notification) invalidateIntrinsicContentSize() needsLayout = true layoutSubtreeIfNeeded() } override func layout() { invalidateIntrinsicContentSize() super.layout() } }
Topic: UI Frameworks SubTopic: AppKit Tags:
0
0
725
Jul ’23
NSTextField in table view with specific configuration doesn't enable undo
After typing anything in a custom text field with undo support, when opening the Edit menu, the undo item is disabled. It seems that setting translatesAutoresizingMaskIntoConstraints=false, a formatter, allowsEditingTextAttributes=true and calling invalidateIntrinsicContentSize() in textDidChange(_:) causes this behaviour. Is this expected, or is there a workaround? Here is the code: class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { @IBOutlet weak var textField: NSTextField! override func loadView() { view = NSView(frame: CGRect(x: 0, y: 0, width: 400, height: 400)) let textField = MyTextField() textField.frame = CGRect(x: 0, y: 0, width: 100, height: 20) textField.translatesAutoresizingMaskIntoConstraints = false textField.formatter = MyFormatter() textField.allowsEditingTextAttributes = true view.addSubview(textField) } } class MyTextField: NSTextField { override func textDidChange(_ notification: Notification) { super.textDidChange(notification) super.invalidateIntrinsicContentSize() } } class MyFormatter: Formatter { override func string(for obj: Any?) -> String? { return obj as? String } override func getObjectValue(_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, for string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool { obj?.pointee = string as NSString return true } }
Topic: UI Frameworks SubTopic: AppKit Tags:
0
0
619
Jul ’23
Vertical text from left to right with NSTextView
In the WebVTT video subtitle format, subtitles can be horizontal, vertical growing left, or vertical growing right. The natural text direction of NSTextView is horizontal; with setLayoutOrientation(_:) I get vertical text growing left. How can I get vertical text growing right? The documentation says that with setLayoutOrientation(_:) the text view's bounds are rotated by 90° clockwise, but manually rotating them by -90° with boundsRotation = -90 just rotates everything, including the text which should have the same orientation as before, just expanding in the opposite direction.
0
0
870
Jul ’23
NSTextField and NSParagraphStyle: right align left-to-right text and left align right-to-left text
NSTextField and NSParagraphStyle have a alignment: NSTextAlignment property that allows to align text to the left, center, right, or natural, which means that text for left-to-right languages is aligned left and text for right-to-left languages is aligned right. What I'm looking for is how to align text in the opposite direction of the natural direction. (Note that using the leading and trailing NSLayoutConstraints is not enough as they only aligns the text bounding box, but not the text within the bounding box.) Is there a way to accomplish this? Or is there a built-in function that allows to determine what the natural direction of a String is, so that I can then calculate the alignment by flipping that value?
0
0
822
Jul ’23
Comparing local and uploaded app screenshots with App Store Connect API
Is there a way to compare a local app screenshot on my Mac with the one currently on App Store Connect without downloading the screenshot itself? The API returns fileSize and sourceFileChecksum properties (https://developer.apple.com/documentation/appstoreconnectapi/read_app_screenshot_information), but the file size of my local image is different (url.resourceValues(forKeys: [.fileSizeKey]).fileSize) and the checksum is also different from the one I provided when completing the app screenshot upload.
0
0
587
Jun ’23
NSTextField frame automatically hugs content when superview is AVPlayerView.contentOverlayView
I need to manually set the frame of a NSTextField, but it seems that when added to AVPlayerView.contentOverlayView the frame gets resized so that it hugs the text. This doesn't happen when the text field is added to a simple NSView instead. Is this a bug? Is there a workaround? class ViewController: NSViewController { override func loadView() { view = NSView() let text = NSTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) text.translatesAutoresizingMaskIntoConstraints = false text.isEditable = false text.backgroundColor = .red let paragraph = NSMutableParagraphStyle() paragraph.alignment = .center text.attributedStringValue = NSAttributedString(string: "asdf", attributes: [.paragraphStyle: paragraph]) view.addSubview(text) // commenting out the following 3 lines solves the issue let playerView = AVPlayerView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) view.addSubview(playerView) playerView.contentOverlayView!.addSubview(text) // uncommenting the following 5 lines also solves the issue, but the wrong text field frame is briefly visible before it resizes to the correct width // DispatchQueue.main.async { // print(text.frame) // text.frame.size.width = 200 // text.removeConstraints(text.constraints) // } } }
0
0
838
Jun ’23
How to install macOS 14 Sonoma or 13 Ventura on an external partition
I would like to install macOS 14 Sonoma on an external partition, but I couldn't find an installer on the developer website. It seems that it's only possible to upgrade from the System Settings, so I thought I would install Ventura first on the separate partition and then upgrade to Sonoma. I downloaded the Ventura installer from the App Store and selected the external partition during the installation, but when the Mac reboots, it just reboots into my main macOS partition. If I shut down and hold the power button pressed to select the boot partition (I have a M1 MacBook Pro 14" 2022), then nothing happens: an indeterminate progress indicator spins for a couple seconds, the partition list remains there and I can only successfully boot into my main partition again. I also tried running the installer from another macOS Ventura and macOS Monterey partition I had installed last year, but when I select the partition on which to install the new Ventura, nothing happens and I can only quit the installer. Is there a way to debug all these issues? How can I install macOS Sonoma on a separate partition without overwriting my main macOS Ventura install?
4
2
4.1k
Jun ’23
filecopy function is slower than cp command
When copying a 7 GB file, the filecopy function is always about 20% slower than the cp command. I tested using my MacBook Pro 14" M1 and an external SSD connected via USB. Mac to Mac filecopy: 4.78s cp: 3.40s Mac to SSD filecopy: 20.22s cp: 15.93s SSD to Mac filecopy: 20.61s cp: 16.64s I use the following code: let openPanel = NSOpenPanel() openPanel.runModal() let source = openPanel.urls[0] openPanel.canChooseDirectories = true openPanel.canChooseFiles = false openPanel.runModal() let destination = openPanel.urls[0].appendingPathComponent(source.lastPathComponent) source.withUnsafeFileSystemRepresentation { sourcePath in destination.withUnsafeFileSystemRepresentation { destinationPath in let state = copyfile_state_alloc() defer { copyfile_state_free(state) } let date = Date() if copyfile(sourcePath, destinationPath, state, copyfile_flags_t(COPYFILE_ALL | COPYFILE_NOFOLLOW | COPYFILE_EXCL)) != 0 { print(NSError(domain: NSPOSIXErrorDomain, code: Int(errno))) } print(-date.timeIntervalSinceNow) } } and the very basic cp command: time cp /path/to/source /path/to/destination Is there a faster way to copy files? Am I doing something wrong with filecopy?
0
0
624
May ’23
Simulate arrow key press in UITextView during UI test
I would like to simulate pressing an arrow key on the hardware keyboard attached to an iPad. In a UI test for a macOS target I can do this: XCUIElement.typeKey(.rightArrow, modifierFlags: [.option, .command]) but this won't compile for a iOS target supporting iPhone and iPad. Is there an alternative? What I would like to achieve in the end is moving the text cursor at the beginning of a particular sentence by pressing Option-Command-Arrow left a certain number of times, but if someone knows a better way, I'd be happy to hear it.
Replies
0
Boosts
0
Views
607
Activity
Aug ’23
Determinate spinning NSProgressIndicator doesn't adapt to frame size and gets cut off
The following code should produce 6 spinning progress indicators of varying sizes: 3 indeterminate and 3 determinate ones. The first two of the 3 determinate ones are either entirely or partially cut off, which doesn't happen with the indeterminate ones. What's the problem? var progress = NSProgressIndicator(frame: CGRect(x: 0, y: 0, width: 16, height: 16)) progress.style = .spinning view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 50, y: 0, width: 24, height: 24)) progress.style = .spinning view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 100, y: 0, width: 32, height: 32)) progress.style = .spinning view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 150, y: 0, width: 16, height: 16)) progress.style = .spinning progress.isIndeterminate = false progress.doubleValue = 50 progress.maxValue = 100 view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 200, y: 0, width: 24, height: 24)) progress.style = .spinning progress.isIndeterminate = false progress.doubleValue = 50 progress.maxValue = 100 view.addSubview(progress) progress = NSProgressIndicator(frame: CGRect(x: 250, y: 0, width: 32, height: 32)) progress.style = .spinning progress.isIndeterminate = false progress.doubleValue = 50 progress.maxValue = 100 view.addSubview(progress)
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
1
Boosts
0
Views
735
Activity
Aug ’23
Mismatching screenshot display types between App Store Connect website and API
When I open an iOS app in the App Store Connect website and disclose the Apple Watch section, it reads Apple Watch Ultra, Series 8, 6, 3, but the documentation for the API lists different versions: APP_WATCH_ULTRA APP_WATCH_SERIES_7 APP_WATCH_SERIES_4 APP_WATCH_SERIES_3 So the Watch Series don't seem to match. There is a similar issue with iPad Pro. The website reads iPad Pro (6th Gen) 12.9" Display and iPad Pro (2nd Gen) 12.9" Display, but the API reads APP_IPAD_PRO_3GEN_129 APP_IPAD_PRO_129 So again the Gen values don't seem to match. How should I interpret these values?
Replies
0
Boosts
0
Views
487
Activity
Aug ’23
App Store Connect API: why do I only have to provide a checksum when uploading app screenshots and not for app event screenshots?
When uploading app screenshots, I have to provide a sourceFileChecksum and uploaded flag: https://developer.apple.com/documentation/appstoreconnectapi/appscreenshotupdaterequest/data/attributes But that's not the case for app event screenshots, I only have to provide the uploadedflag: https://developer.apple.com/documentation/appstoreconnectapi/appeventscreenshotupdaterequest/data/attributes The same is true for app previews and app event video clips. Why is this different?
Replies
1
Boosts
0
Views
473
Activity
Jul ’23
Getting all screenshot display types and app preview types in App Store Connect API
I see that one can get all app categories, but I don't see a way of getting all supported screenshot display types and app preview types. Is this possible and if not, is there some way of getting all supported types without having to download the API specification?
Replies
0
Boosts
0
Views
398
Activity
Jul ’23
Xcode shows compiler errors when accessing class properties and methods only when class is in separate file
When building the code below, two compiler errors appear in AppDelegate.swift: Value of type 'Slice<MyCollection<MySubCollection>>' has no member 'url' No exact matches in call to instance method 'remove' When moving the first 2 classes in ViewController.swift to AppDelegate.swift, the issues go away. Is this expected, or a bug? // AppDelegate.swift // import Cocoa @main class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { var collection: MyCollection<MySubCollection>! let a = collection.first!.url! var subCollection: MySubCollection! collection.remove(subCollection) } } // // ViewController.swift // import Cocoa class MyCollection<Element>: MyCollectionProtocol { var elements = [Element]() } class MySubCollection: MyCollectionProtocol { var elements = [String]() var url: URL? } protocol MyCollectionProtocol: AnyObject, Collection where Index == Int { associatedtype Element var elements: [Element] { get set } } extension MyCollectionProtocol { var startIndex: Index { return elements.startIndex } var endIndex: Index { return elements.endIndex } subscript(position: Index) -> Element { return elements[position] } func index(after i: Index) -> Index { return elements.index(after: i) } } extension MyCollectionProtocol where Element == String { func remove(_ element: Element) { } } extension MyCollectionProtocol where Element: MyCollectionProtocol { func remove(_ element: Element) { } }
Replies
2
Boosts
0
Views
634
Activity
Jul ’23
Autosizing text field: NSCell.cellSize(forBounds:) doesn't respect wrapped text unless using attributed string
I'm trying to implement a text field in a table view that automatically adjusts its height to fit the contained text. My current implementation adjusts its intrinsicContentSize in textDidChange(_:). Unfortunately, NSCell.cellSize(forBounds:) doesn't seem to return the correct height unless setting attributedStringValue and allowsEditingTextAttributes = true for the NSTextField. Is this expected, or is there a workaround? Here is the code: class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { var asdf = "asdf fjdskalöf öf fjkldösa jfklödsa kfljsaödkfj klsdajf kldöasj flkjsdöa fkljasö flkjsa öj " override func loadView() { view = NSView(frame: CGRect(x: 0, y: 0, width: 400, height: 400)) let scrollView = NSScrollView() scrollView.translatesAutoresizingMaskIntoConstraints = false let tableView = NSTableView() tableView.usesAutomaticRowHeights = true tableView.addTableColumn(NSTableColumn()) tableView.dataSource = self tableView.delegate = self scrollView.documentView = tableView view.addSubview(scrollView) NSLayoutConstraint.activate([scrollView.topAnchor.constraint(equalTo: view.topAnchor), scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor), scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor)]) } func numberOfRows(in tableView: NSTableView) -> Int { return 1 } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { let view = NSTableCellView() let text = AutoSizingTextField() text.translatesAutoresizingMaskIntoConstraints = false text.cell?.wraps = true // uncommenting the next 2 lines and commenting out the line after them solves the issue // text.attributedStringValue = NSAttributedString(string: asdf, attributes: [.font: text.font!, .foregroundColor: NSColor.labelColor]) // text.allowsEditingTextAttributes = true text.stringValue = asdf view.addSubview(text) NSLayoutConstraint.activate([text.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), text.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), text.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20), text.widthAnchor.constraint(equalToConstant: 200)]) return view } } class AutoSizingTextField: NSTextField { override var intrinsicContentSize: NSSize { var size = super.intrinsicContentSize guard let cell = cell else { return size } var frame = frame frame.size.height = .infinity size.height = cell.cellSize(forBounds: frame).height NSLog("intrinsicContentSize \(size)") return size } override func textDidChange(_ notification: Notification) { super.textDidChange(notification) invalidateIntrinsicContentSize() needsLayout = true layoutSubtreeIfNeeded() } override func layout() { invalidateIntrinsicContentSize() super.layout() } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
0
Boosts
0
Views
725
Activity
Jul ’23
NSTextField in table view with specific configuration doesn't enable undo
After typing anything in a custom text field with undo support, when opening the Edit menu, the undo item is disabled. It seems that setting translatesAutoresizingMaskIntoConstraints=false, a formatter, allowsEditingTextAttributes=true and calling invalidateIntrinsicContentSize() in textDidChange(_:) causes this behaviour. Is this expected, or is there a workaround? Here is the code: class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { @IBOutlet weak var textField: NSTextField! override func loadView() { view = NSView(frame: CGRect(x: 0, y: 0, width: 400, height: 400)) let textField = MyTextField() textField.frame = CGRect(x: 0, y: 0, width: 100, height: 20) textField.translatesAutoresizingMaskIntoConstraints = false textField.formatter = MyFormatter() textField.allowsEditingTextAttributes = true view.addSubview(textField) } } class MyTextField: NSTextField { override func textDidChange(_ notification: Notification) { super.textDidChange(notification) super.invalidateIntrinsicContentSize() } } class MyFormatter: Formatter { override func string(for obj: Any?) -> String? { return obj as? String } override func getObjectValue(_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, for string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool { obj?.pointee = string as NSString return true } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
0
Boosts
0
Views
619
Activity
Jul ’23
Vertical text from left to right with NSTextView
In the WebVTT video subtitle format, subtitles can be horizontal, vertical growing left, or vertical growing right. The natural text direction of NSTextView is horizontal; with setLayoutOrientation(_:) I get vertical text growing left. How can I get vertical text growing right? The documentation says that with setLayoutOrientation(_:) the text view's bounds are rotated by 90° clockwise, but manually rotating them by -90° with boundsRotation = -90 just rotates everything, including the text which should have the same orientation as before, just expanding in the opposite direction.
Replies
0
Boosts
0
Views
870
Activity
Jul ’23
NSTextField and NSParagraphStyle: right align left-to-right text and left align right-to-left text
NSTextField and NSParagraphStyle have a alignment: NSTextAlignment property that allows to align text to the left, center, right, or natural, which means that text for left-to-right languages is aligned left and text for right-to-left languages is aligned right. What I'm looking for is how to align text in the opposite direction of the natural direction. (Note that using the leading and trailing NSLayoutConstraints is not enough as they only aligns the text bounding box, but not the text within the bounding box.) Is there a way to accomplish this? Or is there a built-in function that allows to determine what the natural direction of a String is, so that I can then calculate the alignment by flipping that value?
Replies
0
Boosts
0
Views
822
Activity
Jul ’23
Comparing local and uploaded app screenshots with App Store Connect API
Is there a way to compare a local app screenshot on my Mac with the one currently on App Store Connect without downloading the screenshot itself? The API returns fileSize and sourceFileChecksum properties (https://developer.apple.com/documentation/appstoreconnectapi/read_app_screenshot_information), but the file size of my local image is different (url.resourceValues(forKeys: [.fileSizeKey]).fileSize) and the checksum is also different from the one I provided when completing the app screenshot upload.
Replies
0
Boosts
0
Views
587
Activity
Jun ’23
NSTextField frame automatically hugs content when superview is AVPlayerView.contentOverlayView
I need to manually set the frame of a NSTextField, but it seems that when added to AVPlayerView.contentOverlayView the frame gets resized so that it hugs the text. This doesn't happen when the text field is added to a simple NSView instead. Is this a bug? Is there a workaround? class ViewController: NSViewController { override func loadView() { view = NSView() let text = NSTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) text.translatesAutoresizingMaskIntoConstraints = false text.isEditable = false text.backgroundColor = .red let paragraph = NSMutableParagraphStyle() paragraph.alignment = .center text.attributedStringValue = NSAttributedString(string: "asdf", attributes: [.paragraphStyle: paragraph]) view.addSubview(text) // commenting out the following 3 lines solves the issue let playerView = AVPlayerView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) view.addSubview(playerView) playerView.contentOverlayView!.addSubview(text) // uncommenting the following 5 lines also solves the issue, but the wrong text field frame is briefly visible before it resizes to the correct width // DispatchQueue.main.async { // print(text.frame) // text.frame.size.width = 200 // text.removeConstraints(text.constraints) // } } }
Replies
0
Boosts
0
Views
838
Activity
Jun ’23
How to install macOS 14 Sonoma or 13 Ventura on an external partition
I would like to install macOS 14 Sonoma on an external partition, but I couldn't find an installer on the developer website. It seems that it's only possible to upgrade from the System Settings, so I thought I would install Ventura first on the separate partition and then upgrade to Sonoma. I downloaded the Ventura installer from the App Store and selected the external partition during the installation, but when the Mac reboots, it just reboots into my main macOS partition. If I shut down and hold the power button pressed to select the boot partition (I have a M1 MacBook Pro 14" 2022), then nothing happens: an indeterminate progress indicator spins for a couple seconds, the partition list remains there and I can only successfully boot into my main partition again. I also tried running the installer from another macOS Ventura and macOS Monterey partition I had installed last year, but when I select the partition on which to install the new Ventura, nothing happens and I can only quit the installer. Is there a way to debug all these issues? How can I install macOS Sonoma on a separate partition without overwriting my main macOS Ventura install?
Replies
4
Boosts
2
Views
4.1k
Activity
Jun ’23
Get the file size of a file in iCloud Drive
When a file named a.txt is not downloaded locally, the iCloud Drive folder actually only contains a placeholder named .a.txt.icloud (that is still displayed as a.txt by the Finder) with a very small file size, something like 176 bytes. How can I get the original file size, like the Finder displays?
Replies
4
Boosts
1
Views
1.5k
Activity
Jun ’23
filecopy function is slower than cp command
When copying a 7 GB file, the filecopy function is always about 20% slower than the cp command. I tested using my MacBook Pro 14" M1 and an external SSD connected via USB. Mac to Mac filecopy: 4.78s cp: 3.40s Mac to SSD filecopy: 20.22s cp: 15.93s SSD to Mac filecopy: 20.61s cp: 16.64s I use the following code: let openPanel = NSOpenPanel() openPanel.runModal() let source = openPanel.urls[0] openPanel.canChooseDirectories = true openPanel.canChooseFiles = false openPanel.runModal() let destination = openPanel.urls[0].appendingPathComponent(source.lastPathComponent) source.withUnsafeFileSystemRepresentation { sourcePath in destination.withUnsafeFileSystemRepresentation { destinationPath in let state = copyfile_state_alloc() defer { copyfile_state_free(state) } let date = Date() if copyfile(sourcePath, destinationPath, state, copyfile_flags_t(COPYFILE_ALL | COPYFILE_NOFOLLOW | COPYFILE_EXCL)) != 0 { print(NSError(domain: NSPOSIXErrorDomain, code: Int(errno))) } print(-date.timeIntervalSinceNow) } } and the very basic cp command: time cp /path/to/source /path/to/destination Is there a faster way to copy files? Am I doing something wrong with filecopy?
Replies
0
Boosts
0
Views
624
Activity
May ’23