How to make my own property attribute in objective-c? - objective-c

I was thinking how could I make my own property attribute, for example:
#property(retain,nonatomic,'myAttribute') int numberOfWheels
#property('unique',nonatomic) NSString productCode
but when I try to get a help from Xcode pressing command button or option button nothing happens
I was looking in this page and many others but no one ask how to make your own attribute, most of then just asking about how to use property attributes or difference between them
I dont know if its possible to make a new attribute, but if its true, could someone help me

The only way to do this is to modify the compiler directly to add this functionality. I have no idea where you'd begin to do that, except to point you to http://llvm.org and say "good luck".

Related

How can I test if an item is anchored?

What is the proper way to test if an item has been anchored? For example, take the left side, I have tried:
property bool isAnchored: parent.anchors.left != undefined
But that does not seem to work? I also tried:
property bool isAnchored: !!parent.anchors.left
which also does not seem to work, I also tried:
property bool isAnchored: parent.anchors.left ? true : false
Any other ideas? There has to be a way to check if an item is anchored but I can not find it?
Unfortunately I don't see any way to do it using the provided/exposed properties. The only thing that determines a valid anchor is the Anchors flag type which is defined in the QQuickAnchorLine::anchorLine member, but that's not exposed to QML anywhere (eg. anchors.left.anchorLine is always undefined). Or in the public C++ API for that matter. The actual QQuickAnchorLines attached to each object are always valid/non-null, as you've discovered.
I think you will need to implement your own flags in whatever routine(s) which set or remove the anchors in your code (I assume that has to be determined somewhere). That is, whenever an anchor changes, set a custom property value. There are also the anchor change signals (leftChanged() etc.) which could be connected to.
Alternatively, you could re-implement your own attached Anchors object in C++ and track whatever properties you want (basically same as the above suggestion but centralized in a C++ class). Here is a good example (I think, not my code) of defining your own anchors lines using a custom attached object. With something like this it would be pretty easy to track/query what is anchored to what.

Is it possible to automatically create a local variable from a method with IDEA

Suppose I have an object of class RandomClass with a method doStuff() which returns an int.
I'd like to do something like this:
Type myObject.doStuff()
Do something which creates a local variable of the type returned by doStuff() (int in this case)
Right now I do that by first typing myObject.doStuff(), use Alt+enter to popup the "Introduce local variable" menu and then use that.
Can I do that faster ?
Thanks.
You can type myObject.doStuff() and then press Ctrl+Alt+V to immediately create the local variable. You will directly bypass the pop-up and that is really all you gain.
You can simplify the key mapping to reduce the number of keys to press for the Extract Variable if it is really necessary.
Generally, no, that's the quickest way to do it.
Given that the doStuff method already exists, I could do what you described with 6 keypresses in about a second and a half. That's pretty quick, I would think...
On the other hand, if it's boilerplate code that you'll be typing over and over, you could consider making a custom Live Template - hit ctrl-j and type something like sout or psvm to see some examples...
Good luck!

NSDocument - how to prevent a document from being marked as updated automatically?

I have a cocoa app that allows the user to enter a query. I'm using an NSWebView with a TextArea HTML object. The problem is, as soon as I type anything into the textarea, my document gets marked as updated. Does anyone know of a way to prevent this?
I've verified that using a NSTextField does not reproduce this behaviour, but I specifically want to go with the HTML/TextArea for styling.
So basically: Can I make it so an NSDocument does not get marked as edited unless I manually call:
[document updateChangeCount: NSChangeDone];
This post on the Apple mailing list seems to match your problem exactly.
The solution suggested is to set a custom undo manager to the webview (sounds like hard work), however a quick-and-dirty hack looks to me like subclassing updateChangeCount and perverting things to your way of thinking.

"No appropriate method" error generated when calling new function using class-defined object

I defined a class called "FilterCriteria" which has a bunch of function .m files (getAMask, getBMask, etc.) associated with it. When I create the FilterCriteria object and call the functions using it, I don't have any problems. However, recently I added another function (which, on a side note, is almost identical to another function that still works), and Matlab returns the error, "No appropriate method, property, or field getHMask for class FilterCriteria."
I've searched online for this problem, but I can't find anything. The file getHMask.m is definitely in the correct folder, so I don't understand why Matlab seems to have such a problem finding it.
Here's getHMask.m's header:
function mask = getHMask(object, quadrant, channel)
Any help would be greatly appreciated. Thanks in advance.
1) A mistake I make sometimes is not saving the file with the correct name. Make sure capital letters are in the right places etc!
2) Another layer of error checking here... You can call methods('object here') (see here) and make sure it lists the method (function) that you are trying to add to it. If it doesn't show up here you should check into the implementation of the method and make sure it's correctly being added to the class you're using for your object.
I had the same problem that's kind of suggested by Ben's bullet #2 and it was driving me crazy. Turns out MatLab wasn't loading the latest version of my class's m-file. I vaguely remembered it gave me a warning earlier about that, because there were old instances of the class in the workspace and to keep from invalidating them it said it wouldn't update the class until I cleared the workspace...
So if that's the problem, restarting MatLab will work, or you can just enter >> clear

Simplest possible way to show two items NSTableView from code?

How I can create a code in XCode 4.2.1 what will create NSTableView and add just couple of items to it?
All what I wanted to do is:
1) Window where is NSTableView
2) I have an array of strings in NSArray which I like to show in that NSTableView
3) All of this should be done in code. So I don't want to learn how to add this action happen when you press button (I know already how to do actions when user click buttons etc), I just want that application launch -> draws the table where is those items from my array. That's it, nothing more.
And yeah I have understood that I do not add items to NSTableView directly. That is not the point in this question. I just mean that I want to show couple of items in that table but I have no and kind of clue WHERE I should add my data from my array.
I have tried to google for example pages for hours (just too many and have not find help) but I will always be stucked in the part when
a) I must do something in the Interface Builder and the images of the interface builder are from version 2.x or 3.x and I have 4.2.1 and it is totally different (new to XCode...). Surely I have drawn my TableView element to UI but I mean delegations etc. Are those necessary at all? Can those be made from source code?
b) Code just does not work anymore because language (Cocoa or Objective-C, I don't know) has changed and I don't know how and what I have to do to make it work on newest version of XCode.
c) There is too much different ways told: "use binding", "you must create new class what is NSTableViewDataSource" etc. I have no any kind of clue what is preferred way, is another way optional or it is "you should use this because another is going deprecated soon" or something.
So please, can somebody give help in step-by-step what I exactly have to do? Should I create some bindings? If so, how and where? Do I have to create DataSource component myself? Are those ways valid any more? If I have to, how I can create it? Create a new class and implement it as a NSTableViewDataSource and then use it? Is that way valid any more and if it is, can sombody show code what is as simple as possible?
I have also checked Apple Documentation page many many times, checked those example codes but there is just too much totally unrelated stuff that I just don't understand at this point so they are totally useless (I mean, I don't know what is required for this task, what are not etc.
I would be very happy if somebody can help short tutorial step-by-step what to do. I mean "step-by-step" like:
1) Create new project
2) Draw NSTableView in project
3) Create new class with this name
4) Write this code: blah blah blah
5) Create another class with this name
6) Write this code
7) Run and see those items from array in NSTableView using (bindings/datasource/whatever is preferred).
Thanks :)
Your tableview needs a datasource. Your datasource is a custom class, it implements the "NSTableViewDataSource" protocol. This protocol contains a few methods that you can use to tell the tableview what data you got.
this includes the objectValue ( the value of the NSCell that is displaying your data on the specified row, and a method that returns the amount of rows the tableview has ( the amount of items in your array ).
Here a tutorial I found by googling:
CocoaDev.com NSTableView tutorial
You can also implement the NSTableViewDelegate protocol which allows some greater control. Like what rows you can select, or some extra configuring of a custom tableview cell.
I must say that back in the day when I started developing desktop applications ( only had experience with web technologies ) that this design pattern confused me as well. Hope you will get your mind round it soon.