getting error in EChart library [__NSCFString value] - ios

I am using EChart library, trying to make bar chart in iPad. I did make everything like in demo project but getting error :
-[__NSCFString value]: unrecognized selector sent to instance 0x8bba220
2014-08-18 08:28:44.684 STAT_V2_iPAD[19187:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString value]: unrecognized selector sent to instance 0x8bba220'
and here is the error code after debugging :
/** The highest value among the whole chart*/
- (EColumnDataModel *) highestValueEColumnChart:(EColumnChart *) eColumnChart{
EColumnDataModel *maxDataModel = nil;
float maxValue = -FLT_MIN;
NSLog(#"After FLT_MIN : %.f",FLT_MIN);
for (EColumnDataModel *dataModel in MergedArr)
{
NSLog(#"Data.Value = %f",dataModel.value);
if (dataModel.value > maxValue)
{
NSLog(#"inside ifd");
maxValue = dataModel.value;
maxDataModel = dataModel;
}
}
NSLog(#"Finished MAX %.f",maxDataModel.value);
return maxDataModel;
}

Problem is your dataModel holds NSString instead of EColumnDataModel . Below answer will prevent the crash but you need to find how string takes place?
-(EColumnDataModel *) highestValueEColumnChart:(EColumnChart *) eColumnChart{
EColumnDataModel *maxDataModel = nil;
float maxValue = -FLT_MIN;
NSLog(#"After FLT_MIN : %.f",FLT_MIN);
for (EColumnDataModel *dataModel in MergedArr)
{
if([dataModel isKindOfClass:[EColumnDataModel class]]){
NSLog(#"Data.Value = %f",dataModel.value);
if (dataModel.value > maxValue)
{
NSLog(#"inside ifd");
maxValue = dataModel.value;
maxDataModel = dataModel;
}
}
}
NSLog(#"Finished MAX %.f",maxDataModel.value);
return maxDataModel;
}

Related

App crash - when installed from App store but not locally

When i test my app as DEBUG then it works. But when i release to App store and from App Store install the app then it crash.
Therefore i changed the DEBUG RUN method into RELEASE run method for testing.
When i now run as RELEASE run method, then the app crash too (same as APP store Crash). The app crash is pointing at line 19.
How do i fix it? here i am telling to make an DNS (A or AAAA record) self.server = [self.server stringByAppendingString:#".example.com"]; by joining one string with the string i have from line 18.
- (void)myMethodHere:(NSString *)a {
//where a = #"splitme://test1/test2/test3";
NSArray *work_array = [a componentsSeparatedByString:#"splitme://"];
self.use_url =[work_array objectAtIndex:1];
if ([self.use_url length] > 0) {
NSArray *work_array = [self.use_url componentsSeparatedByString:#"/"];
self.server = [work_array objectAtIndex:0];
// -------------------
// CRASH HERE // CRASH HERE
// -------------------
if([self.server length] > 0) {
NSLog(#"!!!!!!!!!!!!!!!!!!!!!! 4 - part 1: %#", self.server); // WORKS
// Here we go CRASHing...
self.server = [self.server stringByAppendingString:#".example.com"];
NSLog(#"!!!!!!!!!!!!!!!!!!!!!! 4 - part 2: %#", self.server); // CRASH CRASH
}
else {
self.server = #"test.example.com";
}
}
else {
NSLog(#"!!!!!!!!!!!!!!!!!!!!!! 9: %#", self.use_url);
}
[self load_later];
}
EDIT 1: Following way of doing let me pass but if i have again self.server outside of this scope then app crash again.
NSString *part1 = self.server;
NSString *part2 = #".example.com";
NSString *result =[part1 stringByAppendingString:part2];
self.server = result;
NSLog(#"!!!!!!!!!!!!!!!!!!!!!! 4 - part 2: %#", self.server);
EDIT 2: crashing on AppDelegate.m, after commenting out the NSLog lines.
2017-04-08 10:32:01.773648+0200 app[344:18271] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-04-08 10:32:01.774146+0200 app[344:18271] [MC] Reading from public effective user settings.
2017-04-08 10:32:01.778647+0200 app[344:18271] -[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0
2017-04-08 10:32:01.778888+0200 app[344:18271] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0'
*** First throw call stack:
(0x18a956fd8 0x1893b8538 0x18a95def4 0x18a95af4c 0x18a856d2c 0x100006f78 0x1000076e8 0x1000066cc 0x190a85f9c 0x190a85b78 0x190a8c3f8 0x190a89894 0x190afb2fc 0x190d038b4 0x190d092a8 0x190d1dde0 0x190d0653c 0x18c4ff884 0x18c4ff6f0 0x18c4ffaa0 0x18a905424 0x18a904d94 0x18a9029a0 0x18a832d94 0x190af045c 0x190aeb130 0x100007d78 0x18984159c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
EDIT 3: Crashing NSString not NSString even with explicit cast
- (void)setServer:(NSString *)value
{
if (value != nil && ![value isKindOfClass:[NSString class]]) {
NSLog(#"!!!!!!!!!!!lol!!!!!!!!!!!!! Bug! Set breakpoint here!");
}
self.server = value;
}
NSArray *work_array = [self.use_url componentsSeparatedByString:#"/"];
NSString *setServerURL =(NSString *) [work_array objectAtIndex:0];
[self setServer:setServerURL];
EDIT 4: Crashing
- (void)myMethodHere:(NSString *)a {
NSArray *work_array = [a componentsSeparatedByString:#"test://"];
id objectOne = [work_array objectAtIndex:1];
if ([objectOne isKindOfClass:[NSString class] ] ) {
NSString *objectOneIntoString = objectOne;
self.use_url = (NSString *) objectOneIntoString;
}
if ([self.use_url length] > 0) {
NSLog(#"3: %#", self.use_url);
NSArray *work_array = [self.use_url componentsSeparatedByString:#"/"];
id objectTwo = [work_array objectAtIndex:0];
if ([objectTwo isKindOfClass:[NSString class] ]) {
NSString *objectTwoIntoString = objectTwo;
self.server = objectTwoIntoString;
}
if([self.server length] > 0) {
NSLog(#"4 - part 1: %#", self.server);
NSString *part1 = self.server;
NSString *part2 = #".example.com";
NSString *result = (NSString *) [part1 stringByAppendingString:part2];
self.server = result;
NSLog(#"4 - part 2: %#", self.server);
}
else {
self.server = #"dns.example.com";
NSLog(#"5:%#", self.server);
}
NSLog(#"8: %#", self.server);
}
else {
NSLog(#"9: %#", self.use_url);
}
NSLog(#"10: %#", self.use_url);
}
The error message in your pastebin is:
2017-04-08 10:32:01.778647+0200 app[344:18271] -[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0
2017-04-08 10:32:01.778888+0200 app[344:18271] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0'
This tells you that there was an array on which you called length. So if it really is related to your server property then you are accidentally storing an NSArray there somewhere.
Here's an idea on how to catch that: implement the setServer: method and check whether the type is correct.
- (void)setServer:(NSString *)value
{
if (value != nil && ![value isKindOfClass:[NSString class]]) {
NSLog(#"Bug! Set breakpoint here!");
}
_server = value;
}
Edit: You implemented your setter incorrectly and would normally have produced an endless recursion. So let's start from scratch:
I assume you have a property defined like this:
#property (strong) NSString * server; // Or maybe "copy"
If your property does not look like this you need to tell us!
Then you implement the setter exactly like this:
- (void)setServer:(NSString *)value
{
if (value != nil && ![value isKindOfClass:[NSString class]]) {
NSLog(#"Bug! Set breakpoint here!");
}
_server = value;
// DO NOT DO self.server = value HERE!
}
Then you can just do self.server = blabla; in the rest of your code and if your code sets something that is not a string the NSLog will be hit. So set a breakpoint there!
Edit 2:
Now I've seen in another comment of yours what's wrong…
#property (assign, nonatomic) NSString *server;
The assign does not retain the object! You need to use strong or (in the case if NSString *) copy. As it is, the following will happen:
You assign an object to server.
Since it is not retained, the object is deallocated soon.
But server still has a pointer to that memory location.
Two things can happen now:
Either a new, different object is created at memory location before you access the property. You now get an unexpected object back. Calling methods on this object may work or it may crash since the object does not know the method.
Or the memory location is deemed invalid and you get a crash right away.
Never use assign with objects!
-[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0
self.server class is NSArray .must string length

Error while getting value from NSDictionary

I'm trying to get from JSON parsed in NSDictionary and I'm getting this error all the time.
NSDictionary:
{
"admin_id" = 191767626;
body = "\U043a\U043b\U0430\U0441\U0441, \U043f\U043e\U0447\U0442\U0438 \U0434\U043e\U0434\U0435\U043b\U0430\U043b \U043f\U043e\U0434\U0434\U0435\U0440\U0436\U043a\U0443 \U0433\U0440\U0443\U043f\U043f\U043e\U0432\U044b\U0445 \U0431\U0435\U0441\U0435\U0434";
"chat_active" = "191767626,111273042,108237840,178159348,119271375,90588741,131506543,12657348,251374070,77508447,257350143,222456587,133059311,119425760,95255813,138571437,183017202,57733104,277277624,166958749,138127148,146374071,26326487,71995910,141152531,169957302,148888167,350803848,381660274,94296816,388139636";
"chat_id" = 104;
date = 1488494694;
mid = 1141349;
out = 1;
"photo_100" = "https://pp.userapi.com/c637621/v637621626/2317d/K9M4thCXrP0.jpg";
"photo_200" = "https://pp.userapi.com/c637621/v637621626/2317b/u5opnbkPQo0.jpg";
"photo_50" = "https://pp.userapi.com/c637621/v637621626/2317e/tNBXXHah700.jpg";
"push_settings" = {
"disabled_until" = 1773859745;
sound = 0;
};
"read_state" = 1;
title = CJB;
uid = 79372051;
"users_count" = 32;
}
So I'm interested in getting values for keys chat_id, title and users_count
I tried doing
NSLog(#"%#", [chatInfo objectForKey:#"chat_id"]);
But I'm getting this error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber objectForKey:]: unrecognized selector sent to instance 0x19478910'
How can I solve this? Thanks in advance!
Try like this :
NSLog(#"%#", [[chatInfo objectForKey:#"chat_id"] stringValue]);
Or
NSLog(#"%#",[NSString stringWithFormat:#"%#", [[chatInfo objectForKey:#"chat_id"] stringValue]]);
Hope this will work for you.
Try this and use breakpoints on NSLogs for understand what is wrong:
if ([chatInfo isKindOfClass:[NSArray class]]) {
NSArray *array = (NSArray *) chatInfo;
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([destinationVC isKindOfClass:[NSDictionary class]]) {
NSDictionary *dictionary = (NSDictionary *) destinationVC;
if (dictionary[#"chat_id"]) {
NSLog(#"chat_id: %#", dictionary[#"chat_id"]);
} else {
NSLog(#"chat_id: not found");
}
} else {
NSLog(#"its not dictionary, check your JSON mapping");
}
}];
} else {
NSLog(#"This is not NSArray!");
}

NSArrayM unrecognized selector error

I need some help understanding why I am getting an unrecognized selector error
I have a NSMutableDictionary
#interface CallDetailViewController () {
NSMutableDictionary * thisDictionary;
}
#end
That gets populated from the MasterTabController
- (void) some method {
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];
NSLog(#"Check dictinoary: %#", [thisDictionary description]);
}
Outputting a description shows the data is there
Check dictinoary: (
{
DATEIN = "2015-12-11 13:33:41";
"ETA" = "2015-12-14 13:54:16";
RecordKey = 2961;
Destination = "Some address";
Location = "Some location";
} )
But when I try to access an object in it:
NSLog(#"Destination: %#", [thisDictionary objectForKey:#"Destination"]);
I get the following error.
-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7a73f9a0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]:
unrecognized selector sent to instance 0x7a73f9a0'
The array is populated from a JSON value that returns an array of records called Record. After the JSON is returned, I pull out just section that contains the record.
NSDictionary * dictTowx = [NSDictionary dictionaryWithDictionary:[dictJSON objectForKey:#"ThisResponse"]];
NSDictionary * dictData = [NSDictionary dictionaryWithDictionary:[dictTowx objectForKey:#"Data"]];
NSArray * arrRecordSet = [dictData objectForKey:#"Recordset"];
NSDictionary * dicRecord= [arrRecordSet objectAtIndex:0];
self.detailDictionary = [dicRecord objectForKey:#"Record"];
The RAW JSON:
{
ThisResponse = {
Data = {
Recordset = (
{
Record = (
{
DATEIN = "2015-12-11 13:33:41";
"ETA" = "2015-12-14 13:54:16";
RecordKey = 2961;
Destination = "Some address";
Location = "Some location";
}
);
}
);
};
};
}
What am I doing wrong?
Please try to assign like this
self.detailDictionary = [[dicRecord objectForKey:#"Record"] objectAtIndex:0];
and then access like this
NSLog(#"Destination: %#", [thisDictionary objectForKey:#"Destination"]);
Enjoy programming.
- (void) some method {
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];
NSLog(#"Check dictinoary: %#", [thisDictionary description]);
}
try replacing
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];
with
thisDictionary = [[NSMutableDictionary alloc]initWithDictionary: [[{MasterTabController *)self.tabBarController detailDictionary] mutableCopy]]];
i think your problem may be you are not instantiating the dictionary before setting it to objects from another.

iOS app crashing with error: NSCFNumber stringByReplacingOccurrencesOfString:withString: unrecognized selector sent to instance

Our iOS app terminates with an error of [__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090.
We're testing on an iPhone 5 w iOS 7.
It crashes on this line: [self parseDictionary:notificationMessage intoJSON:jsonStr].
Method containing this line:
- (void)notificationReceived {
NSLog(#"Notification received");
if (notificationMessage && self.callback)
{
NSMutableString *jsonStr = [NSMutableString stringWithString:#"{"];
[self parseDictionary:notificationMessage intoJSON:jsonStr];
if (isInline)
{
[jsonStr appendFormat:#"foreground:\"%d\"", 1];
isInline = NO;
}
else
[jsonStr appendFormat:#"foreground:\"%d\"", 0];
[jsonStr appendString:#"}"];
NSLog(#"Msg: %#", jsonStr);
NSString * jsCallBack = [NSString stringWithFormat:#"%#(%#);", self.callback, jsonStr];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
self.notificationMessage = nil;
}
}
-(void)parseDictionary:(NSDictionary *)inDictionary intoJSON:(NSMutableString *)jsonString
{
NSArray *keys = [inDictionary allKeys];
NSString *key;
for (key in keys)
{
id thisObject = [inDictionary objectForKey:key];
if ([thisObject isKindOfClass:[NSDictionary class]])
[self parseDictionary:thisObject intoJSON:jsonString];
else
[jsonString appendFormat:#"\"%#\":\"%#\",",
key,
[[[[inDictionary objectForKey:key]
stringByReplacingOccurrencesOfString:#"\\" withString:#"\\\\"]
stringByReplacingOccurrencesOfString:#"\"" withString:#"\\\""]
stringByReplacingOccurrencesOfString:#"\n" withString:#"\\n"]];
}
}
Stack trace (along with one debugging line to show the variable value):
2014-01-07 16:32:36.980 Wopple[195:60b] Notification received
Printing description of self->notificationMessage:
{
"_" = "gHf8EeO3_ZDiugJkgA";
aps = {
alert = "hi foo bar right";
badge = 3;
};
}
2014-01-07 16:33:22.774 Wopple[195:60b] -[__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090
2014-01-07 16:33:22.776 Wopple[195:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090'
*** First throw call stack:
(0x308c3e83 0x3ac246c7 0x308c77b7 0x308c60af 0x30814dc8 0x88da5 0x88d1f 0x88915 0x8757b 0x3335ec93 0x3335f75d 0x340d0b37 0x3088e777 0x3088e713 0x3088cedf 0x307f7471 0x307f7253 0x3552b2eb 0x330ac845 0x7f5d3 0x3b11dab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
When you're using:
[[[[inDictionary objectForKey:key]
stringByReplacingOccurrencesOfString:#"\\" withString:#"\\\\"]
stringByReplacingOccurrencesOfString:#"\"" withString:#"\\\""]
stringByReplacingOccurrencesOfString:#"\n" withString:#"\\n"]];
You're assuming that objectForKey is going to return an NSString object. But, in the case where your app is crashing, the object returned is actually an NSNumber.
You should use isKindOfClass: to determine the object type, or use stringValue on your NSNumber to get a string representation of the object.

performSelector afterDelay with multiple arguments error

I´m having some problems with performSelector method on this code:
This method are in other class called "JSONMethods":
+(void)sendPostMsgWithMultipleArguments:(NSArray *)myArgs {
[self sendPostMsg:[myArgs objectAtIndex:0]:[myArgs objectAtIndex:1]];
}
Then, on another class I have the call:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Loading...";
JSONMethods *methods = [[JSONMethods alloc]init];
NSArray *arguments = [[NSMutableArray alloc]initWithObjects:#"http://localhost/promos/txFirmas.php",[NSString stringWithFormat:#"sensor=%d",tableViewNumber], nil];
[methods performSelector:#selector(sendPostMsgWithMultipleArguments:)
withObject:arguments
afterDelay:3.0];
NSString *tit = [NSString stringWithFormat:#"Sign: %d",tableViewNumber];
self.title = tit;
}
I would like wait until the "sendPostMsgWithMultipleArguments:" finish for change the title, how I can make it?
When I test this, mi app crash and show me this by console:
2012-08-17 12:09:15.966 MapaProject[524:11603] -[JSONMethods sendPostMsgWithMultipleArguments:]: unrecognized selector sent to instance 0x7c85b70
2012-08-17 12:09:15.968 MapaProject[524:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[JSONMethods sendPostMsgWithMultipleArguments:]: unrecognized selector sent to instance 0x7c85b70'
*** First throw call stack:
(0x133a022 0x2016cd6 0x133bcbd 0x12a0ed0 0x12a0cb2 0xa1c85d 0x130e936 0x130e3d7 0x1271790 0x1270d84 0x1270c9b 0x15db7d8 0x15db88a 0xf6626 0x236d 0x20c5)
terminate called throwing an exception
Can you help me?
Thanks in advance :)
Change +(void)sendPostMsgWithMultipleArguments:(NSArray *)myArgs
to -(void)sendPostMsgWithMultipleArguments:(NSArray *)myArgs
or even better change
[methods performSelector:#selector(sendPostMsgWithMultipleArguments:) withObject:arguments afterDelay:3.0];
to [[methods class] performSelector:#selector(sendPostMsgWithMultipleArguments:)
withObject:arguments
afterDelay:3.0];
NSArray * mutArray = [NSArray arrayWithObjects:[NSNumber numberWithInt:0],[NSNumber numberWithInt:2], nil]
[self performSelector:#selector(loadMore:) withObject:mutArray afterDelay:1.9];
-(void)loadMore:(NSArray *)array
{
NSNumber * myNumber = [array objectAtIndex:0];
NSNumber * myNumber2 = [array objectAtIndex:1];
}
In swift 3
You can make dictionary to save multiple arguments and pass it with the selector
let argumentsDict = ["arg1Key": arg1Value, "arg2Key": arg2Value] as [String : Any]
perform(#selector(selectorWithMultipleArg), with: argumentsDict, afterDelay: 3.0)
And inside the selector function, take out values using guard and use them. I am using 2 different type arguments to explain better .i.e. Int and String
func selectorWithMultipleArg(_ arguments: [String: Any]) {
guard let arg1Value = arguments["arg1Key"] as? Int else {
fatalError("Invalid value 1")
}
guard let arg2Value = arguments["arg2Key"] as? String else {
fatalError("Invalid value 2")
}
print("Value 1: \(arg1Value)")
print("Value 2: \(arg2Value)")
}
I hope this would help you

Resources