Thursday, 15 July 2010

objective c - NSTextStorage paragraph numbering -



objective c - NSTextStorage paragraph numbering -

is possible paragraph number nstextstorage? has property called paragraphs nsarray, it's not clear how deal individual objects in array.

i looking way number each paragraph in storage, find out in 1 changes made.

i thinking mark paragraphs ranges problem if add together or delete characters in 1 paragraph, ranges of next paragraphs became invalid (they change).

ideally great if find solution paragraph number via range, wouldn't necessary iterate each paragraph. here's code getting range of edited paragraph:

let paragraphrange = textstorage.string.bridgetoobjectivec().paragraphrangeforrange(editedrange)

but how can utilize find out exact number of paragraph in array? can't compare strings because user can type 2 or more identical strings.

update: thought came using whole bunch of nstextviews, each single paragraph. have no thought how else track changes in particular paragraph. thing concerns me if document have, let's say, 1000 pages or more, can hope such construction of nstextview series won't slow downwards runtime?

so far, best thought came this:

var attributes = [nsfontattributename: defaultfont] nsmutabledictionary attributes.setobject(nsuuid().uuidstring, forkey: "identifier") textview.typingattributes = attributes

that is, add together new key in attributes dictionary, name "identifier" , assign unique string. each paragraph have unique identifier.

when user edits text, can grab running attributes of text storage , iterate through array of paragraphs matching "identifier" key.

objective-c cocoa swift nstextstorage

No comments:

Post a Comment