スポンサーリンク

【Obj-C】prefix.pch コピーペーストで使えるサンプル

prefix.pch サンプル

コーディング時に大枠を何処かからコピーペーストして修正実装

するパターンがよくあると思います。

実装時、コピペ用のテンプレートとしてご利用ください。

コードサンプル

//--------------------------------------------------------------------------------------------------------------------
// テストはログを出力、リリースは出力しない
#if !defined(NS_BLOCK_ASSERTIONS)
    #if !defined(NSLog)
        #define NSLog( m, args... ) NSLog( m, ##args )
    #endif
    # define LOG_METHOD NSLog(@"%s", __func__)
#else
    #if !defined(NSLog)
        #define NSLog( m, args... )
    #endif
    # define LOG_METHOD ;
#endif

//--------------------------------------------------------------------------------------------------------------------
// バージョンチェック
#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#endif


//--------------------------------------------------------------------------------------------------------------------
// 共通ヘッダー
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "GAI.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
#import "AppDelegate.h"
#endif

//--------------------------------------------------------------------------------------------------------------------
// ARC NON-ARC 対応
// iOS 5 or above
#if __has_feature(objc_arc_weak)
#define __my_block_weak        __weak
#define __my_block_weak_unsafe __weak
// iOS 4.X
#elif __has_feature(objc_arc)
#define __my_block_weak        __strong
#define __my_block_weak_unsafe __unsafe_unretained
// iOS 3.X or non-ARC projects
#else
#define __my_block_weak        __strong
#define __my_block_weak_unsafe __block
#endif

#if __has_feature(objc_arc_weak)
#define __my_property_weak        weak
#define __my_property_weak_unsafe weak
//@property (nonatomic, weak) id startRet;
#else
#define __my_property_weak        retain
#define __my_property_weak_unsafe assign
//@property (nonatomic, assign) id startRet;
#endif
タイトルとURLをコピーしました