So I've created a class in boo that has three properties, Name as string, required as bool, read as bool.
Then Im going to create a method(SetDefault) that goes through the array of this type and sets all required properties back to true, and read back to false. Actually now that I think about it, Im not sure if it makes sense to have that as a method of the class. Doesn't matter.
Bottom line is Im declaring an array of this class type i've created.
testvar as (MyAttribute) = array(MyAttribute,10)
Once I've declared my array of this class, Im unable to reference any of the properties by using...
testvar(0).Name
The error is "It is not possible to invoke an expression of type (MyAttribute)"
I assume to use an array because they're all going to be the same data type. Is an array to correct type to use and if so what am I doing wrong?
Try using square brackets for array member access i.e. testvar[0].Name.
Related
I have a custom method in an ABAP class.
I used the 'Where used' tool to show where the class is called from but, as it turns out, it's called from somewhere else I didn't expect.
So what's the best way of showing a complete list of everything that calls the method?
Due to the wonders of object-oriented programming, an instance of a class can hide behind a reference to one of its base classes or interfaces it implements. For example:
DATA foo TYPE REF TO z_my_interface.
CREATE OBJECT foo TYPE z_my_class.
" lots of more code
foo->bar( ).
You can not find this reference to z_my_class->foo with its "Where Used" list, because at that code location foo could also be a reference to an instance of any other class which implements z_my_interface. But you might be able to find this if you don't just look at the where-used list of the method but at the where-used list of the whole class or the interface / base class which declares the method.
And then there are evil dynamic programming tricks like this which determine methods and classes at runtime:
DATA foo TYPE REF TO object.
CONSTANTS: classname TYPE string VALUE 'Z_MY_CLASS',
methodname TYPE string VALUE 'BAR'.
CREATE OBJECT foo TYPE (classname).
CALL METHOD foo->(methodname).
There is no chance to find this with the where-used tool. But if the class- and/or method name does actually appear in the code (it might not, for example if they are read from a customizing table) then you can use the report RS_ABAP_SOURCE_SCAN. This handy little tool allows you to select a set of ABAP programs and search for strings (and even regular expressions) within their sourcecodes.
However, if you know the method gets called when you do something specific as a user and just want to know where, then it can be easier to just set a debugger breakpoint in the method, run into it and check the call stack.
Sorted using the code_scanner transaction.
I'm showing the contents of an array of strings with an NSTableView via binding through an Array Controller.
I have "NSString" in Class Name in the attributes inspector for the Array Controller and in the Model Key Path of the Array Controller's binding inspector I have the path to my array. And I have the only column of the table bound in its Value section to the Array Controller without Model Key Path specified (it's just an array of strings).
As a result, the array's strings are displayed fine in the table. But I can't edit any of the rows:
2015-06-17 15:48:44.285 ProjectName[9043:123132] An uncaught exception was raised
2015-06-17 15:48:44.285 ProjectName[9043:123132] Error setting value for key path of object five (from bound object <NSTableColumn: 0x618000082d50> identifier: (null)): [<Swift._NSContiguousString 0x608000045d60> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key .
"five" is the fifth string in the array that I was trying to edit. And as you can see there is a gap in "path of" because the Model Key Path is empty for the column's values.
So do I somehow refer to the string itself in the Model Key Path to make the array editable via the table?
The Class Name should absolutely be set to a valid class. The bigger problem is that the array controller doesn't really play nicely with arrays of strings. There's no (reasonable) way to use -setValue:forKey: on a string since the string is itself what's being edited (replaced), not some property (like "displayName").
I know it seems wasteful, but if you really must use an array controller (more on that in a moment), you should just create a class with a string property and set that as the controller's class name and maintain an array of that class instead of plain strings. Say your array of strings represents tags. Make a Tag class with a name property of type String (or NSString). Set your controller's class name to Tag. This way, there's a key path to which to bind.
But if you really don't see yourself needing anything but an array of strings, you could just use the standard (and infinitely more flexible) [NSTableViewDataSource][1] protocol and good old-fashioned actions triggered by buttons (like Add and Remove). This way you're not fighting the Cocoa Bindings / KVC / KVO mechanisms for what in this case amounts to too-primitive a type (string) for a very abstract controller.
As to amount of work, it's almost "six of one half-dozen of the other" but not quite -- I'd go with the "make it a class with a name property" route for two reasons: 1) It's less work than spinning up a whole table controller / data source, and 2) It's likely you'll later wish you had a more extensible class instead of a simple string for a "list of stuff" even if you don't think so now.
I'm a bit confused why my NSThread cannot be instantiated using a selector due to a runtime error
target does not implement selector (*** -[FileSearcher processFilesAsync:])
The function is defined like this
func processFilesAsync(#data: [String])
and the NSThread will be created this way:
NSThread(target: self, selector: "processFilesAsync:", object: itemsPerThread[i])
"itemsPerThread" is just a dictionary with a String-Array as values.
As far as I know this should work as the method I want to invoke defines an argument and the selector I pass into NSThread's init() method indicates that the target method expects exactly one argument.
I already tried using Swift's "Selector" type instead of only a string but this didn't work as well. I also tried to change the method's type from "[String]" to "AnyObject" which didn't work, too.
Does anybody have a clue what might be wrong?
All of the code above lies within the same class.
I'm using Xcode 6 Beta 5.
Edit
I figured out that is has to do something with the parameter. I implemented a dummy method without parameters and tried to set this as target and it worked. As soon as I modified it to use a parameter as well -> same as above.
Found it. All I had to do was to change the parameter's type from AnyObject to AnyObject?. It even works with specialised types (in my case [String]? instead of [String]).
Of course, because you can call it nil as parameter...
Is there some way in Xcode to enter an object's name, and then get a list of the methods that can be used with that object, sorted either hierarchically by inheritance or by return value type?
I know you can get a list of methods by pressing Control-Space after entering the object's name in standard bracket messaging syntax; however, this list often contains numerous methods that are not applicable to the given object. As a result, you still have to scroll through a bunch of garbage, and then look up the class definitions for the object, or reference custom object implementations you have created in order to see which methods will work.
I know that I can use a With statement to make repeated references to a single object:
With myObj
.StringProperty = ""
.BooleanProperty = False
End With
However, what I want to know is: is there a shorthand for referring to the original object in the With statement? In the above example, can I refer to myObj without explicitly typing myObj as I'm already working with it.
No you can't, but it wouldn't mean much anyway. With just sets the default scope to the object expression that follows it. If you need a reference to the object this doesn't help unless the object is one of the very few that has a .Self property, which is quite rare.