NSLog crashes with certain NSURL- iOS 9.2

前端 未结 2 1561
北恋
北恋 2021-01-14 11:16

Here is my code,where the crash occurs:-

let URL = NSURL(string: \"http://files.parsetfss.com/fa80bc63-88d4-412d-a478-2451cffc92a9/tfss-1d2a321d-b02e-4745-a5         


        
2条回答
  •  抹茶落季
    2021-01-14 12:15

    The first argument of NSLog() is a format string, and contains format specifiers (starting with %) which are expanded by the following variable argument list. In your case %20C is a format specifier, but no matching argument is supplied. That causes undefined behavior, it can crash or produce incomplete or wrong output.

    If you want to use NSLog() then a general safe method is

    NSLog("%@", "Loading page with URL: \(URL)")
    

    In this particular case,

    NSLog("Loading page with URL: %@", URL)
    

    works as well, since NSURL is a NSObject subclass and can be used with the %@ format.

提交回复
热议问题