开发者

How to store recorded file in array?

Here is the code that i save audio file in string. After that i add in array. But still not work here.. Is there any options here to store audio file in array after that storing documentdictionary.

    fileArray = [[NSMutableArray alloc] initWithContentsOfURL:recordedTmpFile];

    fileArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [fileArray objectAtIndex:0];

    NSMutableDictionary *recordDictionary = [NSDictionary dictionaryWithContentsOfFile:documentsDirectory];
    NSFileManager *fileManager = [NSFileMan开发者_JS百科ager defaultManager];
    for(int i= 0; i<fileArray.count;i++)
    {
        NSString *recorded = [fileArray objectAtIndex:i];
        NSString *filePath = [recordDictionary stringByAppendingPathComponent:recorded];
        newArray = [fileManager fileExistsAtPath:filePath];
    }   

If any code missing by me than suggest me some specific idea about. Plz give some response..


I don't want to sound like a dick, but just throwing code at an editor isn't going to work. I don't often write answers like this, but sometimes it needs to be done;

Here's a line-by-line breakdown of what you have written and maybe that will give you an idea of what this snippet is doing:

  1. You create an NSMutableArray called fileArray initialised with the contents of a file. I don't know whether this file is in the correct format or not. documentation
  2. You then overwrite this array with an array of search paths. Incidentally, you've now leaked the memory of the initial array.
  3. You get a string to the Documents directory.
  4. You try to create an NSDictionary from a string rather than in the specific format required by the message. As this is an invalid file recordDictionary is nil documentation
  5. You create a reference to the FileManager
  6. You start a for loop to iterate the contents of fileArray
  7. You get each item in fileArray but this is only a list of directories, not files (see point 2)
  8. You try and create a filePath by appending what you think of as a file to a directory except you are appending a directory (see point 7) to nil (see point 4)
  9. You declare an undimensioned variable and try to assign a BOOL to it documentation

So you've written a lot of code that doesn't do anything. It doesn't work because I doubt you have tried to compile it.

Looking at your question history it seems you ask the same question over and over again. You would be better off starting with a basic introduction to Cocoa and working through that until you understand why your code snippet is so wrong.

All you need to do is to get the location of the file you want to save, and move it to the correct place. Somebody else may just write your code for you, but I won't - I'm not that desperate for the points and I'll just be doing you a disservice. Go back to basics, ask specific questions with some idea of what you've tried and you'll get a far better response

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