NSMutableArray to String and Back again... As datasource!

So here is my problem now:

The user types in character(s) in a text field to have them removed from the table view.
Then once they hit submit:

I get the character(s):
set mychar to CharactersToRemoveTextField’s stringValue()

Then I get the contents of my datasource as a string:
set mydata to myDataSource’s componentsJoinedByString_(“,”)

Then I do my character removal:
set newdata to replaceChar(mychar as string, “”, mydata as string)

Now here is where I’m stuck.
The string I get in the variable newdata looks like the following:
{
column1 = "Digital ";
column2 = First Name 1;
column3 = Last Name 1;
column4 = “New York”;
},{
column1 = "Digital ";
column2 = First Name 2;
column3 = Last Name 2;
column4 = “New York”;
}, etc… etc… etc…

The commas are how I joined all the records.
The replace function removed all the letters the user specified…
But now taking this new format how do I tell the NSMutableArray which is the datasource of the TableView
to initialize itself with this crazy string and do it properly?

Any ideas anyone?

Right now the only way I’ve managed to get it to work is to process the txt into chunks are re-enter them one row at a time into the now blank datasource using addObject_(newrow)

I imagine that there should be a way if using that string with the records in it as is in one shot…
no? anyone?

It’s a little hard to tell what you are doing here. Are you actually using a data source rather than bindings to populate your table (and by data source I mean an object that implements the NSTableViewDataSource Protocol)? If you use bindings, you should be able to just select the text you want to delete right in the table and delete it. Is there some reason you want to do it via a text field? Also, are you trying to delete something from one field in one row with this, or is this some more global delete where you’re deleting something from every row or every column? I really don’t think turning your array into a string is the right way to go about this.

Ric

This was something I built a long time ago using AppleScript studio.
Im trying to convert it to the new AppleScript Obj C version because my old one no longer works with the new apps and systems.

When your dealing with 10k or more rows of data, your not going to go line by line deleting certain wrong textual elements. You just want to be able to type in some text and have it go through and remove what you don’t want.
As I wrote above, the long way of doing what I needed was to process out the whole string value using AppleScript
and then repopulate the MSMutableArray ( datasource ) for the Table View.

I was hoping that since the array method componentsJoinedByString_ gave
me a bracketed string value, that at the end of that I could just put that
back in and have it all work. Call me lazy I guess.

Why not just loop through all the records, searching for the bad characters and replace them with what you want, like so (where theData is an NSMutableArray with your data):

repeat with anItem in theData
            repeat with aKey in anItem's allKeys()
                if anItem's valueForKey_(aKey) as text is badText as text then
                    anItem's setValue_forKey_(replaceText,aKey)
                end if
            end repeat
        end repeat

This would work for values, you would have to have a different method if you need to change the keys as well.

Ric

Actually Thank YOU!
That looks like it will work nicer still.
Thanks a bunch!