Marimuthu
Marimuthu

Reputation: 447

iOS App: Enabling logging with minimal changes to the code

I have an code for an iOS application. How would I enable logging in some of the UI methods like say ViewDidLoad ViewWillAppear etc with minimal changes to the code base?

I was asked this question in an iOS interview.

I told him that I would include the Google Analytics framework to capture the info. He did not the answer in terms of which framework we used.

But rather the approach that we would follow to enable/capture logging information with minimal code change.

Was wondering if there is any inbuilt mechanism to log required info (say capture NSLog into a log file) which could be turned-on by setting/enabling some flag in project settings?

Upvotes: 0

Views: 79

Answers (1)

Jelly
Jelly

Reputation: 4522

This is a basic example of AOP. Logging is a so called cross-cutting concern, you can dig more into it by searching on the internet. In iOS this programming paradigm is usually implemented using method swizzling, again there are some great resources out there about it. A nice library that makes method swizzling easier is aspects. Basically if you use this you don't have to change anything (just add stuff) to add logging to an application.

Upvotes: 2

Related Questions