How to print something to the console in Xcode?

后端 未结 6 1044
逝去的感伤
逝去的感伤 2021-02-06 20:45

How do you print something to the console of Xcode, and is it possible to view the Xcode console from the app itself?

Thanks!

6条回答
  •  清酒与你
    2021-02-06 21:00

    How to print:

    NSLog(@"Something To Print");
    

    Or

    NSString * someString = @"Something To Print";
    NSLog(@"%@", someString);
    

    For other types of variables, use:

    NSLog(@"%@", someObject);
    NSLog(@"%i", someInt);
    NSLog(@"%f", someFloat);
    /// etc...
    

    Can you show it in phone?

    Not by default, but you could set up a display to show you.

    Update for Swift

    print("Print this string")
    print("Print this \(variable)")
    print("Print this ", variable)
    print(variable)
    

提交回复
热议问题