How to create UI tags in Cocoa Objective-c? - objective-c

I'm looking into building a tagging feature in my Mac app. I would like to do something like in the attached image. Is the UI portion offered natively in Cocoa? If so, what is the class name?

You can use NSTokenField to accomplish that. Start by reading Token Field Programming Guide.

I had to do exactly that a couple of weeks ago. I decided to use NSTokenField as well but ran into quite a number of problems. See my endeavours here. Hope you fare better with your implementation as it gave me a couple of really short nights....

Related

Objective-C and designing a plugin mechanism

I need to design a simple plugin system in Objective C. I would like some advice about how to go about this. Thanks!
Cocoa is your girlfriend: http://www.cimgf.com/2008/09/17/cocoa-tutorial-adding-plugins-to-a-cocoa-application/
Awesome tutorial.
There is always going to the Source. Here is the ADC reference to Plug-ins
There are dozens of ways you could do this, so you might need to elaborate a little on what exactly you're trying to achieve. As a starting point, I'd recommend you look into Cocoa delegates which are usually a great way to integrate new code into an existing framework.

Best Java library for accessing Camera (JMF alternative)

I would like to access a camera attached to my system. basically i would like to capture an image using the code retirieve the image. can someone suggest me a good framework. I went through JMF, but it was last updated 7 years ago. FMJ also lacks proper documentation. Is there any framework available which is good and has good userbase?
Xuggler is pretty cool. It has tutorials too.

Textmate Code Completion Question

I know the ESC key does code completion, but is there a way to get a pop-up(tool-tip I guess) that shows you all the possible choices for a piece of code? As an example, it would be nice when writing Javascript to get a list of available actions. Other apps I've used like Coda do this. I'd like to check out Textmate but I have a hard time getting past this missing feature which I find pretty valuable, particularly as a fairly new programmer who likes to see what options are there as it's a bit of a learning tool for me also. I thought I had found a plugin like what I'm looking for, Dialog2, but it seems to have disappeared as it was meant to be built-in to the never-released TM2.
I've looked around a fair bit for the answer to this question and figured this was my next best option. Thanks.
I don't have Textmate available to try it out, but I believe that option-Esc is supposed to show you the list of possible code completions.
Check out subtleGradient's tmbundle: https://github.com/subtleGradient/javascript.tmbundle
It knows how to auto-wrap for arrays, and objects. Documentation look-up too.

Syntax coloring for Cocoa app

I'm planning to do a Cocoa app that requires code syntax to be colored (in all common languages). Instead of writing my own code highlighter/parser, are there any pre-made solutions available?
Thanks
You might be able to use something like Geshi, but there're also the resources listed here: http://www.cocoadev.com/index.pl?SyntaxHighlighting
Edit
More links:
Syntax Highlighting in Cocoa TextView? Experiences? Suggestions? Ideas?
http://parsekit.com/okudakit/
An excellent solution is Uli Kusterer's UKSyntaxColoredTextDocument. It is fast and has several built-in syntax parsers. It's easy to add new languages.
It's free for non-commercial use and very cheap if you want it for a commercial app.
You can also use the JavaScript library SyntaxHighlighter and embed it into a WebView into your app.
After quite a bit of research trying to solve a similar problem, the simplest approach I found by far is to use a JavaScript library for syntax highlighting combined with a WebView. Spending time writing a syntax highlighter, a fairly complex task, is probably not what you'd want to spend time on.
I settled on using the popular CodeMirror and wrote an open source wrapper for Cocoa: https://github.com/swisspol/CodeMirrorView. You can use similar approaches to wrap other JavaScript based code editors in Cocoa apps.
You can use highlight that is used in QLColorCode :) (however, it's not a Framework that you include in your code, but a command-line utility)
EDIT: Ah yeah, use Geshi, it's probably better :D

Accessing iSight programmatically?

Is it possible to access the iSight camera on a macbook programmatically? By this I mean I would like to be able to just grab still frames from the iSight camera on command and then do something with them. If so, is it only accessible using objective c, or could other languages be used as well?
You should check out the QTKit Capture documentation.
On Leopard, you can get at all of it over the RubyCocoa bridge:
require 'osx/cocoa'
OSX.require_framework("/System/Library/Frameworks/QTKit.framework")
OSX::QTCaptureDevice.inputDevices.each do |device|
puts device.localizedDisplayName
end
I don't have a Mac here, but there is some Documentation up here:
http://developer.apple.com/documentation/Hardware/Conceptual/iSightProgGuide/01introduction/chapter_1_section_1.html
It looks like you have to go through the QuickTime API. There is supposed to be a Sample Project called "MungGrab" which could be worth a look according to this thread.
If you poke around Apple's mailing lists you can find some code to do it in Java as well. Here's a simple example suitable for capturing individual frames, and here's a more complicated one that's fast enough to display live video.
There's a command line utility called isightcapture that does more or less what you want to do. You could probably get the code from the developer (his e-mail address is in the readme you get when you download the utility).
One thing that hasn't been mentioned so far is the IKPictureTaker, which is part of Image Kit. This will come up with the standard OS provided panel to take pictures though, with all the possible filter functionality etc. included. I'm not sure if that's what you want.
I suppose you can use it from other languages as well, considering there are things like cocoa bridges but I have no experience with them.
Googling also came up with another question on stackoverflow that seems to address this issue.
Aside from ObjC, you can use the PyObjC or RubyCocoa bindings to access it also. If you're not picky about which language, I'd say use Ruby, as PyObjC is horribly badly documented (even the official Apple page on it refers to the old version, not the one that came with OS X Leopard)
Quartz Composer is probably the easiest way to access it, and .quartz files can be embed in applications pretty easily (and the data piped out to ObjC or such)
Also, I suppose there should be an example or two of this in the /Developer/Examples/
From a related question which specifically asked the solution to be pythonic, you should give a try to motmot's camiface library from Andrew Straw. It also works with firewire cameras, but it works also with the isight, which is what you are looking for.
From the tutorial:
import motmot.cam_iface.cam_iface_ctypes as cam_iface
import numpy as np
mode_num = 0
device_num = 0
num_buffers = 32
cam = cam_iface.Camera(device_num,num_buffers,mode_num)
cam.start_camera()
frame = np.asarray(cam.grab_next_frame_blocking())
print 'grabbed frame with shape %s'%(frame.shape,)