Make a Quick Look NSView in Swift - xcode

I'm trying to add this feature to my app: when pushing a certain button, open a quick look view of a certain file.
I saw this:
Use Quick Look inside a Swift cocoa application to preview audio files,
but the error written in the comments shows up and the app crashes after trying to go back and forth between files.
Apple's class reference of QLPreviewPanel is quite empty.
Which is a correct implementation? What is wrong in the answer in the question I linked?

Apple's class reference of QLPreviewPanel is quite empty.
They have a lot of bugs currently. You can "View page source" in your browser, or use Xcode built-in help, it's pretty good.
Which is a correct implementation?
It looks like someone has already done it with Swift. I'm not sure if that's the full implementation.
What is wrong in the answer in the question I linked?
QLError() [...] called while the panel has no controller is decrypted this way: some class in the responder chain (your NSView or NSWindow should be there already, unless you have a very complex structure) must respond to acceptsPreviewPanelControl: and two other QLPreviewPanelController methods.

Related

Swift 3 Xcode 8: CoreData self.managedObjectContext.hasChanges returns false

I've been following this guide.
And I ported it to my code, I have the folders being made in my library folder, the file contained is a size of "0 Bytes". Inside my tableView I am able to click and add/delete items. So it does have a connection to CoreData. However when I wish to save the results of the tableview, it steps right over the line. I put a breakpoint in and cannot see the variable (nor what I'm supposed to be looking for).
I've been trying for two days to tackle this now. I've read up on google, was using these as a reference, and still no luck. My code and bindings matches up with the sample code provided.
Reference
any ideas? things to check that I haven't already done? It does seem like a link "disappeared" but everything is all on the same viewcontroller which is what is confusing me.
Figured it out. Right Click under delegate and the saveAction will be visible. Link it to your button. Voila! nOOb mistake. Learning here!

Swift - Is it possible to build the menu bar item outside AppDelegate class in a MacOS ManuBar App?

I'm doing a lot at once and this is quite overwhelming sometimes. Learning how to build a mac os (with menu bar and a settings window) while learning swift and sometimes trying to adapt objective c tutorials into swift.
I have followed this tutorial to help me get started with an app with a menubar. I have made it work, but now I want to improve it a little bit.
All the menu setup in this example is within the AppDelegate class. Since my app has a little more stuff in it, a settings window where I also have to play with tables, I wanted to clean the menu related stuff to a responsible class I called MenuLoader.
I moved all menu building related code from AppDelegate to MenuLoader, and I instantiate MenuLoader on AppDelegate's applicationDidFinishLaunching method.
When I run the code though, the app menu bar item appears for what seems the time it is being loaded, with some breaking points I can see clearly that the objects exist and have expected properties, but then the it just disappears. I'm afraid I'm missing some connection the AppDelegate uses to keep a relation of the menu bar referenced.
So my question is: is it possible to have a separate class handling only the status menu bar instead of having a big mess on the AppDelegate? If you think this might be a matter of my implementation, I'll post some code here, though I'm not sure it will make much of a difference.
Of course it's possible to have a separate class. Moving code into another class doesn't change the functionality as long as your logic is the same.
If something just disappears it's possible that you're not holding a strong reference to that object, and so it gets released as soon as it's out of scope. You might need:
class MyClass {
var:MyObject! // use this to store the reference to your object
...
}
If this doesn't help, please post some of your code.

Adding Custom Objects in Xcode 4.3

I'm working with Objective-C and Xcode for about a year. I customise a lot of generic objects. Few days ago one of my friend asked me a question, but I couldn't answer him. So I try to do something my self. For example:
I created this Custom View:
How can I add this View to the Object Library?. Here:
I don't really know why do I need this. But I decide to figure out how to do this. I hope you could help me with this.
Thanks in advance!
I don't think this will work. You are putting buttons on "top" of a custom view placeholder. The custom view placeholder is used to be able to use - yeah you guessed right - custom user defined views.
So of which class would your view-with-5-buttons-on-top be? I think you are running into a dead end, because that's just not the way to do it in Xcode. If you want to design your custom view graphically, just create a NIB file for it.
I don't think that you can add your own view objects into the object library. Everything I know of are user-defined code snippets which will show up on the right.
Edit
There were things called IB plugins in Interface Builder and Xcode versions prior to 4.
Those were discontinued in Xcode 4 as can be read here for example :
http://xcodebook.com/2011/03/no-interface-builder-plugin-support-in-xcode-4/
Further searches for IB plugin gives a lot more guys telling the same.
Best,
Flo

make a file browser in Cocoa

I really want to make a simple file browser in Xcode kind of like Finder itself, but it just displays one folder as a grid view. Can anyone direct me to a guide?
I recommend looking at Apple's code sample for SourceView.
It's probably a good place to start and should give you enough of an idea of where to begin.

Cocoa Interface Builder's 'Attributes Inspector' like window

I'm making a Cocoa application, and I would like a panel like the 'Attributes Inspector' in Interface Builder. So with big tabs on the top and collapsable/expandable groups. Does anyone know how I can do this?
This is an image of the Attributes Inspector:
Attributes Inspector http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeQuickTour/Art/hello_win_attributes.jpg
So I actually want to make a window like the one shown in the image above.
InspectorKit is FOSS on github.
There's no built-in Cocoa controls to do this. You're going to have to write some custom views which replicate the functionality.
There some good advice for creating custom controls in the answers to this question: Looking for info on custom drawing of interface components (Cocoa)
If you need additional help, I recommend you ask smaller, more specific questions explaining what you've tried and what hasn't worked.
I've written some custom classes to do this- it ended up being less work than I expected. I broke it down into two separate components which can be used independently- the first handles the icons at the top and performs the view switching and the second handles the expandable panes:
My code is available at github and is under the BSD 2-clause license.

Resources