Objective C - Create text file to read and write line by line in Cocoa -


i building mac app,i have 2 problem:

  1. i want create text file read , write data on it. don't know how crate text file read , write data. use struct?
  2. i want create xml file read , write data on it. can create struct xml?

do have suggestion? in advance

well, create file, use

[[nsfilemanager defaultmanager] createfileatpath:@"your/path" contents:nil attributes:nil]; 

this creates empty file, can write or read from. write text (or xml), use nsstring's writetofile:atomically:encoding:error: method

nsstring *str = //your text or xml [str writetofile:"your/path" atomically:yes encoding:nsutf8stringencoding error:nil]; 

to read file, make nsstring contents of file

nsstring *contents = [nsstring stringwithcontentsoffile:@"your/path"]; 

or, if not contain string, nsdata object file

nsdata *contents = [nsdata datawithcontentsoffile:@"your/path"]; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -