Posts

Post not yet marked as solved
2 Replies
706 Views
Tracking down some errors in ValueTransformers in an old project. It seems that String.self can't be returned as AnyClass since it is a value type. So this works in Xcode 12.5: func test() - AnyClass { // just for checking     type(of: NSString.self)     type(of: String.self)     type(of: NSNumber.self)     return NSString.self } But this doesn't: func test2() - AnyClass {     return String.self } Cannot convert return expression of type 'String.Type' to return type 'AnyClass' (aka 'AnyObject.Type') So back to the ValueTransformer. This was the code that seemed to compile circa 2016. Now has a warning that it will fail. override class func transformedValueClass() - AnyClass {   return String.self as! AnyClass } String is a struct not a class. And doing this produces an error - because String is a struct override class func transformedValueClass() - AnyClass {   return String.self } So is the correct approach to work with NSStrings in ValueTransformers? Simply cast the last return with: return swiftNSString(utf8String:string) Similarly, Bool is also a struct and has the same issues. But BOOL isn't available so it looks like NSNumber.
Posted
by purple.
Last updated
.
Post not yet marked as solved
0 Replies
273 Views
Are there any known reasons why a single NSFilePresenter instance has its presentedItemDidChange function called twice when the contents of the file is rewritten just once? Big Sur 11.2.3 I have extracted out the functionality into a reader and writer app and currently can't reproduce the issue in a simplified case. But when it is put into a full app context, I can see that two separate threads are initiating the call to presentedItemDidChange(). Checking file size and date modified show that they should be identical files. Only writing a string into a file, so not changing the file in any other way. So it doesn't seem to be two changes being made to the file. I only have one instance of the NSFilePresenter, it is referencing a file, not a directory. Breakpointing at presentedItemDidChange shows that the framework is going through an identical call sequence. But it's happening in two different threads. Not currently using any file coordination since there's only one file and one write operation. The meta data would suggest that it's not emptying the file, then writing it, causing two events 1) when the file size goes to zero and then 2) when the file is written and closed. Checking the file presenter object, and there's only one instance and the same sender object is defined. So it looks like the framework is triggering twice from two different threads. I don't have multiple processes or multiple file presenters. So unclear why two different threads are originating this.
Posted
by purple.
Last updated
.
Post not yet marked as solved
2 Replies
204 Views
Seeing different behaviour when similar code is presented in a Mac app and either a Mac Playground or command line app. The objective is create an array of range references into a string. /* Define a string */ let source = "Hello" /* Define an array that is a collection of ranges within the string. In this case use the whole range. */ let array = [source.startIndex..<source.endIndex, source.startIndex..<source.endIndex] /* Iterate */ for r in array { ... } This works in the Playground and Command Line versions but in a Mac app, the same code produces: For-in loop requires 'Range<String.Index>?' to conform to 'Sequence'; did you mean to unwrap optional? The Range<String.Index> items in the array are themselves not Sequences. Unclear why essentially the same code loop is producing an error message when used in the Mac app but no error for the Playground or command line. Nothing defined is an optional. Experimented with 12.1 and 12.2 - same results so far. Has anybody seen anything similar?
Posted
by purple.
Last updated
.
Post not yet marked as solved
1 Replies
564 Views
Is there an elegant way to produce macOS conforming label/text field alignment with SwiftUI? Once upon a time the Human Interface Guidelines provided diagrams illustrating how Labels should be right aligned on macOS. Big Sur's System Preferences > General still presents this best practice with the colons right aligned (the design guidelines seem to no longer mention this) and the text fields left aligned. Whilst we will use a combination of VStacks and HStacks to layout an interface in this manner, it isn't clear how you currently specify a modifier to align the contents of multiple HStacks so that each has all the text labels right aligned, all the Text Fields left aligned (and the same width or opt in to do so) and also maintain a constant and standard distance between every Label and TextField. To add, one might think that in SwiftUI parlance that we would drop the colon (:) from the Text definition and that SwiftUI would automagically put that in for us. Also not put it in on iOS. Dropping the colon from the Text string would help accessibility - one less character to convey. HorizontalAlignment didn't seem to offer this. A naive form layout for macOS doesn't produce a HIG-happy visual design.
Posted
by purple.
Last updated
.
Post not yet marked as solved
2 Replies
578 Views
I'm assuming that the Embed functionality that is part of Swift UI didn't make it into the Xcode 12 preview. I don't see it in the Editor menu. I have no context menu that looks like the serving suggestion in the video. Didn't see a reference in the release notes. I'm assuming it's not just my fresh install.
Posted
by purple.
Last updated
.