Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

ios - Logging Method signature using swift

I am trying to rewrite my logging class and I would like to know how to substitute PRETTY_FUNCTION or NSStringFromSelector(_cmd) in a swift file in order to track the method calls?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Special literals in swift are as follows (from [the swift guide]

#file String The name of the file in which it appears.

#line Int The line number on which it appears.

#column Int The column number in which it begins.

#function String The name of the declaration in which it appears.


Prior to Swift 2.2b4, these were

(https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html)):

__FILE__ String The name of the file in which it appears.

__LINE__ Int The line number on which it appears.

__COLUMN__ Int The column number in which it begins.

__FUNCTION__ String The name of the declaration in which it appears.

You can use these in logging statements like so:

println("error occurred on line (__LINE__) in function (__FUNCTION__)")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...