Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

swift - print() to console log with color

The code is:

let redColor = "u{001B}[0;31m"
var message = "Some Message"
print(redColor + message)  //This doesn't work
print("(redColor)(message)") //This also doesn't work

and the output would look like this:

[0;31mSome Message

I've also read this post: Color ouput with Swift command line tool, and it doesn't seem to work.

I don't want to use libraries.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Xcode doesn't support console coloring since Xcode 8.

But Since Xcode is fully unicode compatible, you can use emojis instead! for example you can use You can use ?? for warning messages and ?? for error messages. (like the Xcode itself)

Or simply use these note books as a color:

??: error message
??: warning message
??: ok status message
??: action message
??: canceled status message
??: Or anything you like and want to recognize immediately by color

for example:

print("??", "Touch is not disabled as expected")

?? Bounes

Using this method will help you to find the logs in the source code as fast as ?? by a simple eye scan:

Demo

And you can search for them "????" to let the Xcode take you there. Take a look at this result comparison:

Custom emoji search

emoji search

vs

Word search

word search


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...