Save NSTextView in NSMutableArray and read it
-
27-09-2019 - |
Question
My question is the following,
I have an NSTextView
and I want to do 2 things :
First save this textview in an
NSMutableArray
and assign a X,Y position to it in this array.Secondly, get this textview from the
NSMutableArray
and display it at the position I've set when I saved it in the array.
Anyone have an idea of how do to such things?
Solution
First save this textview in an NSMutableArray …
Why?
… and assign a X,Y position to it in this array.
NSArrays aren't two-dimensional; they are one-dimensional, and that dimension is numeric and sequential (i.e., valid indexes are only 0 ≤ idx < count, and existing indexes will change if an object at a lower index is removed).
To map a point to an object, you would need to wrap the point in an NSValue object and use that as the key in a dictionary.
Secondly, get this textview from the NSMutableArray and display it at the position I've set when I saved it in the array.
Again, why? It sounds almost like you're trying to reinvent nibs.