我尝试从 html 响应创建一个属性字符串以将其显示在标签上。但是,当我创建字符串时,我遇到了一些问题。转换从字符串中删除换行符。
let text = "test test test\n\nline 2 test test test\n\nline 3 test test test test test test test test test test test test test test test test test testtest test test test test testtest test test test test testtest test test test test testtest test test test test test"
let attributedString = NSMutableAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue], documentAttributes: nil)
attributedString.addAttribute(.font, value: UIFont.body, range: NSMakeRange(0, attributedString.length))
attributedString.addAttribute(.foregroundColor, value: UIColor.charcoal, range: NSMakeRange(0, attributedString.length))
Run Code Online (Sandbox Code Playgroud)
我想将此属性字符串分配给标签。但它不会显示带有换行符的文本。请帮我解决这个问题
我是iOS的初学者.当我将Core Data用于我的示例项目时,它给了我一个线程错误.
请帮我解决这个错误.
这是我的代码:
-(NSFetchedResultsController*)fetchedResultController{
if (self.fetchedResultController != nil ) {
return self.fetchedResultController;
}
NSFetchRequest *request = [[NSFetchRequest alloc]init];
NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"Recepie" inManagedObjectContext:context];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]initWithKey:@"recepieName" ascending:YES];
NSArray *sortDescriptorArray = [[NSArray alloc]initWithObjects:sortDescriptor,nil];
request.sortDescriptors = sortDescriptorArray;
self.fetchedResultController = [[NSFetchedResultsController alloc] initWithFetchRequest: request managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
self.fetchedResultController.delegate = self;
return self.fetchedResultController;
}
Run Code Online (Sandbox Code Playgroud)