{"id":4770,"date":"2014-03-30T15:17:22","date_gmt":"2014-03-30T15:17:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/convert-nsstring-into-nsmutablearray-collection-of-common-programming-errors\/"},"modified":"2014-03-30T15:17:22","modified_gmt":"2014-03-30T15:17:22","slug":"convert-nsstring-into-nsmutablearray-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/convert-nsstring-into-nsmutablearray-collection-of-common-programming-errors\/","title":{"rendered":"Convert NSString into NSMutableArray-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to convert (or copy?) a NSString into a NSMutableArray. I guess my problem is that I don&#8217;t really understand the structure of a MutableArray. In my limited knowledge, an Array could look like this:<\/p>\n<pre><code>NoteBook = [[NSMutableArray alloc] init];\n\nfor (int temp = 0; temp &lt; 3; temp++) {\n    [NoteBook insertObject:@\"Page\" atIndex:temp];\n}\n<\/code><\/pre>\n<p>Which would give me an Array of <strong>PagePagePage<\/strong>. Let&#8217;s assume I wanted to open a txt file which contains PagePagePage, but the words were separated by a defined string so that I can keep the individual objects in my array apart, like so: <strong>Page&#8212; end of page &#8212;Page&#8212; end of page &#8212;Page<\/strong>.<\/p>\n<p>Now, my next step would be to read this information from the txt file:<\/p>\n<pre><code>NSString *tempTextOut = [NSString stringWithContentsOfFile:filePath\n                                                 encoding:NSUTF8StringEncoding\n                                                    error:&amp;error];\nNoteBook = [tempTextOut componentsSeparatedByString: @\"\\n--- end of page ---\\n\"];\n<\/code><\/pre>\n<p>However, the last line does not work and I&#8217;m told by xCode: Incompatible Objective-C types assigning &#8216;struct NSArray*&#8217;, expected &#8216;struct NSMutableArray*&#8217;. I don&#8217;t really understand this &#8211; NSArray and MutableArray should be compatible (as one is the subclass of the other). Shouldn&#8217;t xCode tell me that the problem is that I&#8217;ve been trying to convert a NSString into an NSMutableArray?<\/p>\n<p>Would I perhaps need to re-set my MutableArray before putting something back into it, because right now, it still contains <strong>PagePagePage<\/strong> which I have assigned to it in the first step. I thought my NoteBook mutable array would simply be replaced by the string, but I guess that won&#8217;t be the case.<\/p>\n<p>I&#8217;d very much appreciate any help in this matter. Thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am trying to convert (or copy?) a NSString into a NSMutableArray. I guess my problem is that I don&#8217;t really understand the structure of a MutableArray. In my limited knowledge, an Array could look like this: NoteBook = [[NSMutableArray alloc] init]; for (int temp = 0; temp &lt; 3; temp++) { [NoteBook insertObject:@&#8221;Page&#8221; atIndex:temp]; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4770","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4770"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4770\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}