Advertisement
Guest User

Objective-C, how to parse file data

a guest
Apr 6th, 2013
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
  3. {
  4.     // Insert code here to read your document from the given data of the specified type.  If the given outError != NULL, ensure that you set *outError when returning NO.
  5.  
  6.     // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
  7.    
  8.     // For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.
  9.    
  10. //begin read code
  11.    
  12.         // copy the file data to a mutable data object with which we can work
  13.     NSMutableData *workableData;
  14.     workableData = [NSMutableData dataWithData:data];
  15.    
  16.         // see the "Archives and Serializations Programming Guide" and the NSCoding Protocol Reference and NSCoder Class Reference for the reason for all this:
  17.     HEKTagACTRcoder *ACTRdecoder = [[HEKTagACTRcoder alloc] init];
  18.     [workableData initWithCoder:ACTRdecoder];   // this sends a message to the NSMutableData (inherited from NSData) object "workableData" to initialize with our NSCoder subclass object "ACTRdecoder" the data according to its handling in the HEKTagACTRcoder subclass. So we have a coder object (ACTRdecoder) which is used to decode the data object (workableData) according to the decoder's class (HEKTagACTRcoder). The coder object (ACTRdecoder) tells the data object (workableData) how to encode and decode the data based upon the coder object class's (HEKTagACTRcoder) methods. It works like this: the initWithCoder: method, which is an NSCoding protocol we do not have to touch, takes in the data that is returned by the NSCoder object (ACTRdecoder), initializes it as an object, then returns that object id to its NSData (or NSMutableData) object. So here is what should happen: 1. The workableData uses its file data with initWithCoder:. 2. initWithCoder: sends the data via the NSCoding protocol to the ACTRdecoder NSCoder. 3. ACTRdecoder manhandles the data according to its defined NSCoder instance methods, which are uniquely designed for the type of data in workableData (the Halo ACTR tag metadata) by using its own versions of - (NSData *)decodeDataObject, for example. 4. The ACTRdecoder data is returned as a single NSData object which is now formatted for use, and 5. passed back to initWithCoder: which initializes that object and finally 5. returns that object's id to its NSMutableData object, workableData.
  19.        
  20.     return YES;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement