How to specify and use arrays in .h and .m files?

Ok, this is pretty basic. For regular variables, no problem.
(in .h)
@interface Mine : NSObject {
int x;
@property (assign) int x;
@end
(in .m)
@implementation Mine
@synthesize x;
@end
But, when I want to specify an array of objects, it fails, with "error: bad property declaration".
(in .h)
@interface Mine : NSObject {
int x[15][10];
@property (assign) int x[15][10];
@end
(in .m)
@implementation Mine
@synthesize x;
@end
If I don't use @property and @synthesize, I can use these arrays just fine in the .m file.
However, the problem I run into, quite often is that I cannot use these without a warning, which usually causes an exception:
x[myX][myY] = s;
or
[obj getX:myX :myY];
gives a warning "assignment from a distinct Objective-C type" or "obj may not respond to -getX" which usually ends up with an exception:
2009-08-17 16:56:00.512 AppName[9638:20b] * -[Mine getX::]: unrecognized selector sent to instance 0x103a800
2009-08-17 16:56:00.538 AppName[9638:20b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[Mine getX::]: unrecognized selector sent to instance 0x103a800'
2009-08-17 16:56:00.548 AppName[9638:20b] Stack: (
807902715,
2426465851,
808284155,
Can someone tell me how to do this properly?
My app wants to create 2 arrays of 15x9 to manage a playing board on an x,y grid.
I want one array to be of type NSString, and the other to be of class Piece (one of my own classes). In some places it works without the @property declaration using a custom getter and setter, but in other places the exact same code gives me one of the errors above.
What am I missing?

Still working this out. In my App, I really only use the "NSMutableArray* cells" to use as a representation of my initial layout, built from a string obtained in my scene plist file. (sceneTableau)
An example board can be seen at http://reststop.homeip.net/dev/Picture4.png for those interested in seeing what the working code does.
- (Board*) setupBoard:(Board*)b {
if (b) {
int loc=0;
b.cells = [[NSMutableArray alloc] initWithCapacity:(boardWidth*boardHeight)];
for (int n=0; n<boardHeight; n++) {
for (int m=0; m<boardWidth; m++) {
NSRange myRange=NSMakeRange(loc*3,2); // get first 2 of 3 chars
NSString* t = [b.sceneTableau substringWithRange:myRange];
[b.cells insertObject:t atIndex:loc];
[t release];
loc++; // increment to next piece
} // for m
} // for n
}This works great, doing my own math for x,y. In fact this initialization loop ONLY used m,n for documentation and could simply be "for (int loc=0; loc<boardWidth*boardHeight; loc++)" to shorten the code. Since I don't ever actually modify the NSString*s I could make the setter routine for cells be an empty void method, e.g. "- (void) setCells:(NSString*) {}".
I also noticed a couple of method in the NSString.h file:- (NSArray *)componentsSeparatedByString:(NSString *)separator;
- (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator;which would allow me to simply use:b.cells = [b.sceneTableau componentsSeparatedByCharactersInSet:whitespaceAndNewlineCharacterSet];since my sceneTableau string is simply 135 sets of 2-character codes separated by a space or a newline.
Taking this in the other direction, I could dispense with the cells array and simply use the sceneTableau field and my getter routine would be:- (NSString*) getCells:(int)loc {
NSRange myRange=NSMakeRange(loc*3,2);
return [b.sceneTableau substringWithRange:myRange];
} (I may go ahead and make this change as it is a little more compact and I don't use this array except to initialize the display).
However, for the pieces, I do need to keep an array, as there is more structure to the objects, and some objects will move from one position to another and the display will need to be redrawn after each move, changing the appearance of at least 2 positions and as many as 4 positions.
If I did need to modify the contents of a cell, then I presume that I should really use objects of type NSMutableString* instead of NSString, and then the proper way to set a new value would be:
- (void) setCells:(NSString* s) {
NSMutableString* c = [self.cells objectAtIndex:(x+y*boardWidth)];
[c setString:s];
I am not sure what I need to do in the way of releasing c in this context. Does c go away at the end of the invocation, and no longer points to anything, or do I need to assign nil, or release c?
I presume I could also do as my current code does[self.cells replaceObjectAtIndex:(myX+myY*boardWidth) withObject:s];but again I am not sure what I need to do about release. I gather that the NSArray handles retaining and releasing the objects which are put into or removed from its instance, and they will all be released when I release the NSArray in my dealloc method.
Based on this, I do need to rethink my NSMutableArray* of pieces, as I will need to write methods that move the pieces and my earlier model does not allow them to move freely without having to perform some coding gymnastics in Objective-C. I will still need to use an array, NSMutableArray most likely.
Have I missed anything?
A quick question on my "setupBoard" routine above. You may have noticed that it takes a Board* and returns a Board*. I currently have to use[b setupBoard:b]; which seems wrong, but it works. What is the proper way to define and invoke this message so that my code would look more like this???[b setupBoard];
and then to finish and do my releases
[b upsetBoard];Is it correct Objectivc-C syntax to have a method that manipulates the contents of an object, such as my setupBoard method, and to say:invocation:
[boardPointer setupBoard];
implementation:
- (void) setupBoard {
if ( self ) { // test for non-nil
[self.cells = [self.sceneTableau componentsSeparatedByCharactersInSet:whitespaceAndNewlineCharacterSet];

Similar Messages

  • How to download and upload files in Java?

    Hi, everyone
    How to download and upload files in Java? Do you have some references about this issue or some valuable web link�? Thanks!
    Best Regards,
    Hai.Ren

    This is too vague a question, please be more specific. What protocol would you like to use? HTTP? FTP? Something else?

  • How to copy and paste files to Time Capsule

    I thought it could be used as an external disk.
    Do you guys know how to copy and paste files directly into Time Capsule?

    I thought it could be used as an external disk.
    An external disk...also known as a local disk....connects directly to a computer using USB or FireWire.
    The Time Capsule is a network disk, since it connects direct to a network. As such, it s a SHARED network device
    Open a Finder window and look for the SHARED heading on the left side of the window. The Time Capsule icon should appear there. Click on the Time Caspule icon.
    A folder, representing the Time Capsule drive named "Data" (unless you have changed the name of the drive) will appear to the right
    Double click on "Data" to mount the Time Capsule drive on the desktop. You may need to click "Connect As" and enter the Time Capsule device password the first time that you do this.

  • How to copy and paste file in mavericks

    how to copy and paste file in mavericks?

    Spoombung wrote:
    I actually can't get copy and paste to work in Mavericks!!!
    Is it me, or is there something wrong with it? I can hardly believe this was overlooked....
    Obviously it was not overlooked.
    Select a file, go to the edit menu and choose Copy, open another folder and choose Paste from the edit menu.
    What happened (error messages etc)

  • How to read and XSD file in java prospective in NWDS

    Hi !!
    anybody can help me that
    how to read and XSD file in java prospective in Netweaver developer Studio
    Regards
    Abhishek Agrahari

    I guess you can make it more clear...

  • How to read and write files using flex?

    Using flex, we would like to make some utility that will do a
    lot of reading and writing from local files.
    The writing is what I am more worried about. How is this
    possible?
    I want to make .zip files containing many xml files, and some
    assorted media files such as .swf jpeg, html, etc.
    I am new to flex btw, I've never used it properly before, and
    this is the main concern I have with flex, which is that it doesn't
    let me write and read lots of files.
    Mainly we are looking for a good cross platform solution that
    will let us develop an app, and flex looks professional and it is
    cross platform. The "internet app" side of things, isn't so much
    what we need really.
    Would wxWidgets be better suited to our needs?

    The Flash player sand box will not allow reading and writing
    local files. If you want to use Flex to create a desktop you will
    need the Apollo runtime. The alpha is available at Adobe
    Labs.

  • How to upload and download files and images using ibm db2?

    For my project i need to upload tutorials in pdf files and doc files to db2 and need to display them in jsp page.and also i need to insert images into db2.Please help me if u kno any of these.
    Thanks in advance.

    UsthadThegreat wrote:
    For my project i need to upload tutorials in pdf files and doc files to db2 and need to display them in jsp page.and also i need to insert images into db2.Please help me if u kno any of these.
    Thanks in advance.You know one of the most key elements of getting help in programming is to post sections of code, or preferably, working examples and then ask specific questions on things you would like to improve, don't understand, or just doesn't work.
    Without some displayed effort on your part, you are going to be fairly hard pressed to get any type of help.

  • How to open and save file like the Notepad Demo do?

    I am a newer to Java Web Start. I found that in the Notepad Demo, when user try to open or save file, a message box appear and give the user some security suggestions.
    In my application, I used a JFileChooser and set the <security> element to <j2ee-application-client-permissions/> in the jnlp file. But the application will thow an exception:
    access denied (java.io.FilePermission C:\Documents and Settings\Administrator\desktop\Java Web Start.lnk read)
    Can someone tell me how to solve this problem. By the way, where can I find the source of the Notepad Demo. I want my application to open and save file just like the Notepad Demo do.

    The Notpad demo uses the JNLP api to read and write files. The api doc can be found at:
    http://java.sun.com/products/javawebstart/docs/javadoc/index.html
    Although the Notpad demo source is not available, there is other sample code available at:
    http://developer.java.sun.com/developer/releases/javawebstart/
    Included here is the webpad demo, which uses the FileOpenService and
    FileSaveService API's.

  • How to cffileupload and store file paths in a database?

    I'm using CF 9 and have multi-file uploading working. What I need help with is a help desk type page that will display the filenames with links to the files that are uploaded with the form that a user submits. When I view an admin page, I need to see the email form results with a list of the files uploaded and links to where they are.
    Any ideas on how I can get an admin page to display only the files associated with each form submission? I'm assuming that I need to find a method of stroring each uploaded file path to a database but I don't know how to do that. Any help would be appreciated. Thanks

    You could proceed as follows:
    1) Create a database table named uploadedFile. The columns could be, for example,
    upload_id: INT, autoincrement, primary key
    datetimecreated: DATETIME
    serverfile: VARCHAR(50)
    serverdirectory: VARCHAR(30)
    2) Do your multi-upload, for example,
    myMultiUploader.cfm
    <cffileupload url="myUploadFiles.cfm" width="600" ... etc>
    myUploadFiles.cfm
    <cffile action = "uploadAll" destination = "c:\myUploads" nameConflict = "overwrite">
    <!--- This is where your question gets answered --->   
    <!--- All the information about each uploaded file is stored in the cffile structure. ColdFusion creates one cffile struct for each and every file you upload in a single upload round --->
    <!--- Save the information about each file to the database. The back slash \ often serves the purpose of an escape character. So I've replaced it with the forward slash / in the file path. --->
    <cfquery name="saveUploadInfo" datasource="myDSN">
        insert into uploadedfile (datetimecreated, serverdirectory, serverfile)
        values (#cffile.timecreated#, '#replace(cffile.serverdirectory,"\","/","all")#', '#cffile.serverfile#')
    </cfquery>
    <!--- You could in fact log (and review) all the upload data by means of the following --->
    <!--- <cflog file="uploadData" text="#serializeJson(cffile)#"> --->

  • How to view and access files on my iBook G3 from another iMac

    **Hello, everybody on this excelent forum. I need to know how to use my Firewire conection, to view and access files in my iBook G3, from another iMac G3, both are OK in working good condition. I put this question because some days ago a Mac expert fix to me the access in my recent SwapMeet second hand aqcired iMac G3, without the original last owner password.
    this person are egoistic, and DoNot show me how he use the Firewire do this job.
    Thank You: Eduardo from NorthWest Mexico.

    Hello, Niel, Thank You very Much for your fast and kindly responce.
    the next monday I'll buy a new FireWire cable to test the metod you tell me.
    Again thanks and best regards from NW-Mexico.
    Eduardo

  • How does idx and sub files work?

    How can I get idx and sub files to work on quicktime and apple tv? I have a mp4 movie with those subtitle files and wonder how they work.
    Message was edited by: elangsru

    Go to ine.com and sign up for a free membership. They offer free streaming of the CCNA R/S and CCNA Voice videos. You can also use Google to find many resources to read on.

  • How to open and close files from UIwindow my function doesn't work

    Hello guys!
    I am trying to create a simple ui-interface.
    I made one button so far.
    but my function does not work.
    if I run the function without dialog box it works perfectly!
    when I running the function in the dialog window, picking a file and open, nothing happens why?
    please help me with a correct code.
    also how do I write  2 functions that also closing a file and  saving a file?
    here is my simple code.
    var w = new Window ("dialog");
    button.onClick = function () {
    OpenMyFile();
    w.show ();
    function OpenMyFile(){
    var myFile = File.openDialog();
    app.open(myFile)
    Thank you in advance.

    Well, to answer your first question, you've added an event listener, but you haven't actually added the button itself.
    try this:
    var w = new Window ("dialog");
    b = w.add("button", undefined, "Click me!");
    b.onClick = function () {
    OpenMyFile();
    w.show ();
    function OpenMyFile(){
    var myFile = File.openDialog();
    app.open(myFile)

  • How to Open and Save files

    I have a problem to open and save the files.here is my code. can anyone help me to open the files.
    public void actionPerformed(ActionEvent e) {
    if ("open".equals(e.getActionCommand())) {
    FileDialog fdopen=new FileDialog(this, "Load File", FileDialog.LOAD);
    fdopen.show();
    Thanks for ur time

    Hi fbnmir or who ever can answer my question,
    My problem is similar to the code you wrote. I'm trying to make (or rather complete a half done) editor for text files. For opening and saving files I have so far:
    public void actionPerformed(ActionEvent ae){
    FileDialog filedialog;
    final SearchDialog searchDialog;
    String arg = (String)ae.getActionCommand();
    // the Open ... case
    if(arg.equals(Editor.fileLabels[0])){ 
    if(Editor.VERBOSE)
    System.err.println(Editor.fileLabels[0] +
                        " has been selected");
    filedialog = new FileDialog(editor, "Open File Dialog", FileDialog.LOAD);
    filedialog.show();
    if(Editor.VERBOSE){  
    System.err.println("Exited filedialog.setVisible(true);");
    System.err.println("Open file = " + filedialog.getFile());
    System.err.println("Open directory = " + filedialog.getDirectory());
    //the Save ... case
    if(arg.equals(Editor.fileLabels[1])){ 
    if(Editor.VERBOSE)
    System.err.println(Editor.fileLabels[1] + " has been selected");
    filedialog = new FileDialog(editor, "Save File Dialog", FileDialog.SAVE);
    filedialog.show();
    if(Editor.VERBOSE){ 
    System.err.println("Exited filedialog.setVisible(true);");
    System.err.println("Save file = " + filedialog.getFile());
    System.err.println("Save directory = " + filedialog.getDirectory());
    These are two components of a MenuHandler class. The problem with this code is that in the text editor window, even if the Open button is pressed the file I want to open isn't displayed. Although the System.err (I think that's what it is called) says:
    Open ... has been selected
    Exited filedialog.setVisible(true);
    Open file = tutorial_01.rtf
    Open directory = C:\dhruba\epgy_2006\tutorial\
    Save ... has been selected
    Exited filedialog.setVisible(true);
    Save file = test.txt
    Save directory = C:\dhruba\epgy_2006\tutorial\
    How can I actually display the file I want to open, or save some text I've written?
    I would appreciate any help, thanks.

  • How to drag and drop files between two JFileChooser

    Sir i want to drag and drop files between two JFileChooser i don't know how to do that. So is there any reference code for that so that i can able to do it. I have enabled setDragEnabled(true) for both the jfilechooser now i don't now how to drop files in them means drag file from one jfilechooser and drop it to another JFileChooser,.
    Plz help me this is the requirement in my project.

    Note: This thread was originally posted in the [New To Java|http://forums.sun.com/forum.jspa?forumID=54] forum, but moved to this forum for closer topic alignment.

  • Help with how to read and write files to the applets server

    I am writing a form that requires some data to be written serverside(not on the host machine) and I also need to be able to read from those same files.
    Can anyone provide any help?
    I looked into signing but it seems, to me, that signing is for when you are going to be modifying files on the host...

    brianb7590 wrote:
    Would I use that to refer to the file like I would with a regular application?Nope. It's pretty complicated. You've got to set something up on the server to accept requests, get all the data and then save files somewhere and on the client side you've got to make the connection and send the data.
    Edited by: tjacobs01 on Apr 13, 2009 5:49 PM

  • How to zip and unzip files in Mac OS X

    Hi There,
    I want to know how can I unzip and zip my files and folder in mac. Also is there any software that can unzip .rar files in mac. Any help will be appreciated.
    Thanks in advance.

    how can I unzip and zip my files and folder in mac
    To make a zip file, select your file in the finder and then File > Create Archive.
    If you start Mac Help, and type "zip" into the search field, you'll find out more.

Maybe you are looking for

  • Log on to SAP via HTTP ( WebSAPConsole)

    Hii all,          I have created one application which is on R/3 side . I have assigned t-code of this application to sapconsole administrator in control panel. then i have create virtual directory name ( mysap , it could be any name ) . Now when i w

  • White macbook: upper case cracked at edges. Is replacement possible?

    My Macbook has cracked casing edges at the front and sides. There is also some cracking at the top edges of the screen that I'm less worried about as it is not leaving anything exposed. It's well out of warranty with no Applecare, but I read on a US

  • Help and support error message

    when I try and use the help and support icon on my HP pavillion windows vista computer, I get the following error message:Microsoft script host Script: C:\Windows\Help\OEM\scripts\openOEMACW.jse line: 2 Char:1 error: Automation server can't Create Ob

  • Picking up a file as soon as it is kept in the folder on the server

    Hi Guys, Is there a way that I can pick up a file as soon as it is placed in a folder.. I do not want to schedule a background program to keep on checking for files

  • Music Player S^3 artist&album

    I recently got a C6-01 and am very happy with the phone overall. There are a few questions I have about the way the music player deals with the library though. 1) Why do songs get categorised in the (Unknown/Unknown) category when the artist is known