Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If all you have is 4 objects, don't bother looping you can simply -</p> <p>If you have a sub class of Customers you can use:</p> <pre><code> newCustomer.contactName = [importArray objectAtIndex:0];//change it to the correct index, and correct property name newCustomer.phone = [importArray objectAtIndex:1]; //....And so on </code></pre> <p>else you will need to use</p> <pre><code> [newCustomer objectForKey:@"contactName"] = [importArray objectAtIndex:0]; </code></pre> <p><strong>BUT</strong></p> <p>If you have many properties in your CSV you can set an other array of the keys in your entity and -</p> <pre><code> for(NSUInteger i=0;i&lt;[importArray count];i++){ [newCustomer objectForKey:[keysArry objectAtIndex:i]] = [importArray objectAtIndex:i]; } </code></pre> <p><strong>Better sometimes</strong></p> <p>A better way to handle this, ecpaciely if you have many properties is to use -</p> <pre><code> //1. crate a dictionary from your CSV with keys that are similar to your entity property names. NSDictionary *csvDictinary = []//set your dictionary. //2.get all the property names from your customers entity NSDictionary *attributes = [[NSEntityDescription entityForName:@"Costumer" inManagedObjectContext:self] attributesByName]; //3. set the properties to your entity for (NSString *attr in attributes) { [Costumer setValue:[csvDictinary valueForKey:attr] forKey:attr]; } </code></pre> <p><strong>EDIT</strong> To sub class your entity:</p> <ol> <li>select the entity in the model editor.</li> <li>in Xcode menu select Editor -> Create NSManagedObject Subclass.</li> <li>import or @class your new subclass when you want to refer it.</li> </ol> <p><strong>BTW</strong></p> <ol> <li>Subclass your entities - it will make your life easier and will cause better performance.</li> <li>Your entity name should be -"Customer" in singular, as it hold only 1 customer.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload