Post

Replies

Boosts

Views

Activity

NSScrollView + NSTextView. scrolling to a specific word.
I have an interesting challenge, but I do not know where to start. given an NSTextView in an NSScrollView, and enough text in the textView to enable scrolling, how do you determine the location of a single word, and jump to it? we see this sort of behavior in Find panels in Most text editors. So it can be done. additionally, I would very much like to find some kind of predetermined... elements in the text. as a link or an image is not text but can be inline with the text (in Attributed strings) I would like to put an element in the text that is not text, but is targetable and capable of being tagged with some kind of reference. Almost like a bookmark, in which I can scroll to. I have determined that I could use URL Links. But they are so fragile.
1
0
823
Nov ’23
Mac swift Xib based doc app deletes a doc when I make changes and then save it.
I have a Mac doc based app. I have save methods setup (they sort of work... I'm trying to get them up and running) I'm using NSSecureCoding, with NSObjects in Swift. It has been unusually frustrating. I have run into something I find wildly difficult to even explain. I can save a new document that has not been saved yet. it loads as expected. but if I make a change to a doc I have already saved, and save that, ny file gets wiped out. my save code is called, and the app wipes all of the data out of the saved file. The file exists, but it's emptied. it goes from around ~200k in size to 2k in size. there's no error that I have identified. It just wipes my file. So I have NO idea if it's something I did. docs are... unhelpful. internet searches... are unhelpful. this is just one of a number of errors I have to figure out, but it is massively complicating everything else. any ideas welcome.
1
0
599
Nov ’23
NSCollectionView drag n drop; Sections are ignored in the drop's IndexPath
I have a doc, xib based project. it has an NSCollectionView, which properly displays the data. including items and section headers. I have drag n drop enabled where I can drop into the collectionView, and I generate a new object. this is NOT a reordering issue (yet) when I drop into the collectionView, if the drop is on top of a HeaderView, the drop is canceled (before it gets to my delegate code.) But more importantly : the Header views are entirely ignored in every step of the drag and drop. the hinting, only ever shows up adjacent to a collectionViewItemView, Never below or above the section header. The drop ALWAYS has a section of zero in its index path. regardless of where the drop is. I tried to override this behavior in both the validate drop and accept drop methods. with a great deal of frustration and struggle I discovered that I cannot compare the placement of my header views, because the frames of those views are all at the base origin point. is this normal behavior? Has anyone else run into this? is there a fix?
0
0
661
Nov ’23
Metal Perspective Martrix issue
new to Metal, following Janie Clayton's book. Ran into a problem creating a proper Perspective Projection Matrix. I'm hoping someone with matrix experience will see this and the issue will jump out. the matrix structures: swift: struct Matrix4x4{     var X : SIMD4<Float>     var Y : SIMD4<Float>     var Z : SIMD4<Float>     var W : SIMD4<Float> metal: float4x4 projectionMatrix; the swift code that generates the projection matrix: static func perspectiveProjection(_ aspect : Float32, fieldOfView: Float32, near: Float32, far: Float32)->Matrix4x4{         var mat = Matrix4x4()         let zRange = far - near         let fovRadians = fieldOfView * Float32(Double.pi / 180.0)         let yScale = 1 / tan(fovRadians * 0.5)         let xScale = yScale / aspect         let zScale = -( far + near) / zRange         let wzScale = -2 * far * near / zRange         mat.X.x = xScale         mat.Y.y = yScale         mat.Z.z = zScale         mat.Z.w = -1         mat.W.z = wzScale         mat.W.w = 0         return mat     } how the shader applies the projection matrix : outVertex.position =  uniforms.projectionMatrix * props.modelMatrix * vert[vid].position; the result here is just the clear color. it seems that the issue is with wZScale. hard coding that to zero and the mat.W.w to 1.0, allows me to at least see my scene, skewed. messing around with those values, it seems like the objects are crushed and pushed through the camera, existing behind it. I'm basically dead in the water here, typing word for word what is in the book. it's pretty darned frustrating. I'm just learning my way around matrices.
2
0
1.8k
Jul ’23
SCNGeometry is difficult to instantiate
Hey. I've combed through the seriously weak documentation, looked for examples (none of which are in Swift) I found an Obj-C example and converted it. It doesn't work. It creates an empty hierarchy of SCNNodes. What is going on here? this is the third time, I've written SCNGeometry code from scratch, using examples from different sources, trying to follow the insanely arcane, undocumented, and openGL-ish design pattern. This time, I've taken Obj-C code, and simply converted it, leaving everything as close to the original as possible.what is going on?// BKPivotNode is a subclass of SCNNode. func genTubeTest(aPivot: BKPivotNode)-&gt;SCNNode{ var retNode = SCNNode() if aPivot.children.isEmpty != true{ for aChild in aPivot.childNodes{ if let bChild = aChild as? BKPivotNode { let sources = [SCNGeometrySource(vertices: [ SCNVector3(x: -1.0, y: -1.0, z: 0), SCNVector3(x: -1.0, y: 1.0, z: 0), SCNVector3(x: 1.0, y: 1.0, z: 0), SCNVector3(x: 1.0, y: -1.0, z: 0)], count: 4 ), SCNGeometrySource(normals: [ SCNVector3(x: 0.0, y: 0.0, z: -1.0), SCNVector3(x: 0.0, y: 0.0, z: -1.0), SCNVector3(x: 0.0, y: 0.0, z: -1.0), SCNVector3(x: 0.0, y: 0.0, z: -1.0)], count: 4 ), SCNGeometrySource(textureCoordinates: [ CGPoint(x: 0.0, y: 0.0), CGPoint(x: 0.0, y: 1.0), CGPoint(x: 1.0, y: 1.0), CGPoint(x: 1.0, y: 0.0)], count: 4 )] let newElement = SCNGeometryElement(data: NSData(bytes: [0, 2, 3,0,1,2], length: sizeof(Int)), primitiveType: .Triangles, primitiveCount: 2, bytesPerIndex: sizeof(Int)) let newGeo = SCNGeometry(sources:sources, elements:[newElement]) let newMat = SCNMaterial() newMat.diffuse.contents = NSColor.redColor() newMat.transparency = 0.5 newMat.doubleSided = true newGeo.firstMaterial = newMat; let newNode = SCNNode() newNode.geometry = newGeo retNode.addChildNode(newNode) } } } return retNode }
10
0
2.5k
Nov ’22
I have a class with an overridden method, and the method never gets called.
this is super frustrating.I have a class, it's one of hundreds.eariler today, it worked fine. I have made no changes. The editor seems to think I have overriden the superClass's method. (you can find that out by just doing it again and looking at the error messages)But, when I compile. my override is never called. In the OTHER subclasses it is called. I have cleaned and recompiled the entire project. I have re-written the method from scratch. I have copied the method from the super class, and pasted it into the subclass, adding the "override" key word.this is not the first time this has happened.
13
0
3.5k
Apr ’22
obtuse error message when trying to add a tag to a file in the finder.
Hi, caught in a loop of unhelpful error messages. Been trying to find a code example to follow, apparently that is not a thing anymore. the docs... for over 20 years now are only half finished. So Im here in the forums looking for guidance. I am trying to set a resource for an existing file URL. the intention is to add a tag to the file. Nothing onerous. Should be easy. Getting the list of tags WAS easy. here's the code as I have it: func setItemTags(atURL:URL, tags: [String]){         do {             try atURL.setResourceValue(tags, forKey: .tagNamesKey)         } catch let error as NSError {             print(error)         }     } I get an error that says: Argument type '[String]' expected to be an instance of a class or class-constrained type ok. seems pretty straight forward, the Array (which is what I get from acquiring the resources... so this doesn't make much sense at all, but whatever.) needs to be a class. clearly it's a Holdover from Obj-c. And it needs to be an NSArray. I SHOULD be able to bridge to an NSArray by replacing 'tags' with 'NSArray(array: tags)' but that doesn't work at all. I get a different error. 'setResourceValue(:forKey:)' is unavailable: Use struct URLResourceValues and URL.setResourceValues(:) instead So no error message is really telling us anything. no matter how much I try, I can't just materialize the answer out of thin air. what I really need is a single example of how to properly use the 'steresourceValue' function of URL, to set the .tagNamesKey. I am astonished that this is not documented anywhere.* *I have found ancient examples of this, which is now deprecated by changes to swift, and is only useful as a source of confusion.
5
1
1.5k
Mar ’22
drawing into an existing CGImage
Ok, maybe I'm hung up on Mac OS X design patterns, just tell me if that's the case.the problem:I need to draw a line on an existing CGImage.There's no LockFocus methods for CGImage, There's no obvious documented way to get the already created Context of a Bitmap in the CGImage. There's no obvious or explicit code explaining the procedure.I have the reference to the image, I have the two points that make up the line, I know all of the code to draw that line... I just cannot make the context associated to that image, the current context. What gives? what is the design pattern? Please tell me where I can read about this.
3
0
2.8k
Nov ’21