Print logs in debug state in Swift

Source: Internet
Author: User
Tags log log

First of all, we should know that the entrance to Swift's program is in Appdelegate.swift. So in the print log in Appdelegate.swift this is the case

Import Uikit@uiapplicationmainclassAppdelegate:uiresponder, uiapplicationdelegate {var window:uiwindow?func Application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject:anyobject]< /c3>?) -Bool {dllog ("Hello")                return true    }}//write the log to be printed in the same rank with appdelegate method, that is, do not belong to the Appdelegate class, so that in the project to use this print log, because this is the program's entrance,//the t here means that the message parameter type is not specifiedFunc dllog<t> (message:t, filename:string = __file__, funcname:string = __function__, Linenum:int =__line__) {        #ifDEBUG/** * Here also search for swift flags in the project build settings, find other Swift flags find Debug * Add-D debug, can. */         //1. Processing the fileLet file = (fileName asnsstring). Lastpathcomponent//2. Print ContentPrint ("[\ (file)][\ (funcName)] (\ (linenum)) \ (message)")            #endif    }

The type of printing is:[Appdelegate.swift][application (_:didfinishlaunchingwithoptions:)] (+) Hello

The contents of the file method name line number, respectively

Secondly, one thing that should be dealt with is that (in fact, it is explained in the code)

This completes the log log in the full debug state.

Print logs in debug state in Swift

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.