我正在为var UserSchema = new Schema({
name: String,
username: {
type: String,
required: [true, "Please enter a username"],
minlength: [6, "Username must be at least 6 characters"],
maxlength: [15, "Username cannot exceed 15 characters"],
unique: true
},
password: {
type: String,
required: [true, "Please enter a password"],
minlength: [6, "Password must be at least 6 characters"],
maxlength: [17, "Password cannot exceed 17 characters"],
},
roommates: [
{
roommates: {type: Schema.Types.ObjectId, ref: "User"},
status: {type: String, default: "pending"},
requests: [
{type: Schema.Types.ObjectId, ref: "Request"}
],
balance: {type: Number, default: 0}
}
]
})
分配值。如果我从UILabel
获得的价值比\ n显示的那样,并且不会将其作为新行读取。
这是我的代码
NSManagedObject
我希望UiLabel读取\ n作为新行
但是下面的代码给出了预期的输出
let cards:Card = cardArray[0] as! Card
lblTitle?.text = cards.title
//Output in UiLabel is "This is \n title"
答案 0 :(得分:1)
我认为您title
包含转义字符,即\n
在\\n
替换\n
时打印的原因。
Swift 3
lblTitle?.text = cards.title.replacingOccurrences(of: "\\n", with: "\n")
Swifr 2.3或更低
lblTitle?.text = cards.title.stringByReplacingOccurrencesOfString("\\n", withString: "\n")