NOOB Problems with getting results from code (more specificly with NSComboBox) - cocoa

I know that this is probably a simple question but here is what I'm racking my brain to figure this out:
I know that this:
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index {
return [midiModelContents objectAtIndex:index];
}
will return the item at the index provided. My question is, what code do I need to use to call this routine?
I've tried something like this:
NSString *curData =(comboBox: midiModel objectValueForItemAtIndex:0);
but I get a "error: 'comboBox' undeclared"
Can anyone help me with the concept that I'm messing up?

First, you might want to read the Objective-C Programming Language to learn the correct syntax for sending messages to objects, including yourself.
You get a nonsense error message because you have written (what is in Objective-C) nonsense code. A valid Objective-C message expression would compile and run successfully, but I don't think it would do what you're expecting it to.
You see (and this is the second thing), comboBox:objectValueForItemAtIndex: is not ordinarily a message you send to yourself. The combo box sends that message to you when you are its data source. Data sources are a variation on the delegate pattern that is among the things described in detail in the Cocoa Fundamentals Guide.
(You can send the message to yourself, and it may even make sense to do this if you deliberately want to go through the same object-value-retrieval path the combo box does, but this is not what you need to do to make a combo box work.)
Both the Language document and the Cocoa Fundamentals document are essential reading for every Cocoa programmer, along with the Memory Management Guide for Cocoa. You should read all three documents from start to finish.
The solution to your immediate problem is for the object that responds to comboBox:objectValueForItemAtIndex: to be the data source of the combo box. You will probably hook this up in IB, in the same nib where you created the combo box.
If none of that makes any sense, then all I can suggest to you is, again, to read those documents. They will explain everything.
If you really did simply mean to ask yourself for the object value the same way the combo box does (i.e., you have the combo box working already and intend to get the object value the same way for some other purpose), then you still need to read the Objective-C Programming Language document to learn the correct syntax to send yourself that message.

Related

Creating a new snip% with Racket

I am trying to create a new GUI element within DrRacket's text window, like picts or syntax objects. As far as I can tell, the most standard way of doing this is with a snip%.1
Unfortunately, the documentation for creating new snips, while comprehensive, is a bit impenetrable and leaves some questions to be answered.
For starters, what is the difference between a snip% and a snip-class%? Why do these need to be separated out into two classes, rather than simply being combined into one class? Is it because multiple snips will use one snip class?
Second off, what is snip-reader<%>? Not only why does it need to be a separate class, but why is the module providing it supposed to be installed?2 If it does need to be a new class, why can't it just be referred to directly. Why go through this whole process of constructing and then parsing a string of the form: "(lib ...)\n(lib ...)"?
I mean, there might now be any reason for this design, and it might just be a remnant of an old API. If so, has anyone thought of making a new more consistent API? Or if there is a reason for this design, can you please tell me what it is, as the docs don't seem to make that clear.
I mean, as of right now, I can copy/paste the sample given in the docs on creating a new snip. But I'm having a hard time understanding the design going on here, so I can use them properly.
1I know there are other ways to do it, but I also want to have interactive buttons and whatnot.
2I know it doesn't need to be installed as a library per se, but the documentation seems to strongly push you in that direction.
Okay, I think I finally found the answer. Broadly speaking:
The snip% class includes the methods for drawing the snip, telling the editor how much space to reserve for the picture, and handling events such as mouse clicks.
Next, the snip-class% class is used for encoding and decoding snips. This must be a separate class because when saved to a file, the editor needs to encode what type of snip it is, and for obvious reasons it can't just put the literal snip% class in there. The value it stores in the file is the snip-class%'s 'class name'. This can be anything, and as long as the editor has the classname associated to a snip-class%, it can be loaded. Additionally, if it is of the form "(lib ...)" or "(lib ...) (lib ...)" Racket will just automatically load it into the list for you.
Nothing 'needs' to be installed per se, its just the easiest way to go about it. Otherwise you manually need to tell the editor how to handle the snip before actually loading the file.

Audio Recording Semantics Issues

So I am not very good with computers and have to create my first app for a project. It's going fine so far - essentially I am trying to create an app that records and saves data. Right now I'm still getting the record part down, since Xcode is having periodic issues. I am using this link for setting up the code:
http://www.techotopia.com/index.php/Recording_Audio_on_iOS_7_with_AVAudioRecorder
Unfortunately, I am running into 2 types of semantic errors, two red, two yellow. They are all in RecordModelController.m - the first is like this:
return [self.pageData indexOfObject:viewController.dataObject];
Xcode claims that Property 'dataObject' isn't found in any object or forward class in 'RecordDataViewController'. That's actually my two red errors, they just sound very similar so I paraphrased them into one. The yellow error, however, repeats itself twice on the same line of code, which is:
return [self viewControllerAtIndex:index storyboard:viewController. storyboard];
The yellow issues on these lines of code (again, repeated twice) is "Incompatible pointer types returning 'RecordDataViewController *' from a function with result type 'UIViewController *'" - I genuinely tried to look in RecordDataViewController.h and couldn't make sense of this. Like I said, bad with computers, not sure why I'm having this issue, and I know that it's probably something basic.
If anyone would be willing to help me out with how to deal with issues like this, that would be great. Thanks, and sorry for my incompetence.
The red are called errors. The yellow are called warnings. I'm going to suggest you look at a few beginning Xcode/iOS programming tutorials so you understand the basic concepts of how view controllers, arrays, etc. work in objective-c. The best place to start for someone completely new as yourself is here: http://www.raywenderlich.com/tutorials
Hope this helps!

