xcode - unrecognized selector sent to instance - ios

I called method in another class (they are both singletons).
WebserviceHelper.h
#interface WebserviceHelper : NSObject {
int currentType;
NSString *SERVER_URL;
WebserviceManager *webService;
}
#property (nonatomic, assign) id delegate;
- (void)retrieveStudentwithCode:(NSString *)code {
currentType = STUDENT_TYPE;
NSString *param = [NSString stringWithFormat:#"token=uencom&cid=%#", code];
NSString *link = [NSString stringWithFormat:#"%#getStudentInfo", SERVER_URL];
[webService retrieveData:link withParameters:param];
}
After call webservice and get data it cached here in received data. I check and it works fine
but when it deliver to didFinishLoading error happen here
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)receivedData {
data = [NSMutableData new];
[data appendData:receivedData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
//it carsh here
[delegate: data];
}
Call stack:
2014-08-20 10:39:05.187 School-Link[1030:60b] -[WebserviceHelper :]: unrecognized selector sent to instance 0xa88a420
2014-08-20 10:39:05.188 School-Link[1030:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WebserviceHelper :]: unrecognized selector sent to instance 0xa88a420'
*** First throw call stack:
(
0 CoreFoundation 0x01bf31e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018f08e5 objc_exception_throw + 44
2 CoreFoundation 0x01c90243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01be350b ___forwarding___ + 1019
4 CoreFoundation 0x01be30ee _CF_forwarding_prep_0 + 14
5 School-Link 0x00030c82 -[WebserviceManager connectionDidFinishLoading:] + 242
6 Foundation 0x016b9e49 ___NSURLConnectionDidFinishLoading_block_invoke + 40
7 Foundation 0x016507e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
8 Foundation 0x014d8f5e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
9 Foundation 0x014d8ec6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
10 Foundation 0x014d8dd8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
11 Foundation 0x014d9188 _NSURLConnectionDidFinishLoading + 43
12 CFNetwork 0x02a3169f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 111
13 CFNetwork 0x02a2f3de ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
14 CoreFoundation 0x01b94c69 CFArrayApplyFunction + 57
15 CFNetwork 0x02998441 _ZN19RunloopBlockContext7performEv + 155
16 CFNetwork 0x02a7a3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
17 CFNetwork 0x02998257 _ZN17MultiplexerSource7performEv + 299
18 CFNetwork 0x0299806c _ZN17MultiplexerSource8_performEPv + 76
19 CoreFoundation 0x01b7c77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
20 CoreFoundation 0x01b7c1d5 __CFRunLoopDoSources0 + 437
21 CoreFoundation 0x01b991ae __CFRunLoopRun + 910
22 CoreFoundation 0x01b989d3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x01b987eb CFRunLoopRunInMode + 123
24 GraphicsServices 0x0338d5ee GSEventRunModal + 192
25 GraphicsServices 0x0338d42b GSEventRun + 104
26 UIKit 0x005b0f9b UIApplicationMain + 1225
27 School-Link 0x00018f6d main + 141
28 libdyld.dylib 0x03026701 start + 1
29 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Try this, have a protocol declaration in WebserviceHelper.h like
#protocol studentDataDelegate <NSObject>
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
#end
WebserviceHelper.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
[self.delegate WebserviceHelper:self didStudentDataDownloadCompleteWithData:data];
}
so which ever class confirms to the above protocol should implement the delegate method like,
#interface RequestingDataClass : UIViewController <studentDataDelegate>
by doing this you will receive the warning that you have not implemented didStudentDataDownloadCompleteWithData:method so do it like
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
{
webserviceHelper.delegate=self;
// Do something with the `data`
}

You do no show the declaration of the delegate, however this statement:
[delegate: data];
Should be:
[delegate haveSomeData:data];
(or something similar)

did you create protocol in your WebserviceHelper.h file like this?
#protocol WebserviceHelperDelegate <NSObject>
#required
-(void)reciveData:(NSData *)data;//or your method
#end
decleare a property
#property (nonatomic,strong) id <WebserviceHelperDelegate> delegate;
then call this method like
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
//it carsh here
[self.delegate reciveData: data];
}
And implement this method from where you call webservice class and assign delegate
-(void)reciveData:(NSData *)data{
}

Related

When I use a NSMutableArray which as a property of a Singleton , to add some object into the NSMutableArray. It crushed

Here is my sampleCode :
-(IBAction)add:(id)sender {
//ShoppingManager sharedManager is a singleton
[[ShoppingManager sharedManager].onlineClassArray addObject:#(1)];
}
and code in ShoppingManager.m:
//singleton
+ (ShoppingManager *)sharedManager{
static id instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc]init];
});
return instance;
}
- (OnlineClassItemizeArray *)onlineClassArray{
if (!_onlineClassArray) {
_onlineClassArray = [OnlineClassItemizeArray array];
}
return _onlineClassArray;
}
and the ShoppingMananger.h:
#interface ShoppingManager : NSObject
#property(nonatomic,strong) OnlineClassItemizeArray * onlineClassArray;
+ (ShoppingManager*)sharedManager;
#end
I don't know what is wrong with these codes.when i added some object into the mutableArray,it stopped at this line:(a all Exception BreakPoint)
_onlineClassArray = [OnlineClassItemizeArray array];
than crushed at here:
DISPATCH_INLINE DISPATCH_ALWAYS_INLINE DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
DISPATCH_SWIFT3_UNAVAILABLE("Use lazily initialized globals instead")
void
_dispatch_once(dispatch_once_t *predicate,
DISPATCH_NOESCAPE dispatch_block_t block)
{
if (DISPATCH_EXPECT(*predicate, ~0l) != ~0l) {
dispatch_once(predicate, block);//<---crushed here
} else {
dispatch_compiler_barrier();
}
DISPATCH_COMPILER_CAN_ASSUME(*predicate == ~0l);
}
and here is the whole error msg:
2017-03-14 01:01:36.586 tesr1111[7075:1333259] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray initWithCapacity:]: method only defined for abstract class. Define -[OnlineClassItemizeArray initWithCapacity:]!'
*** First throw call stack:
(
0 CoreFoundation 0x00000001100c4d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010fb2621e objc_exception_throw + 48
2 CoreFoundation 0x00000001101357df __CFRequireConcreteImplementation + 255
3 CoreFoundation 0x00000001101241a7 -[NSMutableArray initWithCapacity:] + 39
4 tesr1111 0x000000010f54e6d0 -[ShoppingManager init] + 160
5 tesr1111 0x000000010f54e5f1 __32+[ShoppingManager sharedManager]_block_invoke + 65
6 libdispatch.dylib 0x0000000112eda0cd _dispatch_client_callout + 8
7 libdispatch.dylib 0x0000000112ebf1f8 dispatch_once_f + 501
8 tesr1111 0x000000010f54e588 +[ShoppingManager sharedManager] + 136
9 tesr1111 0x000000010f54de9d -[ViewController add:] + 61
10 UIKit 0x00000001104ea8bc -[UIApplication sendAction:to:from:forEvent:] + 83
11 UIKit 0x0000000110670c38 -[UIControl sendAction:to:forEvent:] + 67
12 UIKit 0x0000000110670f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
13 UIKit 0x000000011066fe4d -[UIControl touchesEnded:withEvent:] + 668
14 UIKit 0x0000000110558545 -[UIWindow _sendTouchesForEvent:] + 2747
15 UIKit 0x0000000110559c33 -[UIWindow sendEvent:] + 4011
16 UIKit 0x00000001105069ab -[UIApplication sendEvent:] + 371
17 UIKit 0x0000000120cca481 -[UIApplicationAccessibility sendEvent:] + 93
18 UIKit 0x0000000110cf372d __dispatchPreprocessedEventFromEventQueue + 3248
19 UIKit 0x0000000110cec463 __handleEventQueue + 4879
20 CoreFoundation 0x0000000110069761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000011004e98c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x000000011004de76 __CFRunLoopRun + 918
23 CoreFoundation 0x000000011004d884 CFRunLoopRunSpecific + 420
24 GraphicsServices 0x0000000113eb0a6f GSEventRunModal + 161
25 UIKit 0x00000001104e8c68 UIApplicationMain + 159
26 tesr1111 0x000000010f54e4df main + 111
27 libdyld.dylib 0x0000000112f2668d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
If anyone can give me any idea or helping link. Thanks in advance.
You are subclassing NSMutableArray incorrectly. It is a class cluster and there is a minimum set of methods that need to be implemented.
In this case, you are calling initWithCapacity: but haven't overridden that method. Or, more likely, you are calling a generic method (init) that calls through to that method.
Exactly as the exception says:
2017-03-14 01:01:36.586 tesr1111[7075:1333259] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSMutableArray initWithCapacity:]: method only defined for abstract class. Define -[OnlineClassItemizeArray initWithCapacity:]!'
However, subclassing the collection classes is a code smell. It is pretty much never done. There are rare cases where it makes sense; what is yours?

