cocoa - Saving preferences of document when it is a txt file -


i wonder how can save preferences of document such window size, position in screen, etc when document simple txt file. (my app text editor)

i thought of nsuserdefaults , save file path happen if file moved later when app closed? using nsuserdefaults idea? looking advice

thanks

edit: added these 2 methods mydocument.m (thanks @somegeekintn @black frog)

//helper method set nswindow frame string in file system attributes - (bool) _savepreferencesinfileaturl:(nsurl *)absoluteurl{      const char *path = [[absoluteurl path] filesystemrepresentation];     const char *name = [@"nswindow frame" cstringusingencoding:nsutf8stringencoding];     const char *framecstring = [nsstringfromrect([window frame]) cstringusingencoding:nsutf8stringencoding];      int result = setxattr(path , name, framecstring, strlen(framecstring) + 1, 0, 0);     return (result<0)? no: yes; }  //helper method reads nswindow frame string file system attributes - (bool) _readpreferencesinfileaturl:(nsurl *)absoluteurl{      const char *path = [[absoluteurl path] filesystemrepresentation];     const char *name = [@"nswindow frame" cstringusingencoding:nsutf8stringencoding];     char framecstring [50];      ssize_t bytesretrieved = getxattr(path, name, framecstring, 50, 0, 0);      //use framecstring...      return (bytesretrieved<0)? no: yes;  } 

you may want take @ setxattr , getxattr write , read file's extended attributes respectively. can put pretty whatever in these attributes.

int setxattr(const char *path, const char *name, void *value, size_t size, u_int32_t position, int options); ssize_t getxattr(const char *path, const char *name, void *value, size_t size, u_int32_t position, int options); 

setxattr man page


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -