Useful tips when programming in Objective-C
dateAugust 27 2013 | comments 0 comments
Use Custom Fonts
In order to have a very unique and well designed UI in your app, you need to have something different than any other app. 
This may be in terms of images, colors, contents, fonts, text styles, way of presentation. 
So if you want to use a different font, other than the ones available for iOS (, here is a tip on how to add your own custom font to use it in any iOS app:
Create a new project or inside your existing project:
1. Add your Font File inside your project 
The font should have the following format:
OpenType Format (OTF)
TrueType Format (TTF)

2. Inside your Info.plist add a new row (right click) with "Fonts provided by application" (it will be an Array) 
Inside this array add a new item (Item 0) that has as value your Font File name. Do not forget to add the file extension also.
If you have more files with custom font you have to add more items inside the array.
Save your Info.plist.

3. Now you can use your Custom font UIFont *customFont = [UIFont fontWithName:@"CustomFontName" size:18]; 
Ignore NSLog when you debug
When you develop iOS application, the trusty NSLog macro is used by many to print out debug information.
If you read the NSLog documentation you'll find this description:" NSLog: Logs an error message to the Apple System Log facility."
This means that NSLog Logs an error to the Apple System Log facility. Not a debug message, an error.
Debug messages like this should never appear in a release build, at least by default. 
They clutter up the device log with unimportant developer left-overs, and can compromise your app security by revealing sensitive information about an app or user.
If we read a little further in the documentation, Apple gives us their logging best-practices:
Adopt Best Practices for Logging
Treat your log messages as a potentially customer-facing portion of your application, not as purely an internal debugging tool. Follow good logging practices to make your logs as useful as possible:
a. Provide the right amount of information; no more, no less. Avoid creating clutter.
b. Avoid logging messages that the user can't do anything about.
c. Use hashtags and log levels to make your log messages easier to search and filter.
In order for the log files to be useful (to developers and users), they must contain the right level of detail. If applications log too much, the log files quickly fill up with uninteresting and meaningless messages, overwhelming any useful content. If they log too little, the logs lack the details needed to identify and diagnose issues."
Here is one quick and "dirty" way to improve things:
In your "Prefix.pch" write the fallowing:
 #ifdef NDEBUG
  #define NSLog(...) NSLog(__VA_ARGS__)
  #define NSLog(...)
NDEBUG is a standard macro that means "no debug" or "release mode". This will usually be defined in the Release configuration of your target's build settings.
You can also choose to "disable" the NSLog when you want to debug the application on a device:
    #define NSLog(...)
More about NSLog and how to implement some new logging macros in my next articles.

dateAugust 27 2013 | comments 0 comments

Useful tips when programming in Objective-C
Blog post currently doesn't have any comments.
Leave comment

 Security code