For Swift >=2.2:
You can try to do:
print("\(NSDate()) \(#file) \(#line) \(#function) in \(self.dynamicType)")
You can use a global method like this:
func VerboseLog<T>(object: T, filename: String = #file, line: Int = #line, funcname: String = #function) {
print("\(NSDate()) \(filename) \(line) \(funcname) in \(object.dynamicType)")
}
More information:
#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.
Apple official source.
About aspect oriented programming as you ask, unfortunately Swift dont has now a runtime support. You must refer to obj-c bridging.
There is an interesting library called MOAspect that can be useful if you want to use this kind of approach:
MOAspects.hookClassMethodForClass(UIScreen.self, selector:"mainScreen", position:.Before) {
NSLog("hooked screen!")
}
UIScreen.mainScreen() // -> hooked screen!