Search code examples
htmliossharepointcore-textrich-text-editor

How to sync NSAttributed string to MS Sharepoint server


I have requirement where user edits notes for Rich text editing features. Then user syncs these notes to sharepoint. My question is, does sharepoint column type support storing an attributed string OR I would have to convert NSAttributed strings to HTML tags ? Does sharepoint support storing unicode character attributed strings OR HTML pages as column type


Solution

  • Convert the NSAttributedString to NSData using NSKeyedArchiver and upload:

    NSString *theString = @"Example";
    NSDictionary *theAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
                                   [NSFont fontWithName:@"Helvetica" size:26], NSFontAttributeName,
                                   [NSColor whiteColor], NSForegroundColorAttributeName, nil];
    NSAttributedString *theAttributedString = [[NSAttributedString alloc] 
                                               initWithString:theString
                                               attributes: theAttributes];
    NSData *theData = [NSKeyedArchiver archivedDataWithRootObject:theAttributedString];
    

    Download the data from the server and convert it back to the NSAttributedString using:

    NSAttributedString *theAttributedString = [NSKeyedUnarchiver unarchiveObjectWithData:theData];
    

    Generally I upload NSAttributedStrings in two formats:

    • The archived NSAttributedString to make sure I can later retrieve exactly the same object.
    • The plain version of the NSAttributedString to allow search and display server side.