Can please any one tell how to use macros like debuglog by using print some information to console while building a framework in ios, and it should work when application developer runs the application with this framework in debug mode.
1) define a global BOOL in your library with some odd name:
BOOL GzRkYr22; // (use your framework name as prefix or suffix)
2) provide some means for your users to turn the flag on or off:
- (void)enabledDebuggingMessages:(BOOL)val;
That method will set the global flag.
3) Put this in your .pch file
extern BOOL GzRkYr22;
#define Log(format, ...) \
do { if(GzRkYr22 ) NSLog(format, \
## __VA_ARGS__); \
} while(NO)
4) Sprinkle your code with Log messages:
Log(#"Just did %d operations", someNumber);
5) If you later decide you want to only have log messages for a “debug” version of your library, but totally disable them for "production" versions:
#ifndef NDEBUG // some macro that is defined or not defined for the different modes
#define Log(format, ...) \
do { if(GzRkYr22 ) NSLog(format, \
## __VA_ARGS__); \
} while(NO)
#else
#define Log(format, ...)
#endif
Related
I'm trying to compile eigen 3.3.9 fron the github mirror with VS2019, /std:c++latest and /Zc:__cplusplus
What i get is a
eigen\Eigen\src\Core\util\Meta.h(320,25): error C2039: 'result_of': is not a member of 'std'
because EIGEN_HAS_STD_RESULT_OF is defined. This get's determined here:
#ifndef EIGEN_HAS_STD_RESULT_OF
#if EIGEN_MAX_CPP_VER>=11 && ((__has_feature(cxx_lambdas) || (defined(__cplusplus) && __cplusplus >= 201103L)))
#define EIGEN_HAS_STD_RESULT_OF 1
#else
#define EIGEN_HAS_STD_RESULT_OF 0
#endif
#endif
From what i can read, std::result_of is removed in C++20 which is not reflected in the check above.
Am i doing something wrong? Is there an easy way to compile eigen with VS, C++20 and a __cplusplus define which reflects the actual standard version without having to manually set all the defines myself or patching Macros.h?
I'm including a Swift source in my CocoaPods library for the first time. For me to get the project to compile, I need to import the generated Swift header into my Objective-C source. This takes two different forms, depending on whether the project is being built as a static library or a dynamic framework:
#ifdef BUILT_AS_FRAMEWORK
#import <UnzipKit/UnzipKit-Swift.h>
#else
// Used when built as a static library
#import "UnzipKit-Swift.h"
#endif
I'm defining BUILT_AS_FRAMEWORK in my Xcode project for development time, but when I lint the library as a dynamic framework, and because I haven't defined that flag in the Podspec, it attempts to resolve the second import, and can't find it.
Is there a way I can define the BUILT_AS_FRAMEWORK preprocessor macro, but only if the consuming Podfile doesn't build it as a static library?
I created issue #9101 in the CocoaPods project for this question.
I was able to use an Xcode environment variable (PACKAGE_TYPE) in conjunction with a pre-compilation Run Script build phase to dynamically produce a header to import, which in turn makes the correct generated Swift Header import.
generate-swift-import-header.sh
#!/bin/sh
[[ "${PACKAGE_TYPE}" = "com.apple.package-type.wrapper.framework" ]] \
&& SWIFTIMPORT="<${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}-Swift.h>" \
|| SWIFTIMPORT="\"${PRODUCT_MODULE_NAME}-Swift.h\""
if [ -z "$PODS_TARGET_SRCROOT" ]; then
PODS_TARGET_SRCROOT=${SOURCE_ROOT}
echo "Building in Xcode instead of CocoaPods. Overriding PODS_TARGET_SRCROOT with SOURCE_ROOT"
fi
_Import_text="
#ifndef GeneratedSwiftImport_h
#define GeneratedSwiftImport_h
#import ${SWIFTIMPORT}
#endif /* GeneratedSwiftImport_h */
"
echo "$_Import_text" > ${PODS_TARGET_SRCROOT}/Source/GeneratedSwiftImport.h
Podspec update
s.script_phases = { :name => "Generate UnzipKit Swift Header",
:script => "\"${PODS_TARGET_SRCROOT}\"/Scripts/generate-swift-import-header.sh",
:execution_position => :before_compile }
Library source
I replaced my conditional import with this:
#import "GeneratedSwiftImport.h"
I also ignored the GeneratedSwiftImport.h file in Git.
Problem statement:- I am using third party library, which need to have config.plist(name must be same), Config.plist have several key-value pairs, for production,Dev and stating environment, values for key does change.
Right now i need to manually change file Name, like if i need to run app in production environment, i do change file name ConfigPROD.plist into Config.plist,
for Staging i do change file name from ConfigDev.plist into Config.plist.
Need Solution like:- can i change, file content using preprocessor macro, like
#if isProductionBuild == 1
#define kBaseURL #"https://api.base.com/bart/"
#define kEnvironmnet #"PROD"
***//copy ConfigPROD.plist file content into Config.plist***
#elif isStageBuild == 1
#define kBaseURL #"https://api-stage.base.com/bart/"
#define kEnvironmnet #"stg"
*//copy ConfigSTG.plist file content into Config.plist*
#else
#define kBaseURL #"https://api-dev.base.com/bart/"
#define kEnvironmnet #"dev"
*//copy ConfigDEV.plist file content into Config.plist*
#endif
pleae see if we do have feature like "copy ConfigDEV.plist file content into Config.plist"
Note:- This file copy operation should get completed before third party library start using Config.plist.
You don't need a preprocessor macro, you need a Run Script build phase that gets executed first. See Running a Script While Building a Product for an introduction. Just create a Bash script that looks at $CONFIGURATION (which will be Debug or Release or any other configuration name you have) and then renames one or the other file. Something like:
mv ./Config.plist ./Config.plist.orig
if [[ 'Release' == ${CONFIGURATION} ]]; then
cp ./Config.PROD.plist ./Config.plist
else
cp ./Config.DEV.plist ./Config.plist
To easily handle this, add all 3 files (Config.plist, Config.DEV.plist and Config.PROD.plist) to Xcode, but only the first one should be added to the target (check the box in the right side panel). You can have default settings in this file, it will be overwritten anyway.
If you're using git or something similar, you can add another run script phase at the end of your build to restore the original Config.plist to hide your changes from git.
I have an crossplatform implementation of own protocol, data-structures and logic written on Haxe. How I can build and use it in my enterprise-application (with native UI) for iOS and OSX?
How to create iOS- / OSX- library from Haxe and use it in native application
Actuality: 12.2014; HXCPP-ver.: 3.1.39~git.
Dependency: hxcpp
1. Haxe -> Library
Create a new Haxe-project with main class named HxModule.
src/HxModule.hx
class HxModule
{
public static function main()
{
Sys.println('Hello from HxModule: "${test()}"');
}
#:headerCode
public static function test():Int
{
return 101;
}
}
build.hxml
-main HxModule
-cp src
-lib hxcpp
# this is for Mac OS X:
-D HXCPP_M64
# this is required on Windows. the "d" stands for debug:
#-D ABI=-MTd
--each
# at this phase we create a binary for tests
-cpp out/cpp/module
--next
# at this phase we create a binary for tests
-cpp out/cpp/module
-D static_link
-D actuate
Build: $ haxe buid.hxml
2. Xcode-project <- Library
Create a new Xcode-project. It can be for OSX or iOS, Application or Cocoa Framework.
In the 'Project' / 'Build Setting' / 'Header Search Paths' add paths to dependencies: (all paths must be full/not-relative and recursive)
out/cpp/module/include - you have to fix it to full path;
{your-haxelib-repo}/hxcpp/{version}/include - {here-yours};
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
In the 'Project' / 'Build Settings' / 'Apple LLVM 6.0 - Language - C++' change values:
'C++ Language Dialect' = GNU++11 [-std=gnu++11]
'C++ Standard Library' = libstdc++ (GNU C++ standard library)
In the 'Project' / 'Build Phases' / 'Link Binary With Libraries':
HxModule.a
Rename file: AppDelegate.m -> AppDelegate.mm
Edit AppDelegate.mm:
AppDelegate.mm
#import "AppDelegate.h"
#import "HxModule.h"
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSLog(#"test: %d", ((int)HxModule_obj::test()));
}
#end
Additionally for autocomplete and better navigation you can add into Xcode-project the reference groups from directories:
include from output of Haxe;
include from haxelib hxcpp.
Possible problems:
At the time when this text was written only one possible issue. It can be solved by editing the file {haxelib:hxcpp}/include/hxcpp.h. Simply add a few lines at the beginning of the file:
{haxelib:hxcpp}/include/hxcpp.h
#ifndef HXCPP_H
#define HXCPP_H
// Standard headers ....
// Custom override by #suhinini
#define Class HxcppClass
// Basic mapping from haxe -> c++
typedef int Int;
typedef bool Bool;
// Windows hack
#define NOMINMAX
#ifdef _MSC_VER
#include <typeinfo.h>
namespace hx { typedef ::type_info type_info; }
...
see after // Standard headers .....
Example project.
I have 2 targets on my project one production and one stage with different configurations.
I want in the code to be able to say
#if target == production
NSLog(#"production");
#elif target == stage
NSLog(#"stage");
#endif
Can someone please tell me how can I do that?
Thank you,
~Sonic555gr
You can define some Preprocessor Macros for each Target, like this...
And then you can do something like this:
#ifdef PRODUCTION
//some Code
#elif STAGE
//some other Code
#else
//more Code^^
#endif
But be carefull if you need it in Debug- and/or in Release-Build, you have to declare it there.