I am working on a cocoa-based text editor. Should I base it on NSTextView or is there a more efficient option? Keep in mind that I plan to support tabs so there can be many editors open at the same time.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes.
No, assuming “efficiency” includes your own time and effort weighed against the feature set you want to support—Cocoa’s text system does a lot for you, which you’d be throwing away if you rolled your own.
Some examples:
If you roll your own, you get to spend months reinventing and debugging some if not most if not all of those wheels. I call that inefficient.
The text system you already have, meanwhile, is fast nearly all of the time. You need huge texts with long lines (or maybe lots of embedded images/sounds) to bog it down.
Unless the user is going to be typing into all of them at once, I don’t see how that will cause a performance problem. 0% CPU × N or N-1 views = 0% CPU.
The one place where you might have a problem is memory usage, if the documents are both many and large. They’d have to be both in the extreme, as even a modest Mac nowadays has 1 GiB of RAM, and text doesn’t weigh much.
If that’s the case, then you could only keep the N most recently used unmodified texts in memory, and otherwise remember only the arrays of selection ranges. But 99% of the time, swapping texts in and out will be far more expensive than just leaving them all in memory.