Syntax Error

Discussion in 'Mac Programming' started by Binju, Mar 31, 2010.

  1. Binju macrumors member

    Joined:
    Jan 31, 2010
    #1
    Can you find the syntax error?

    Code:
    [["%@" writeToFile:@"/NSLog.txt" atomically:YES encoding:[NSUTF8StringEncoding error:nil]],movieFile] ;
     
  2. kresh macrumors 6502a

    kresh

    #2
    atomically -> automatically ?

    Just guessing, I can't code :)
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    More a massive conceptual error. You are assuming that, somehow, possibly by magic, the compiler will let you use the return of
    Code:
    ["%@" writeToFile:@"/NSLog.txt" atomically:YES encoding:[NSUTF8StringEncoding error:nil]]
    as an object that you can call a method on without giving the method name. What you do pass it is ",movieFile" which is not a valid method call.

    I think what you are trying to do is us
    Code:
    "%@"
    
    as a format string and have movieFile be the argument to that format. But your code is nothing even close to that: look at the stringWithFormat: method in NSString and use it.
     
  4. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
    #4
    Code:
    [[NSString stringWithFormat:@"%@", movieFile] writeToFile:@"/NSLog.txt" atomically:YES encoding:[NSUTF8StringEncoding error:nil]];
    
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    You still have a meaningless set of square brackets around the result that the compiler will try and turn into a method call and fail.

    I suggest you take two steps back and read up on the basics of Objective-C before trying to write any code as it's clearly you fundamentally don't understand what you are doing.
     
  6. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
    #6
    Code:
    NSString *urlString = [movieURL absoluteString];
    	[urlString writeToFile: @"/myfile.txt" atomically: YES encoding:NSUTF8StringEncoding error:nil];
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    What is your question?

    We can't read your mind.

    If you want to know "Does it compile?", then you should compile it and see.

    If you have another problem, then you must describe the problem.
     
  8. Binju thread starter macrumors member

    Joined:
    Jan 31, 2010
    #8
    Code:
    NSString *urlString = [movieURL absoluteString];
    	[urlString writeToFile: @"/myfile.txt" atomically: YES encoding:NSUTF8StringEncoding error:nil];
    This works
     

Share This Page