Check value in TextField with NSDictionary Objective C (for Login)

I'am a super a super rookie in IOS. I am doing a login feature. When the login in button is pressed, the APP shall check the text from storage. Then it should change to the second VC if check status return true. I currently have a ViewController to ViewController segue with identifier. I tried the perform segue with identifier but it doesn't work.(Doesn't change scene and shows no alert.)
Here is the login Page.
#import
#interface LoginPage : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *usernameField;
#property (strong, nonatomic) IBOutlet UITextField *passwordField;
- (IBAction)LoginTapped:(id)sender;
- (IBAction)SignupTapped:(id)sender;
#end
the login.m
#import "LoginPage.h"
#import "Home.h"
#implementation LoginPage
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)LoginTapped:(id)sender {
NSMutableDictionary *infodictionary =[[NSMutableDictionary alloc] init];
[infodictionary setObject:#"1" forKey:#"rose"];
[infodictionary setObject:#"2" forKey:#"cathy"];
[infodictionary setObject:#"3" forKey:#"corey"];
if ([_passwordField.text isEqualToString:[infodictionary objectForKey: _usernameField.text]]){
// Home *home = [[Home alloc] init];
[self performSegueWithIdentifier:#"ToHome" sender:self];
}
}
- (IBAction)SignupTapped:(id)sender {
NSString *_NAME = [NSString alloc];
NSString *_PASS = [NSString alloc];
_NAME= _usernameField.text;
_PASS = _passwordField.text;
}
#end
the stimulator gives me terminating with uncaught exception of type NSException
2016-02-07 05:39:49.437 project_feature_login[8249:941926] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7fb5f9c98300> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key passwordField.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102b18f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000102592deb objc_exception_throw + 48
2 CoreFoundation 0x0000000102b18b89 -[NSException raise] + 9
3 Foundation 0x000000010215fa6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x000000010305004c -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010327da71 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x0000000102a59a80 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010327c454 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x0000000103056c16 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000103057542 -[UIViewController loadView] + 178
10 UIKit 0x00000001030578a0 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x0000000103058013 -[UIViewController view] + 27
12 UIKit 0x0000000102f3151c -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000102f31c05 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000102f434a5 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000102ebd396 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000102ec39c3 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1750
17 UIKit 0x0000000102ec0ba3 -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000105870784 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000105870af2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x0000000102a45011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x0000000102a3af3c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x0000000102a3a3f3 __CFRunLoopRun + 867
23 CoreFoundation 0x0000000102a39e08 CFRunLoopRunSpecific + 488
24 UIKit 0x0000000102ec04f5 -[UIApplication _run] + 402
25 UIKit 0x0000000102ec530d UIApplicationMain + 171
26 project_feature_login 0x0000000102094a6f main + 111
27 libdyld.dylib 0x000000010523c92d start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
Seeking for Help!!!!
Try using self.passwordField.text instead of _passwordField.text while verifying your if condition. Also check the IBOutlet connection of passwordField in Interface Builder. Class set for that UIViewController in interface must be LoginPage

How to map local NSDictionary into a custom Object using RKMappingOperation?

RJobObject * jobObj = [RJobObject new];
RKMappingOperation *mappingOperation = [[RKMappingOperation alloc] initWithSourceObject:jobDictionary destinationObject:jobObj mapping:[RJobObject mapping]];
mappingOperation.dataSource = (id)jobObj;
[mappingOperation start];
jobDictionary structure:
NSDictionary *msg1 = #{
#"id" : #"dfcd",
#"message" : #"ndjfcdfcd"
};
NSDictionary *msg2 = #{
#"id" : #"fjvdfv",
#"message" : #"kjndcdovc"
};
NSDictionary *msg3 = #{
#"id" : #"fce",
#"message" : #"dfcdf"
};
NSArray *msgsArray = [NSArray arrayWithObjects:msg1, msg2,msg3, nil];
NSMutableDictionary * jobDictionary = [NSMutableDictionary dictionaryWithDictionary:#{#"id" : #"Sourabh pant",
#"title": #"http://www.google.com"
}];
[jobDictionary setObject:msgsArray forKey:#"messages"];
/......................................................./
RJobObject is the custom object:
#property (nonatomic) NSString * id;
#property (nonatomic) long long duration;
#property (nonatomic) NSString * title;
#property (nonatomic) NSString * image;
#property (nonatomic) NSString * secret;
#property (nonatomic) NSInteger unreadCount;
#property (nonatomic) NSArray * messages;
This creates a crash inside RRestkit, if the jobDictionary contains messages.If the messages array inside jobDictionary is empty,then the code runs fine.
So to sum up the message array is not being mapped.
Stack trace
2015-11-28 15:59:22.808 Checking Rest Kit[35951:3402596] -
[RJobObject mappingOperation:targetObjectForRepresentation:withMapping:inRelationship:]: unrecognized selector sent to instance 0x79f96270
2015-11-28 16:00:48.987 Checking Rest Kit[35951:3402596] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RJobObject mappingOperation:targetObjectForRepresentation:withMapping:inRelationship:]: unrecognized selector sent to instance 0x79f96270'
*** First throw call stack:
(
0 CoreFoundation 0x018e3a14 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x013a2e02 objc_exception_throw + 50
2 CoreFoundation 0x018ecd63 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0182a6bd ___forwarding___ + 1037
4 CoreFoundation 0x0182a28e _CF_forwarding_prep_0 + 14
5 Checking Rest Kit 0x00142f48 -[RKMappingOperation destinationObjectForMappingRepresentation:parentRepresentation:withMapping:inRelationship:] + 1704
6 Checking Rest Kit 0x00149885 __64-[RKMappingOperation mapOneToManyRelationshipWithValue:mapping:]_block_invoke + 149
7 CoreFoundation 0x018152e9 __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 73
8 CoreFoundation 0x01815182 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 162
9 CoreFoundation 0x017ff835 -[NSArray enumerateObjectsUsingBlock:] + 53
10 Checking Rest Kit 0x0014920b -[RKMappingOperation mapOneToManyRelationshipWithValue:mapping:] + 2763
11 Checking Rest Kit 0x0014b4fb -[RKMappingOperation applyRelationshipMappings] + 6283
12 Checking Rest Kit 0x0014d7db -[RKMappingOperation main] + 4075
13 Checking Rest Kit 0x0014c7dd -[RKMappingOperation start] + 45
14 Checking Rest Kit 0x000ab866 -[ViewController jobObjectFromJobDictionary:] + 310
15 Checking Rest Kit 0x000ab6d5 -[ViewController fetchJobFromDbForId:] + 85
16 Checking Rest Kit 0x000ab566 -[ViewController viewDidLoad] + 918
17 UIKit 0x01e3b2ae -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
18 UIKit 0x01e3fdce -[UIViewController loadViewIfRequired] + 1384
19 UIKit 0x01e401ed -[UIViewController view] + 35
20 UIKit 0x01cedf94 -[UIWindow addRootViewControllerViewIfPossible] + 69
21 UIKit 0x01cee6b1 -[UIWindow _setHidden:forced:] + 304
22 UIKit 0x01ceea67 -[UIWindow _orderFrontWithoutMakingKey] + 49
23 UIKit 0x01d02118 -[UIWindow makeKeyAndVisible] + 80
24 UIKit 0x01c6a6e7 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4190
25 UIKit 0x01c71cd6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1989
26 UIKit 0x01c96ee5 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3218 + 68
27 UIKit 0x01c6e966 -[UIApplication workspaceDidEndTransaction:] + 163
28 FrontBoardServices 0x04c4dc76 __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
29 FrontBoardServices 0x04c4d74d __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
30 FrontBoardServices 0x04c6b173 -[FBSSerialQueue _performNext] + 184
31 FrontBoardServices 0x04c6b5aa -[FBSSerialQueue _performNextFromRunLoopSource] + 52
32 FrontBoardServices 0x04c6a8a6 FBSSerialQueueRunLoopSourceHandler + 33
33 CoreFoundation 0x017fd6ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
34 CoreFoundation 0x017f338b __CFRunLoopDoSources0 + 523
35 CoreFoundation 0x017f27a8 __CFRunLoopRun + 1032
36 CoreFoundation 0x017f20e6 CFRunLoopRunSpecific + 470
37 CoreFoundation 0x017f1efb CFRunLoopRunInMode + 123
38 UIKit 0x01c6e206 -[UIApplication _run] + 540
39 UIKit 0x01c73bfa UIApplicationMain + 160
40 Checking Rest Kit 0x000af02a main + 138
41 libdyld.dylib 0x03911a21 start + 1
42 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
In Rconnection.m
- (id)destinationObjectForMappingRepresentation:(id)representation parentRepresentation:(id)parentRepresentation withMapping:(RKMapping *)mapping inRelationship:(RKRelationshipMapping *)relationshipMapping {
/* Some Code */
............
if (destinationObject == nil)
{
NSDictionary *dictionaryRepresentation = [representation isKindOfClass:[NSDictionary class]] ? representation : #{ [NSNull null] : representation };
RKMappingMetadata *parentMetadata = [RKMappingMetadata new];
parentMetadata.parentObject = self.destinationObject ?: [NSNull null];
NSArray *metadata = RKInsertInMetadataList(self.metadataList, parentMetadata, nil);
RKMappingSourceObject *sourceObject = [[RKMappingSourceObject alloc] initWithObject:dictionaryRepresentation parentObject:parentRepresentation rootObject:self.rootSourceObject metadata:metadata];
// Crashing Breakpoint below:
destinationObject = [dataSource mappingOperation:self targetObjectForRepresentation:(NSDictionary *)sourceObject withMapping:concreteMapping inRelationship:relationshipMapping];
}
.......
/* Some code */
}
#import <Foundation/Foundation.h>
#import <RestKit/RestKit.h>
#interface RJobObject : NSObject
#property (nonatomic) NSString * id;
#property (nonatomic) long long duration;
#property (nonatomic) NSString * title;
#property (nonatomic) NSString * image;
#property (nonatomic) NSString * secret;
#property (nonatomic) NSInteger unreadCount;
#property (nonatomic) NSArray * messages;
+(RKObjectMapping *)mapping;
#end
This line is incorrect:
mappingOperation.dataSource = (id)jobObj;
because you are giving the operation a plain data model object as a data source (and telling the compiler to like it by casting to id).
When the operation runs it needs some new instances to be created so it can map the content from the JSON dict into them, this is a job the data source is supposed to do. When the operation asks the data source you get a crash because the object you provided as the data source, jobObj, doesn't understand the request.
You need to create and set an appropriate data source that can handle this requirement.

Calling method is causing Error creating LLDB target

I am trying to make my first Objective-C library. I am creating a method which will take in a UIImage and return NSMutableData. I have created the following:
+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image
{
int maxWidth = 100;
BOOL drawerKick = YES;
BOOL compressionEnable = YES;
RasterDocument *rasterDoc = [[RasterDocument alloc] initWithDefaults:RasSpeed_Medium endOfPageBehaviour:RasPageEndMode_FeedAndFullCut endOfDocumentBahaviour:RasPageEndMode_FeedAndFullCut topMargin:RasTopMargin_Standard pageLength:0 leftMargin:0 rightMargin:0];
StarBitmap *starbitmap = [[StarBitmap alloc] initWithUIImage:image :maxWidth :false];
NSMutableData *commandsToPrint = [[NSMutableData alloc] init];
NSData *shortcommand = [rasterDoc BeginDocumentCommandData];
[commandsToPrint appendData:shortcommand];
shortcommand = [starbitmap getImageDataForPrinting:compressionEnable];
[commandsToPrint appendData:shortcommand];
shortcommand = [rasterDoc EndDocumentCommandData];
[commandsToPrint appendData:shortcommand];
if (drawerKick == YES) {
[commandsToPrint appendBytes:"\x07"
length:sizeof("\x07") - 1]; // KickCashDrawer
}
[starbitmap release];
[rasterDoc release];
return commandsToPrint;
}
Just for testing purposes, I am trying to call it from a button click event:
- (IBAction)DevButton_TouchUpInside:(id)sender {
UIImage *imageToPrint = [UIImage imageNamed:#"image1.png"];
// NSMutableData *commandsToPrint = [[NSMutableData alloc] init];
// *commandsToPrint=[self GetDataToSendToPrinter:imageToPrint];
//This is where I call it
NSMutableData *commandsToPrint = [self GetDataToSendToPrinter:imageToPrint];
int commandSize = (int)[commandsToPrint length];
unsigned char *dataToSentToPrinter = (unsigned char *)malloc(commandSize);
[commandsToPrint getBytes:dataToSentToPrinter];
NSString *portName = #"TCP:10.0.1.4";
NSString *portSettings = #"Standard";
NSMutableString *message;
SMPort *starPort = nil;
starPort = [SMPort getPort:portName :portSettings :10000];
[starPort writePort:dataToSentToPrinter :0 :commandSize];
}
However I keep getting the following crash when clicking on the button:
Warning: Error creating LLDB target at path '/Users/.../Library/Developer/Xcode/DerivedData/IOS_SDK-cjctcqoxudpegpadjbwitveqtkso/Build/Products/Debug-iphonesimulator/StarIO SDK.app'- using an empty LLDB target which can cause slow memory reads from remote devices.
2014-09-26 18:39:22.588 StarIO SDK[17823:513276] -[IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:]: unrecognized selector sent to instance 0xb366260
2014-09-26 18:39:22.624 StarIO SDK[17823:513276] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:]: unrecognized selector sent to instance 0xb366260'
*** First throw call stack:
(
0 CoreFoundation 0x021c4df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01c49a97 objc_exception_throw + 44
2 CoreFoundation 0x021cca75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x021159c7 ___forwarding___ + 1047
4 CoreFoundation 0x0211558e _CF_forwarding_prep_0 + 14
5 StarIO SDK 0x000428bb -[IOS_SDKViewControllerRasterMode DevButton_TouchUpInside:] + 107
6 libobjc.A.dylib 0x01c5f7cd -[NSObject performSelector:withObject:withObject:] + 84
7 UIKit 0x0042179d -[UIApplication sendAction:to:from:forEvent:] + 99
8 UIKit 0x0042172f -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
9 UIKit 0x00554a16 -[UIControl sendAction:to:forEvent:] + 69
10 UIKit 0x00554e33 -[UIControl _sendActionsForEvents:withEvent:] + 598
11 UIKit 0x0055409d -[UIControl touchesEnded:withEvent:] + 660
12 UIKit 0x00471aba -[UIWindow _sendTouchesForEvent:] + 874
13 UIKit 0x00472595 -[UIWindow sendEvent:] + 791
14 UIKit 0x00437aa9 -[UIApplication sendEvent:] + 242
15 UIKit 0x004478de _UIApplicationHandleEventFromQueueEvent + 20690
16 UIKit 0x0041c079 _UIApplicationHandleEventQueue + 2206
17 CoreFoundation 0x020e87bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x020de2cd __CFRunLoopDoSources0 + 253
19 CoreFoundation 0x020dd828 __CFRunLoopRun + 952
20 CoreFoundation 0x020dd1ab CFRunLoopRunSpecific + 443
21 CoreFoundation 0x020dcfdb CFRunLoopRunInMode + 123
22 GraphicsServices 0x03b8c24f GSEventRunModal + 192
23 GraphicsServices 0x03b8c08c GSEventRun + 104
24 UIKit 0x0041fe16 UIApplicationMain + 1526
25 StarIO SDK 0x000027e2 main + 130
26 libdyld.dylib 0x036f0ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I asume I am missing something really basic. It's the first Objective-C method I have created, I'm just looking at building a simple library I can then wrap in a Xamarin binding. Where am I going wrong?
You're calling a class method from an instance method.
+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image //Should be called using the class name
- (IBAction)DevButton_TouchUpInside:(id)sender //Should be called using self
I'm not sure how that compiled actually, you should've gotten an error like this:
No visible #interface for IOS_SDKViewControllerRasterMode declares the selector 'GetDataToSendToPrinter:'
Per the log it spit out, it's not finding the function GetDataToSendToPrinter:. Try calling it as a class method:
NSMutableData *commandsToPrint = [IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:imageToPrint];

Thread 1: signal SIGBRT [duplicate]

This question already has answers here:
setValue:forUndefinedKey: this class is not key value coding-compliant for the key [duplicate]
(20 answers)
Closed 8 years ago.
I'm receiving an error while running my xcode project. My app always work, so I can't really see why this isn't working any more. Does anyone have an idea? I've found that it's caused due to an invalid method I'm calling. I can't seem to figure out where this mistake is located.. Anyone?
The error I get:
2014-02-25 11:52:06.784 Chemie Xpert - PSE[1381:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x8d49be0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
*** First throw call stack:
(
0 CoreFoundation 0x023625e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44
2 CoreFoundation 0x023f26a1 -[NSException raise] + 17
3 Foundation 0x00f709ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x00edccfb _NSSetUsingKeyValueSetter + 88
5 Foundation 0x00edc253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x00f3e70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x002bfa15 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x014ce7d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x0235db6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x002be56e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x002c02fb -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 165
12 UIKit 0x0001d3bb -[UIApplication _loadMainNibFileNamed:bundle:] + 58
13 UIKit 0x0001d6e9 -[UIApplication _loadMainInterfaceFile] + 245
14 UIKit 0x0001c28f -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 543
15 UIKit 0x0003087c -[UIApplication handleEvent:withNewEvent:] + 3447
16 UIKit 0x00030de9 -[UIApplication sendEvent:] + 85
17 UIKit 0x0001e025 _UIApplicationHandleEvent + 736
18 GraphicsServices 0x022c02f6 _PurpleEventCallback + 776
19 GraphicsServices 0x022bfe01 PurpleEventCallback + 46
20 CoreFoundation 0x022ddd65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
21 CoreFoundation 0x022dda9b __CFRunLoopDoSource1 + 523
22 CoreFoundation 0x0230877c __CFRunLoopRun + 2156
23 CoreFoundation 0x02307ac3 CFRunLoopRunSpecific + 467
24 CoreFoundation 0x023078db CFRunLoopRunInMode + 123
25 UIKit 0x0001badd -[UIApplication _run] + 840
26 UIKit 0x0001dd3b UIApplicationMain + 1225
27 Chemie Xpert - PSE 0x0000247d main + 141
28 libdyld.dylib 0x0598d70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
My code:
main.m:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webview;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html" inDirectory:#"localHTML"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
webview.scalesPageToFit = YES;
webview.scrollView.bounces = NO;
webview.scrollView.minimumZoomScale = 1;
webview.scrollView.bouncesZoom = FALSE;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
#end
Maybe you deleted the UIView object from the NIB and replaced with the UIWebView.
This is fine, but you should link the webView to the "view" property of the viewController in the xib file.
Is the webview set as an IBOutlet? That could be the cause.

Resources