Post

Replies

Boosts

Views

Activity

NSKeyedUnarchiver failing to unarchive custom types or Arrays
I'm fit to be tied, so I apologise for any harsh language.I have an NSCoding compliant class hierarchy (mac os + swift)And I am adding support for drag n drop.This requires adding NSPasteboardReading/NSPasteboardWritingwhich has been an abysmal experience. I got it working, but not correctly. Now I'm trying to do it right. And something that SHOULD just work, in the context of doing this work is failing to produce expected results. I've already spent too much time trying to guess what the ---- is going on.upon completion of my drop, the source object is asked to provide a "propertyList." I used to encode my entire object and then in the init(withPasteboard) method I would copy the values from the instantiated resulting object to self. Which is a stupid and horrible way of doing the work, But at the time: after 2 weeks of literally trying random things with the pasteboard (lack of examples and documentation) was the only thing that worked.Now, I am encoding the properties of the object, which includes 2 arrays of custom objects (which are both NSCoding compliant, and have been observed correctly encoding and decoding thousands of times.)so it looks like this: func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? { do { let archiver = NSKeyedArchiver(requiringSecureCoding: false) archiver.encode(name, forKey: "name") archiver.encode(self.type, forKey: "type") archiver.encode(children, forKey: "children") // the problem is channels as follows: archiver.encode(channels, forKey: "channels") archiver.finishEncoding() let data = archiver.encodedData return data } catch { //debugPrint("archiveFailed for drag of node in toolbox") } return nil } required init?(pasteboardPropertyList propertyList: Any, ofType type: NSPasteboard.PasteboardType) { super.init() if let data = propertyList as? Data{ do { //let newObject = try NSKeyedUnarchiver.unarchivedObject(ofClass: docDataObj.self, from: data) let unarchiver = try NSKeyedUnarchiver.init(forReadingFrom: data) self.name = unarchiver.decodeObject(forKey: "name" ) as! String self.type = unarchiver.decodeObject(forKey: "type" ) as! String if unarchiver.containsValue(forKey: "channels"){ let anObj = unarchiver.decodeObject(forKey: "channels" ) if anObj != nil{ if let objTest = anObj as? [docDataChannel]{ self.channels = objTest } } } if unarchiver.containsValue(forKey: "chidlren"){ self.children = unarchiver.decodeObject(forKey: "children" ) as! [docDataObj] } } catch { //debugPrint("initing from property list failed trying to unarchive") } } }you'll notice a little cottage industry popping up around the property "channels"That's where I always recieve a nil value from the unarchiver. I tried unarchiving every single type (Bool, Double, Float...) that unarchiver supports. There's nothing to unarchive for that key.But I set it. With classes that easily archive elsewhere. I have followed the debugger, and the encode method is called on the contents of the channels array. As far as can be told, the objects are encoded.AND the unarchiver reports that there is a value for that key. every single time. it returns true.the children array... that's empty in my testing, but there IS a value for THAT key.so the unarchiver swears it has a value that it doesn't, that I can confirm is set. what gives?
2
0
3.0k
Dec ’18
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.1k
Feb ’18
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.5k
Aug ’16
autolayout is terrible
I have a very simple split view window. everything is laid out, but auot layout is screwing everything up.wish i knew why auto layout jacknifes my Ui.the splitview is the top level view in the window. it is horizontal, and there is a text field in the rightmost view in the splitview.the splitview is tied to the window top, bottom, trailing and leading.at that point, everything works as expected. when compiled, the split controls work just fine.the problem, is when I try to add constraints to the text box. I put top, leading and trailing constraints on. all to superview. IB actually reversed the first item and the second item in the top constraint, thought I caught the issue. But alas, nope. When I run the app, the splitview became a piece of crap. The split control allows you to drag it, but when you let go, it snaps to some point that it won't let go. It will not under any circumstances behave like a splitview any more. There is no justification, there is no reason, there is no logical argument for this kind of behavior. But now I need to dig through the documentation and try to understand the short comings of the autolayout engine. Ideas welcome.
7
0
2.7k
Sep ’15
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)->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.3k
Jul ’15