Saving files in xCode and making graph

I am new to programming. Now i have been learning for a few weeks and am now making my first app. Probably not for public, just for me. At least for now. So here it goes. I want the user to be able to enter his information (for example weight or something like that) into textField and then save it, so I can later form a graph (for example of weight loss through time). Now the graph should not be that much of a problem, since there are many tutorials on that. I am more interested in how to enter information, then save it so it can be later accessed. Any help? What should I read?
Thanks!
Working with UITextFields in Objective C is pretty straightforward - you can grab the NSString from such an object using the 'text' property. Use plists for storage locally, or JSON.
Look at core data tutorials especially related to Apples' doc on “Core Data and Cocoa Bindings”
CoreData shows how to setup objects and save them to a file or simple database. Cocoa Bindings are how to make input screens pass data to object models.
You should be able to write a program to enter weights, save them and show in a table without writing any code.

Converting NSString to keyCode+modifiers for AXUIElementPostKeyboardEvent

Edit: Turns out, I was misled during my initial explorations of the accessibility APIs. Once I found the secure text field in the AX hierarchy, I was easily able to set the value. Not sure what to do with this question beyond that, but I wanted to update this for future searchers.
I'm working on some code that will post keyboard events to targeted applications using the Accessibility APIs. So far, I have been able to write a trivial app that allows me to type in a string value and then post keyboard events with those key codes to the targeted application. In reality, the strings would be read from another location.
What I have not yet been able to figure out is how to ascertain whether and which modifier keys should also be posted. For instance, when I type Hello, world! into my test application, the input is sent to the other application as hello, world1 because I am not yet including the modifier keys to create the upper case H and the exclamation point. This is made doubly complicated by multi-keystroke characters like é or ü. Sending é sends a raw e with no accent for example.
Is there a simple method I am overlooking for discerning the modifiers to combine with a keycode for creating a particular NSString or unichar? If not, does anyone have a suggestion of how to proceed? So far, the best I have come up with is calling UCKeyTranslate with all possible modifier combinations until I find one that matches the unichar I get using -[NSString characterAtIndex:] I'm not sure this is scalable or reliable, though, given the multi-keystroke nature of some characters as noted above.
Thanks in advance!
This probably won't help. But just in case: Is it really necessary to send keyboard events? Because that is going to get really difficult if you need to support, say, Kotoeri.
It's a simple matter to override insertText: and doCommandBySelector: and send the results of the key sequence, rather than the individual keystrokes.
I have found a example which does the trick but it's incomplete:It will not be a general solution in any case ...how can this handle multiple keyboard layouts ?
There is an cgquartz obsolete function to do so: CGPostKeyboardEvent (not sure it's possible to pass only the char?) may be can still be used (marked undocumented with some side effect to but .. ).
EDIT: UCKeyTranslate as a way to build a dictionary. Interesting but how the OS do this? A better answer should be hidden somewhere !

.NET/Winforms: need an example for a nice UI for exception displaying

I'm writing a little developer tool which will (among other things) display exceptions thrown from the code that the tool is currently inspecting. Since it is a developer tool I would like to display as much information about the exception as possible (at the least type, message, stack trace and a recursive InnerException) and do it in a way that is easy to comprehend and analyze.
Unfortunately I cannot think of a nice UI for this. Are there any good examples out there? I have access to DevExpress components if that helps.
Starting with the VS display, I'd look for:
omit null values (such as HelpLink == null, or InnerException==null)
Don't nest InnerException, it's basically a stack so represent it as such
In StackTrace, you could make the file name clickable (or at least easy to pick out and copy).
In StackTrace, Emphasizing the actual class and function name to make it stick out from the full namespace and signature garble.
Some more data reduction is possible, e.g. exception type displayed twice, but this takes careful handling not to swallow information either
You could consider a HTML view, either making it interactive by catching clicks, or using javascript.
Well the Visual Studio one does a fair job! I can't seem to upload an image from this PC, but there's an image here if you haven't seen it.
Everything shown in a dynamic table/tree-like structure, you can drill down into inner exceptions etc, everything is copyable, and there are expandable viewers for certain things (e.g. stack traces). Not pretty, but functional.
Whatever you do, make sure that the developer can copy and paste all the relevant information!

Resources