简体   繁体   English

尝试在标签上打印日志文件(swift4)

[英]trying to print log file on label (swift4)

My code below is calling coreData to print on a label. 我在下面的代码调用coreData在标签上打印。 If I print on a label it only takes the last entry of coreData unlike what is printed on the log file. 如果我在标签上打印,则与日志文件上打印的内容不同,它仅占用coreData的最后一个条目。

for i in user! {

        print( "color: \(i.username!) Score: \(i.password!)")
        displayL.text = ( "color: \(i.username!) Score: \(i.password!)")
    }

LOG FILE 日志文件

在此处输入图片说明

VIEWCONTROLLER 视图控制器 在此处输入图片说明

Try this: 尝试这个:

for i in user! {
    print( "color: \(i.username!) Score: \(i.password!)")
    displayL.text = "\(displayL.text ?? "")\ncolor: \(i.username!) Score: \(i.password!)")
}

As you can see I'm concatenating the string instead of overriding it in every iteration 如您所见,我正在串联字符串,而不是在每次迭代中都覆盖

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM