Importing AFNetworking without pod - ios

I want to add AFNetworking without pod and source code to my project. I started by adding source code and then following libraries.
Then I added prefix file
#import <Availability.h>
#if __IPHONE_OS_VERSION_MIN_REQUIRED
#ifndef __IPHONE_6_0
#warning "This project uses features only available in iPhone SDK 6.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#endif
#else
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <AssertMacros.h>
#import <CoreServices/CoreServices.h>
#endif
#endif
And add prefix file to Build Settings -> Apple LLVM 6.1 - Language -> Prefix Header.
After that I built project and I got following errors:
Implicit declaration of function 'SecItemExport' is invalid in C99
Use of undeclared identifier 'kSecFormatUnknown' Use of undeclared
identifier 'kSecItemPemArmour'
Which all are in a file and line. AFSecurity Policy.m, line 31. Which is:
__Require_noErr_Quiet(SecItemExport(key, kSecFormatUnknown, kSecItemPemArmour, NULL, &data), _out);
When I comment this line of code, which is not correct, the rest of project is built completely.
What should I do and why those errors happened?

I found the answer on github.
As mentioned in the release notes for 2.6, if you are installing the library manually you will need to define the following variables in your project's pch:
#ifndef TARGET_OS_IOS
#define TARGET_OS_IOS TARGET_OS_IPHONE
#endif
#ifndef TARGET_OS_WATCH
#define TARGET_OS_WATCH 0
#endif
Github Link.

My solution is to add "TARGET_OS_IOS=1" at Preprocessor Macros -- Build Settings

Related

OpenCV iOS - Expected identifier (MACRO)

Getting error from "opencv2.framework".
Just a new project contained "opencv2.framework" not running.
My Steps:
download latest opencv2.framework
add required frameworks
declare .pch file stuff
changed .m file -> .mm
Am I missing something?
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import <Availability.h>
#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#endif
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
#endif /* PrefixHeader_pch */
Line 46 says it all: You have to put opencv.hpp before any Apple's headers. In PrefixHeader.pch move
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
up and before
#import <Availability.h>

XCode 9 - Error while importing #import <objc/runtime.h> - for Simulator Only

I am trying to import #import & it gives me below error:
Declaration of 'objc_property_t' must be imported from module 'ObjectiveC.runtime' before it is required
Here is the code:
#import <Foundation/Foundation.h>
#if TARGET_IPHONE_SIMULATOR
#import <objc/objc-runtime.h>
#else
#import <objc/runtime.h>
#import <objc/message.h>
#endif
Please Note: For Device, it's compiled successfully. It generates an error for Simulator only. This happens since I started using XCode 9. For XCode 8 it was working fine.
It looks like in iOS 11, objc-runtime.h has been removed.
You need to either remove if macro or import , inside it.

Conditional Compilation not succeeding swift

I have two targets in my project TargetA and TargetB
TargetA bridging header file TargetA-Bridging-Header.h
#import "Class1.h"
#import "Class2.h"
#import "Class3.h"
TargetB bridging header file TargetB-Bridging-Header.h
#import "Class4.h"
#import "Class5.h"
#import "Class6.h"
There is one class of swift that is used in both Targets with name "MyCombinedTargetsClass.swift"
It has the following code
#if TARGETA
Class2.instance().someMethod()
#endif
Now the problem is if I compile TargetA then it succeeds but If I compile TargetB it gives me error "unresolved identifier Class2" though the code is written under macro of TargetA #if TARGETA

cannot find interface declaration for 'NSObject', superclass of 'GPXType'

I have done some research on that issue , but I have not found anything similar just yet.
I am using iOS GPX framework to draw the path on map using GPX file. I have import iOS GPX.framework on my project. but I have face an issue.
Please Guide me, If anyone has any advice...
Just modify the header file, add this line on top of the file
#import <Foundation/Foundation.h>
Seems they thought that you will have a PCH file, where Foundation and UIKit will be imported, but Xcode 6 removed PCH default support, so the problem came. (See my previous answer)
Finally I have solved my problem
I have import #import < UIKit/UIKit.h> and change my Xcode 6 Architectures $(ARCHS_STANDARD_32_BIT).
Thanks so much Guys.
You haven't imported the header file #import ...
When compiling for both iOS and OsX, I had similar issue that I have resolved by importing TargetConditionals.h. The final thing looks like this:
#import <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_MAC
#import <Cocoa/Cocoa.h>
#endif
#interface MyClass : NSObject
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
// Define UIKit methods
#elif TARGET_OS_MAC
// Define Cocoa methods
#endif
- (void)reloadRegisteredComponents;
#end

How can I declare a config.h file, add it to my App-Prefix.pch, and then use it globally in my app?

I want to create a Config.h file to house all my static const strings that should be global to my application.
I've created a new Config.h file, but there are a few things I'm unaware of.
1) How do I declare variables. A or B?
A)
#define hotelURLString4 = #"http://blah.herokuapp.com/api/v1/hotels/";
B)
static NSString * const hotelURLString2 = #"http://blah.herokuapp.com/api/v1/hotels/";
2) I can't seem to use this file. If I try to import the Config.h directly into a file of mine, I get a "Config.h file not found" error in xcode. If I include it in my AppName-Prefix.pch up at the top via...
#import <Availability.h>
#import "Config.h"
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
That does not seem to work either. How do I do this.
3) How do I access the variable declared/defined. Do I call Config.hotelURLString, or [Config hotelURLString]... or how do I access it?
===================================================================
============================ UPDATE ===============================
1) I created my header like this... am I not doing something correctly, because I tried again and it won't work either.
2) This is my AppName-Prefix.pch file.
#import <Availability.h>
#import "Config.h"
#import "MyHeader.h"
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
3) Here is my Project Navigator
To answer question 1, method B is probably better, although you should name your variable more like:
kHoteUrlString2
And preferably something more descriptive then just the numbers, but the main point here is the lower case k and the uppercase first letter. This is a C/ObjC naming convention for constants.
As for question 2, it sounds like your file isn't actually in the project. Some more details are needed to answer this part of the question, and I'll update my answer if the question has more details added.
As for question 3, you use the variable exactly as you would as if you had declared it at the top of whatever file you're using. Objective-C doesn't have namespaces.

Resources