I'm busy with a library of a collegae. In his code he sets isa a few times. This stills works but is officially deprecated. The alternative should be the object_setClass function. But when I replace it I get a warning: Implicit declaration of function 'object_setClass' is invalid in C99.
Perhaps i am missing an import or something? Anyone an idea? Thanks.
if(nodePtr->type == XML_ELEMENT_NODE)
{
self->isa = [DDXMLElement class];
//object_setClass(self, [DDXMLElement class]);
}
else if(nodePtr->type == XML_DOCUMENT_NODE)
{
self->isa = [DDXMLDocument class];
//object_setClass(self, [DDXMLDocument class]);
}
It's declared in #include <objc/runtime.h> -- have you included that header?
Related
I am trying to use LogglyLogger-CocoaLumberjack in my swift project.
I am getting this error in xCode.
Enum case 'verbose' has no associated values
I am unable to resolve this.
https://prnt.sc/uznr01
I am actually trying to translate the Objective-C code in swift 5. Here is my swift function
in appDelegate.swift class
func initLoggly(){
// static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
let ddLogLevel:DDLogLevel = .verbose
// LogglyLogger *logglyLogger = [[LogglyLogger alloc] init];
let logglyLogger = LogglyLogger()
// [logglyLogger setLogFormatter:[[LogglyFormatter alloc] init]];
logglyLogger.logFormatter = LogglyFormatter()
// logglyLogger.logglyKey = #"your-loggly-api-key";
logglyLogger.logglyKey = "XXXXXXXXXXXX-XXXXXX"
//
// // Set posting interval every 15 seconds, just for testing this out, but the default value of 600 seconds is better in apps
// // that normally don't access the network very often. When the user suspends the app, the logs will always be posted.
// logglyLogger.saveInterval = 15;
logglyLogger.saveInterval = 15
// [DDLog addLogger:logglyLogger];
DDLog.add(logglyLogger)
// // Do some logging
// DDLogVerbose(#"{\"myJsonKey\":\"some verbose json value\"}");
// ddLogLevel.verbose("{\"initloggly\":\"some verbose json value\"}") // also tried this, error ==> Enum case 'verbose' cannot be used as an instance member
DDLogLevel.verbose("{\"initloggly\":\"some verbose json value\"}") // Here is the error on this line
}
Please point out what I am doing wrong!
This library is heavly based on C preprocessor macros which aren't accessible from Swift.
You will probably need to write a small set of wrapper functions in Objective-C that use these macros and are in turn callable from Swift.
Here's an example of how this could look like:
LogglyWrapper.h:
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
#interface LogglyWrapper : NSObject
+(void) logVerbose:(NSString*) msg;
#end
NS_ASSUME_NONNULL_END
and LogglyWrapper.m:
#import "LogglyWrapper.h"
#import <LogglyLogger.h>
#implementation LogglyWrapper
static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
+(void) logVerbose:(NSString*) msg {
DDLogVerbose(#"%#", msg);
}
#end
usage from Swift:
LogglyWrapper.logVerbose("foo")
I know what duplicate symbol linker error means, but in my case I don't know how I'm getting it. I have the following file, which defines some simple globals
// defines.h
#ifndef _DEFINES_H
#define _DEFINES_H
BOOL useTestCode = YES;
#endif
Then I import it in two *.m files, and use the global.
// someFile1.m
#import "defines.h"
- (void)foo
{
if (useTestCode) {
NSLog(#"Using test code");
}
else {
NSLog(#"NOT Using test code");
}
}
// someFile2.m
#import "defines.h"
- (void)foo
{
if (useTestCode) {
NSLog(#"Using test code");
}
else {
NSLog(#"NOT Using test code");
}
}
If I comment out one of the #import "defines.h" statement in either file, I don't get the duplicate symbol linker error, but of course the corresponding *.m file will fail to compile. Why am I getting the duplicate symbol linker error? How do I solve it in iOS 7?
Here is the linker error message. It's literally for the simple code above.
duplicate symbol _useTestCode in:
/Users/cfouts/Library/Developer/Xcode/DerivedData/DupSymbol-bnfownlxdoyqelbhxzpyaaitfshy/Build/Intermediates/DupSymbol.build/Debug-iphonesimulator/DupSymbol.build/Objects-normal/x86_64/DSsomeFile2.o
/Users/cfouts/Library/Developer/Xcode/DerivedData/DupSymbol-bnfownlxdoyqelbhxzpyaaitfshy/Build/Intermediates/DupSymbol.build/Debug-iphonesimulator/DupSymbol.build/Objects-normal/x86_64/DSsomeFile1.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
in your header you have
BOOL useTestCode = YES;
which is copied to every .m file that includes it so you have multiple useTestCode symbols
you need to change the header to contain
extern BOOL useTestCode;
and in one .m file, define the variable
BOOL useTestCode = YES;
Though Bryan C's answer is one solution, and it gave me a clue, I like this better.
// defines.h
#ifndef _DEFINES_H
#define _DEFINES_H
static BOOL useTestCode = YES;
#endif
I have a CFUserNotificationDisplayAlert setup like this:
CFOptionFlags cfRes;
CFUserNotificationDisplayAlert(5, kCFUserNotificationNoteAlertLevel,
NULL, NULL, NULL,
CFSTR("Okay"),
CFSTR("Stop!"),
&cfRes);
switch (cfRes)
{
case kCFUserNotificationDefaultResponse:
strTest = CFSTR("Default response");
break;
case kCFUserNotificationAlternateResponse:
strTest = CFSTR("Alternate response");
break;
}
With this code I get this error:
use of undeclared identifier kCFUserNotifactationDefualtResponce (And the other kCF*'s)
Any ideas? I have the following imported:
#import <CoreFoundation/CoreFoundation.h>
#import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>
The CFUserNotification API is not available on iOS. Looks to me like you copied that bit of code from a Mac App.
Quoted from CodaFi's comment above so question can be marked as answered as per: https://meta.stackexchange.com/questions/54718/how-should-i-handle-questions-which-are-answered-in-the-comments
I tried with the below code snippet taken from the website after replacing with my namespace and realm. But when i try to run the application, I am receiving the parser error like
Entity: line 1: parser error : Start tag expected, '<' not found
WACloudAccessControlClient *acsClient =
[WACloudAccessControlClient
accessControlClientForNamespace:#“iostest-walkthrough”
realm:#“uri:wazmobiletoolkit”];
[acsClient showInViewController:self
allowsClose:NO
withCompletionHandler:^(BOOL authenticated)
{
if (!authenticated) {
NSLog(#"Error authenticating");
} else {
WACloudAccessToken *token = [WACloudAccessControlClient sharedToken];
NSString *securityToken = [token securityToken];
}
}];
I am not able to understand the issue clearly.
Please guide me with example. Thank you
I would suggest looking at the samples here:
https://github.com/WindowsAzure-Toolkits/wa-toolkit-ios
You can also look at this for getting started:
http://www.wadewegner.com/2011/05/windows-azure-toolkit-for-ios/
My guess is that you didn't #import something you need.
I want use function 'dlopen()' to invoke a dynamic library on iOS platform, is the function 'dlopen()' private API?
I've had success using dlopen on iOS for years. In my use case, I use dlopen to load public system frameworks on demand instead of having them loaded on app launch. Works great!
[EDIT] - as of iOS 8, extensions and shared frameworks are prohibited from using dlopen, however the application itself can still use dlopen (and is now documented as being supported for not only Apple frameworks, but custom frameworks too). See the Deploying a Containing App to Older Versions of iOS section in this Apple doc: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensibilityPG.pdf
[EDIT] - contrived example
#import <dlfcn.h>
void printApplicationState()
{
Class UIApplicationClass = NSClassFromString(#"UIApplication");
if (Nil == UIApplicationClass) {
void *handle = dlopen("System/Library/Frameworks/UIKit.framework/UIKit", RTLD_NOW);
if (handle) {
UIApplicationClass = NSClassFromString(#"UIApplication");
assert(UIApplicationClass != Nil);
NSInteger applicationState = [UIApplicationClass applicationState];
printf("app state: %ti\n", applicationState);
if (0 != dlclose(handle)) {
printf("dlclose failed! %s\n", dlerror());
}
} else {
printf("dlopen failed! %s\n", dlerror());
}
} else {
printf("app state: %ti\n", [UIApplicationClass applicationState]);
}
}