Brian F Love
Learn from a Google Developer Expert focused on Angular, Web Technologies, and Node.js from Portland, OR.
Ad ·ultimatecourses.com
Learn Angular the right way with Ultimate Courses

新行存储在核心Dat NSString属性a

I recently ran into an interesting issue that I thought I would write about.I have an entity in Core Data that stores an explanation. The explanation attribute is a string type, and I am using this value to display the text within aUITextView. I have newline characters (n) in my data.

I was expecting the newlines to then be shown in the resultingUITextViewwhen I set the text property to the value stored in my database. The problem is that the newlines were being displayed in theUITextView:

Newlines in UITextView

The simple solution is to replace instances of "n" with an actual newline character. It's a one-liner:

[explanation stringByReplacingOccurrencesOfString:@"\n"withString:@"n"];

Here we simply call thestringByReplacingOccurrencesOfString:withString:method on the string that we retrieved from core data.

Brian F Love

Hi, I'm Brian. I am interested in TypeScript, Angular and Node.js. I'm married to my best friend Bonnie, I live in Portland and I ski (a lot).