What Is -[NSURL _fastCharacterContents]:?

梦想的初衷 提交于 2019-12-23 17:24:31

问题


So I'm calling this in a method:

-(id)initWithContentURL:(NSString *)url {
if (self = [super init]) {
    NSLog(@"xSheetMusicViewController - %@",url);
    // Casting an NSString object pointer to a CFStringRef:
    CFStringRef cfString = (CFStringRef)url;        
    CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);
    pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
    }
    return self;
}

Which crashes right at the NSLog at the line marked:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);

with this wonderful little error I've never seen before. Here's the crash log:

SheetMuse[83550:b603] -[NSURL _fastCharacterContents]: unrecognized selector sent to instance 0x4ec35f0
2011-09-22 17:36:22.921 SheetMuse[83550:b603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL _fastCharacterContents]: unrecognized selector sent to instance 0x4ec35f0'
*** Call stack at first throw:
(
0   CoreFoundation                      0x011be5a9 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x01312313 objc_exception_throw + 44
2   CoreFoundation                      0x011c00bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3   CoreFoundation                      0x0112f966 ___forwarding___ + 966
4   CoreFoundation                      0x0112f522 _CF_forwarding_prep_0 + 50
5   CoreFoundation                      0x010d2857 CFStringGetCharactersPtr + 135
6   CoreFoundation                      0x010d6c93 CFStringGetFileSystemRepresentation + 35
7   CoreFoundation                      0x01110811 _CFFindBundleResources + 289
8   CoreFoundation                      0x0110d961 CFBundleCopyResourceURL + 305
9   SheetMuse                           0x00005b19 -[xSheetMusicViewController initWithContentURL:] + 153
10  SheetMuse                           0x00009724 -[ExamplesViewController tableView:didSelectRowAtIndexPath:] + 708
11  UIKit                               0x00487b68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
12  UIKit                               0x0047db05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
13  Foundation                          0x00b9779e __NSFireDelayedPerform + 441
14  CoreFoundation                      0x0119f8c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
15  CoreFoundation                      0x011a0e74 __CFRunLoopDoTimer + 1220
16  CoreFoundation                      0x010fd2c9 __CFRunLoopRun + 1817
17  CoreFoundation                      0x010fc840 CFRunLoopRunSpecific + 208
18  CoreFoundation                      0x010fc761 CFRunLoopRunInMode + 97
19  GraphicsServices                    0x028a31c4 GSEventRunModal + 217
20  GraphicsServices                    0x028a3289 GSEventRun + 115
21  UIKit                               0x0041ec93 UIApplicationMain + 1160
22  SheetMuse                           0x000028a9 main + 121
23  SheetMuse                           0x00002825 start + 53
)
terminate called throwing an exceptionsharedlibrary apply-load-rules all

So, what is this error, and how do I fix it?

EDIT: This question has been solved. Thank you everyone who answered, I was banging my head on the wall trying to figure this out. If you would like, I can give you a mention in the app, seeing as I would like to release it in a few weeks, and your help has ironed out the biggest bug in the code. Again THANK YOU!


回答1:


-_fastCharacterContents: is a private method of NSString. The error you get indicates that the corresponding message was being sent to an NSURL instance, hence the crash. It looks like the url parameter that’s being passed to -initWithContentURL: is an NSURL, not an NSString.

Placing

NSLog(@"url is of type %@", [url class]);

at the beginning of the method should tell you the exact class of url.

I suggest you change your method signature to:

- (void)initWithContentPath:(NSString *)path

in order to make it clear that the method expects a string representing a (relative) path. There are other classes in Cocoa Touch that declare  -initWithContentURL: to receive an NSURL * argument.




回答2:


In most cases this sort of error is due to passing the wrong type of object on a call.




回答3:


How are you calling initWithContentURL? It looks like you might be passing an NSURL that has been (improperly) cast to an NSString.



来源:https://stackoverflow.com/questions/7522766/what-is-nsurl-fastcharactercontents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!