o9s
is a microblog
home archives search feed blogroll


My Common iOS file

I use a Common.h file in all of my iOS projects. I am not going to explain what these functions do, they are mostly obvious.

#ifndef Confee_Common_h
#define Confee_Common_h

#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
#define SCREEN_WIDTH_IN_PIXELS ([[UIScreen mainScreen] bounds].size.width * [[UIScreen mainScreen] scale])
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
#define LS(str) NSLocalizedString(str, nil)
#define IS_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad

#endif

LS(str) is a fun shortcut. I was tired of always typing out the very verbose NSLocalizedString(str, nil). It helps shortening the code.

I add Common.h to my prefix.pch file so it’s included in all my classes. I also have UIKit and Foundation in this file.

[...]

#ifdef __OBJC__
  #import "Common.h"
  #import <UIKit/UIKit.h>
  #import <Foundation/Foundation.h>
#endif
Posted on 2018-03-18   #ios  






← Next post    ·    Previous post →