I want to ask something about the NSString in objective C. I use the following code to retrieve some of the HTML content.
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
In the data, it contains lot of HTML code e.g.
<!DOCTY... >
...
// retrieve the content from <form> to </form>
<form method="post" action="...">
<input type="..." name="name_1" value="value_1" />
<input type="..." name="name_2" value="value_2" />
</form>
...
</html>
I want to get the content of the name_1, value_1, name_2 and value_2 to and NSString, just like
NSString A = "name_1"
NSString B = "value_1"
NSString C = "name_2"
NSString D = "value_2"
Does the NSString provide this kind of search or method to retrieve the string? Thank you very much.
NSString can and does but it would be very messy.
If you are intent on parsing the NSString take a look a NSScanner, otherwise check out parsing using the NSXMLDocument
--Frank
Related
<a idref="_5AD480AC_7D6C_4AA6_B003_F1C5F38F4D15"
sectionid="n1e14b600d6dec639" internal="true" type="text"
slug="histologie/quergestreifte+muskulatur+histologie" link="" ui-
sref="main.learn.content({slug:
'histologie/quergestreifte+muskulatur+histologie', '#':
'_5AD480AC_7D6C_4AA6_B003_F1C5F38F4D15'})" webtrends-track-on-click="
{'WT.i_module': 'Textlink - Intern'}" >
ultrastrukturelle Aufbau der Myofilamente
</a>
I have above content as response. I just want to change that string to below.
How to get:
href="/lernmodule/histologie/quergestreifte+muskulatur+histologie#_5AD480AC_7D6C_4AA6_B003_F1C5F38F4D15"
from the above string?
If the format of your response is specific like you shown in your question then below code will work for you:
NSString *match = #"internal";
NSString *postTel;
NSString *preTel;
NSScanner *scanner = [NSScanner scannerWithString:str];
[scanner scanUpToString:match intoString:&preTel];
[scanner scanString:match intoString:nil];
postTel = [str substringToIndex:scanner.scanLocation];
NSString*requiredString=[[postTel substringFromIndex:3] stringByReplacingOccurrencesOfString:#"internal" withString:#""];
strContent=[strContent stringByReplacingOccurrencesOfString:#"', '#': '" withString:#"'#"];
strContent=[strContent stringByReplacingOccurrencesOfString:#"'})\" web" withString:#"\" web"];
strContent=[strContent stringByReplacingOccurrencesOfString:#"({slug: '" withString:#" \" href=\"/lernmodule/"];
strContent=[strContent stringByReplacingOccurrencesOfString:#"\"\"#" withString:#"#"];
I have a html page, My requirement is in my Objective C code I need to find a text for example in the below example I have "Color Change" in <p> tag, Once I find the text, I need to change the <p> tag color value, How can we achieve it.
> <!DOCTYPE html> <html> <body>
>
> <h1 style="color:blue;">This is a heading</h1> <p
> style="color:red;">Color Change</p>
>
> </body> </html>
if you are using local html file
then this code might be helpful for you..
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"html"];
NSString* text = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
NSLog(#"%#",htmlFile);
NSLog(#"Hello");
[self._webview loadHTMLString:[NSString stringWithFormat:#"<html><body bgcolor=\"#000000\" text=\"#FFFFFF\" face=\"Bookman Old Style, Book Antiqua, Garamond\" size=\"5\">%#</body></html>", text] baseURL: nil];
here in the below code color:#fff tag use for text color #fff use black color
NSString *webStr =#"Your text use";
[self._webview loadHTMLString:[NSString stringWithFormat:#"<div id ='foo' align='left' style='line-height:18px; float:left;width:300px; font-size:13px;font-family:helvetica;background-color:transparent; color:#fff;>%#<div>",webStr] baseURL:nil];
let me know , is this helpful or not for you
In the end, setTextColor: is the answer, there's an important detail missing from the earlier answers: To get this to work in iOS 8, I had to set the color =after= I set the text.
- (void)viewDidLoad
{
[super viewDidLoad];
_myTextView.textColor = [UIColor whiteColor];
_myTextView.text = #"hai hello hello..."
I'm trying to change the value of an element in a <input type="checkbox"> from null to checked.
How would I do this from objective-C (iOS application)?
Here's the relevant HTML of the page
<td align="right" width="15%" class="darkNeutral">
<input id="chk_Assignments" type="checkbox" class="ShowAll" />
<label for="chk_Assignments">Show All</label>
</td>
I was thinking I'd use POST or something, but I'm not sure how to access the element, add a checked attribute, and set the value of the attribute to "checked".
NSString *javaScript = #"document.getElementById('chk_Assignments').setAttribute('checked', 'checked');";
// Make the UIWebView method call
NSString *response = [webViewA stringByEvaluatingJavaScriptFromString:javaScript];
NSLog(#"javascript result: %#", response);
If HTML page got jQuery included, the javascript could be simplified:
NSString *javaScript = #"$('#chk_Assignments').attr('checked', 'checked');";
NSString *response = [webViewA stringByEvaluatingJavaScriptFromString:javaScript];
NSLog(#"javascript result: %#", response);
i need your help.
This is the first time i try to parse HTML and i am running through some problems. I followed Rays Tutorial about HTML parsing. He uses hpple. The file i want to parse is a lot more complicated than his. I want to excract some variables through the code below:
<div id="status">
<div id="loading" style="display:none">Error:<br />Connection to demo board was lost.</div>
<div id="display">
<span style="float:right;font-size:9px;font-weight:normal;padding-top:8px;text-indent:0px">(click to toggle)</span>
<p>LEDs:<br /><span class="leds">
<!-- <a id="led7" onclick="newAJAXCommand('leds.cgi?led=7');">•</a>
<a id="led6" onclick="newAJAXCommand('leds.cgi?led=6');">•</a>
<a id="led5" onclick="newAJAXCommand('leds.cgi?led=5');">•</a>
<a id="led4" onclick="newAJAXCommand('leds.cgi?led=4');">•</a>
<a id="led3" onclick="newAJAXCommand('leds.cgi?led=3');">•</a>
<a id="led2" onclick="newAJAXCommand('leds.cgi?led=2');">•</a> -->
<a id="led1" onclick="newAJAXCommand('leds.cgi?led=1');">•</a>
<!-- <a id="led0">•</a> -->
</span></p>
<p>Buttons:<br />
<!-- <span id="btn3">?</span>
<span id="btn2">?</span>
<span id="btn1">?</span> -->
<span id="btn0">?</span></p>
<p>Potentiometer: <span id="pot0" style="font-weight:normal">?</span></p>
<p>Temperature: <span id="temp0" style="font-weight:normal">?</span></p>
</div>
So far i can get LEDs, Buttons, Potentiometer and Temperature. I can not get their values . (the values of those specific 4 fields).
I am using the code below:
- (void)loadTutorials {
// 1
NSURL *tutorialsUrl = [NSURL URLWithString:#"http://192.168.0.112/"];
NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:tutorialsUrl];
// 2
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];
// 3
NSString *tutorialsXpathQueryString = #"//div[#id='display']/p";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];
// 4
NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in tutorialsNodes) {
// 5
Tutorial *tutorial = [[Tutorial alloc] init];
[newTutorials addObject:tutorial];
NSLog(#"Object=%#",element);
// 6
tutorial.title = [[element firstChild] content];
// 7
tutorial.url = [element objectForKey:#"???"]; //???
}
// 8
_objects = newTutorials;
[self.tableView reloadData];
}
I suspect that the problem is the objectForKey: But i am not sure. I tested all sort of keys i could imagine. Any help would be most welcome.
I have a simple web service (using a Cake PHP/MySQL back-end) that updates my text-based elements just fine. I'm looking to store an image (which the user would drop on top of an NSImageView) and am stumped. I thought the following example would worK:
- (void) updateApi {
NSLog(#"Updating user account settings");
NSString* request_url = #"/users/update";
NSLog(#"%#", [NSString stringWithFormat:#"%#%#", #"http://mysite.net", request_url]);
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#%#", #"http://mysite.net", request_url]]];
NSMutableString* post_values = [NSMutableString stringWithFormat:#"data[id]=%#", [[NSUserDefaults standardUserDefaults] objectForKey:#"user_id"]];
[post_values appendFormat:#"&data[company]=%#", [company_field stringValue]];
[post_values appendFormat:#"&data[phone]=%#", [phone_field stringValue]];
[post_values appendFormat:#"&data[address1]=%#", [address1_field stringValue]];
[post_values appendFormat:#"&data[address2]=%#", [address2_field stringValue]];
[post_values appendFormat:#"&data[city]=%#", [city_field stringValue]];
[post_values appendFormat:#"&data[state]=%#", [state_field stringValue]];
[post_values appendFormat:#"&data[zip]=%#", [zip_field stringValue]];
[post_values appendFormat:#"&data[website]=%#", [website_field stringValue]];
// Store logo as PNG and prepare to upload to server
//NSLog(#" *** This function does not save the user's logo");
NSImage *logoImage = [logo_image image];
if (logoImage) {
// Image exists; we need to convert it to a BLOB for our back-end database posting
NSLog(#"Image exists in logo_image");
// Grab possible representations of this image
NSArray *representations = [logoImage representations];
// Create the PNG data
NSData *imageData = [NSBitmapImageRep representationOfImageRepsInArray:representations usingType:NSPNGFileType properties:nil];
// Post the blob as a string
[post_values appendFormat:#"&data[logo_png_data]=%#", imageData];
}
NSString* encoded_post_values = [post_values stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData* request_data = [NSData dataWithBytes:[encoded_post_values UTF8String] length:[encoded_post_values length]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"content-type"];
[request setHTTPBody:request_data];
NSData* return_data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(#"%#", [[NSString alloc] initWithData:return_data encoding:NSUTF8StringEncoding]);
NSString* result = [[CJSONDeserializer deserializer] deserialize:return_data error:nil];
NSLog(#"%#", result);
}
My plan was to take the PNG representation of the NSImageView, store that in the data[logo_png_data] parameter, and then post that to the web service.
The other values work just fine, but if I try to decode that image data (which is stored in a mediumblob column in my MySQL table) it fails miserably. I'm retrieving the data as such:
Note - account_settings is an NSDictionary property that contains the returned parameters from web service
[website_field setStringValue:[account_settings objectForKey:#"website"]];
[zip_field setStringValue:[account_settings objectForKey:#"zip"]];
// Create logo from image data
NSData *imageData = [account_settings objectForKey:#"logo_png_data"];
if (imageData) {
// Some data is present
NSLog(#"Image data exists\n\n%#\n\n", imageData);
// This fails
NSImage *theImage = [[NSImage alloc] initWithData:imageData];
if (theImage) {
NSLog(#"Image has been created successfully");
}
}
In the above example, I end up with an _NSCFString for *imageData:
<89504e47 0d0a1a0a 0000000d 49484452 000000aa 0000003d 08060000 003d15f2 79000016 61494441 547801ed 9d7b705c d57dc7ef ae56d6c3 b2bc580e 010c5805 02e1e1a0 8686649a 042f0909 4d7989cc 641adaa4 883f324d f3420d9d f228416b da264d21 1991191e 75d2783d 1920edf0 1001d2d2 34f5aa76 28306d11 0486406c 5839050c 46b6906c 4b96b4bb fd7ccf3d 677557da 95ee4a7e 31bd3ff8 ed39f79c dff99ddf fd9deffe cee3de95 63c562d1 ab46975e dad94add e5f0bffd e4277daf 56938bca 230f1c6c 0fc4e602 aa3a07ac 3f223917 fe399c01 b04f9146 1479e090 7a200c50 5761d143 f0326b99 807a5d14 61ad37a2 e4907820 3e5f2f16 901b0372 8aae0f11 69af0c94 95b237af bbf9e29b 6ffeab13 4b055126 f2c001f0 c0bc40b5 7d08a8a3 81fe145d 6f00ac77 d8756ca9 aa502878 c542e171 c0faa552 6194893c b0480fcc 3bf53bfd 975d76f9 57c97f25 168bb922 cfe67f45 c1e71f7c f0fe1157 d17353cf ffc6e2f1 d6782cf6 28425fbc e9a66fbc edeaa234 f2c0423c 6022ea93 4ffdd777 7ef1f813 d7f46fde 72c9bf6f ea776bd1 327d7575 751b61af 02bf97b2 1f7de633 7fa01302 4344d547 1459e18b 88ae3f25 ba2e7775 511a7960 211e3040 1d1d1dbd 07be6274 64b46764 6474d37d f7f77de7 c7ff745f 2aa8f081 07ee1b49 24ea1e74 40255f02 2d7903d6 cf7ef60f 0d583949 d85cc8e7 0554f11a f8a7ac5d 23b0061d 1ae56bf2 8001ea05 1f3fffbf 474647bf 0b7b6240 bb16c0de 7ae7dfff e0e1dbef 5c9f721a ebea120f 38a0922f 01d5e605 562d0fbc 3c1155c7 5e16a80e ac77393d 511a79a0 560f94ad 51ef5aff 0feb01d7 fb05b219 fc3f5ca7 bbbff6e5 d73ef7b9 3fdec432 f538cff3 d7aafe92 b52cfff9 8d1b373c 75fd75d7 3fcf1af6 04ad63c5 f1785ce9 b7d6ddbc ee5bb51a 19c9471e 28dbf54f 4d4ea6f3 53537bf2 4cdb33f8 fd5cdf73 eb776f4b 11359f9c 8eaad3d3 7fa0ecdb 722b801f 3411d582 de46d7eb 6fbaa9e7 a391db23 0fd4ea81 32a07ee5 cb5f7c6d 0a400256 cf709eb4 c4f916c0 7aebb1c7 ae2a5498 f6ed32c0 2c078efb c217fee4 d30073b3 05677009 e0b176fd db5a8d8c e4230f94 0155ee00 8cf702d6 d74d449d 22b23ab6 806d696d b9b46559 eb5245d0 191baad2 9a95f2af 96403abd a9f20a7e 745d73e3 5fdef847 91eb230f d4e28159 40fdf3af 5f3d0a48 d71ba006 970016b0 0070bc75 796bdb52 2830dd97 406acb8e 9b9c9a1a 77ebdc12 68fd5300 45d8e861 402da314 c97ab380 2a9f5cf7 17d73c4c 54dd03cf 5cab9a08 5bc817bc c6a6a615 f5f54b12 d391d53f 05f0a36c 828d53fc 9cc01195 3ffd4f47 d735d75f 7fc3fb22 ff471e08 eb8144cf babf3e09 e133e121 584f9086 d6f5dcb8 83b56996 8878b1a2 a2a7ff03 27018a90 5cc69634 34b64d4e ec7fa3c2 ce1f35c5 33f29393 e66cc0ed fa293480 3527019e 771197cf aa2ca2c8 03f379c0 1c4fa56f fe9b0f20 788c8405 22689227 4ac57c21 ff4d00aa b3aa0050 0dd8ce9c 066e7e88 cabd3aae f29b1a2d 7c1457ec 1f1f6f54 c600954a 1eab1afd 06a8b1d8 965b6ebd e5f7251d 51e481f9 3c909000 c0d199a7 01aabdae e7e0d3cb 4fe4eb8b 85a2a6ff 09f0e6c0 5ae7406a 019c4c24 1200557a cca73ea0 22cb8a58 bcc0fc2f 60aa52d5 caeb4c15 1d1f3162 d147e481 101e306b d49e6fdc b00f00fd 261e2f1d cc1b3001 ab6d20ab 8948d832 35958fc1 02edd2b2 cd51b158 473fcdc1 1300ad5b 7921a5a9 8e15acbf 4ce02915 51b9d48e b5aac07e cdd7af89 5e070c31 48918837 bd9902a8 2fb1012a 453c1305 bde2ab2c 01f05311 ecd5b500 b4583e5f 58aacd94 e1a27996 efb1e96a 12381d03 da38e06e 500435e0 9cde444d 83d53f01 581d0d42 e481301e 28edfa6f bce15a45 d531fba8 5311d1b4 2f004645 3fcdd800 b005e835 4f47461f b0fbf7ef 6ff641ea effcd1d3 a26b22f2 4c601a5d bc0b502a 0f636424 1379a004 54b90290 bea548aa 2580363e ccd70658 8aaa9aba 89b88d3c 956a6693 4579e9ed 28455796 0553d499 8700d2b9 221eaf13 b8f51275 09942eba 0af80eec d110441e 08e301b3 99728244 d131832e 0a0cc848 d9faeb74 4a39ca62 cb0446e4 625379a0 0be040ac 01f3e4e4 647d73f3 d271364f 49008f5e 1b9101aa 40cfae4a db7fa358 35fe17a2 ec7b627a 893e220f 54f24019 504d1445 4a201211 399b34f5 5ba42640 68b3c059 bf64496c 62efde32 a0729a15 afab8b27 0af9a964 9d8da6fb f6ed6396 07a85286 4ee92d28 35977c16 8b83aa8a 28f2c07c 1e28076a 2c96f031 ea838917 53569929 1f7002e2 e5c56221 26d0aa96 dd526c32 3f59022b 80246816 de4d3465 47a64d99 796f8099 df07aaa2 a9d6bdc1 e87ad7f7 d76f9fcf c0a83ef2 803c5006 54d6a6bc 850f9814 f2485977 9eac080a 36799fdf 5baabcaa b4146063 15dbbf5f 8ff375e5 79fbc6c6 5a8998f5 3196068a 9c1c6315 f7eddd5b 0802538a 7dd5ea23 b6c5348c 3e220f84 f0403950 63f1568b 246ff7ae 217e4222 9016bdba 78bccd00 d280566b d2985797 48980d91 604b711d bba604c1 d48fb7a0 71746484 605a79da b7d1f591 10f64522 91078c07 4a40edfd deedcd44 bf7a952a a2b2be3c 8b8d9122 5f23586c d012c02d 567d7016 cd430122 a7cea1ea 9b9a9a8b 66d607e9 6acfcf59 fcf5a9da 6935a068 5abea98a 802a671f 21c4f8b4 638ad810 81296bb3 474452da 7603b263 0426ad23 2727a79a 26f6ef5f a328ca35 6b53454d 73f08fd1 fe542fb9 447dbd40 6ad6b5f5 f5ee3754 ecf099fe dfd8b163 4ae0565b 45d620b3 70ddb261 63e6a0ae 4fb9972c acf70c52 07dad3d2 6975679d ee4059da 95bd1352 ecee8073 d8fa0abc c9b1ee87 7c6842fe a0f95b46 94222ac0 6b73d3fe aea1a135 84c34662 e0124261 83048989 4a20523f 4b808cd7 61a0b96a 6c6c2470 fa67a743 6fbd959f 9898282a 82d29eff 2d035a1b 5deff675 459f87d3 038c4b07 fd6761fd 42b8dfe6 490c0dbb cc919096 80ca26fe 18e06440 b867cfe8 79328e67 f5cb5c99 8f4d0a4d 86cd3fcf f8610556 43cdcdcd 3c67f503 f4f6c1c1 49b33e9d 06a63fed 2349f92f effdc71f 4740f5dd 76b83fd3 1820906e 642cbb48 8f583240 bde3aeef 33edfb47 4a7b46f7 ace085a7 e3f8b6c5 d944352b 22562045 d2b85e8c 1672f510 a0a5a5c5 2c1b76ed da957f8b 88aaf5aa c8005611 55177e64 bd4ed988 8e080fa4 ac15e923 c29a398c 3040252c 1ee300b9 7bf7ae35 ca73682f 90daf889 06073672 8aa4be4e 1fc4adcb 96157951 cac8bcf8 e28b269a ea284053 bf5418f6 a3eb9df7 3d70ffe6 39ec89aa 0ead07cc 1f05613c 7387b6db da7b3340 05502b1d 22f7eedd 7b9ef284 d3a6d2bc eec74380 4885d95f f905fa85 aa40d8b6 b2cd6ca0 dedab933 ffe61b6f 547bfff4 97b4fe66 ed26462d de091e00 eca98369 6762fd0f 7ed80c20 9b04bd3d 23a32be8 f028454f 22aa2953 e70ec4ca b21d52e8 343fa776 86b5b5ad 344753cf 3ff79c89 a69af675 4610d339 2aba88ae 237c19fe f481be07 a33f96e6 9c16a535 794087f4 6d7e8b98 b74bd33e 4459239b ab3245ba 1248ed33 54fdd91e 03c2152b 8e2a3634 2cf18677 ef2ebcfe faeb7e34 9d31ed23 78ed238f 3e12fd3e aacca3d1 452d1ee0 0c34dee6 22e6d8be b1b3b4ed 6173d4a8 40e893dd 08298cea 9194a9e0 f12a3fdc 13bd6be5 4a3db9f2 5e78e105 fdceaad2 1b52773e f22fff5c f32e9f48 9c42bd38 48392eb2 07634d75 30fb4377 12bb53b0 8e838234 c085eea7 e6a3a02a f64ab774 0e1c0c1f 49f96209 bbe50371 fb0c5d39 ae65b7ec 9f4509a6 7d364d42 2107fd53 93270b88 00afde87 a745ab12 d6a64688 ac2e2727 270c668f 3efae822 4fb18abf 7ae18529 ad6931c4 2b6813e5 47dc2d8f fdec5faf 9dd56b95 023ba0dd 548bcd42 bf922872 fd94a7b9 a96ca5fa b06535f6 d75dcd89 d5fab3fa 7ba9bfb2 9a0ce56f 239721d5 fd0ccf21 27df26a9 976fc455 fd231dc8 ca476536 53c6a438 9b2a94f7 634b6ab6 64f51274 64a95d0b 9f5f695c a8efa22e 0daf86ab 12728354 ca1799a0 508229be 55a0dcb1 e3f55310 32759481 39f2f65a 853c63e2 caafe7dd 534f9bf8 952b5716 97343478 cf3efbec 948ea14a 6f48218f 8211aeaf 300a437c d05f0762 7db0bb91 8df67a38 d0bc937c 172c876c a2cd6ddc 5037f99a a94a7f59 14e502ca 3ac877c1 eaef69da aca3bf34 f97909d9 14427db0 003508f7 c203b0a3 24994ef8 4af86a38 a536e81f 263f8b2a d8ab7f57 a10fce05 84dbc9a7 60e97436 5f1518f4 7eca8324 19d1ccf2 01bf78f1 9fd89d44 8bec747d 3d63afb3 a441eae0 a20b3e1b de607da1 6b434454 9eefc73c 8f697f15 89219e30 99a751ee 9a7a2d4d e3aa1476 f353fc5e 9f94686a a67d6da2 664efb08 5cb1e93f fa436d9e ec206451 af41d58d 74e2dc1c e94cca22 9ba6b01b ee81af96 2390ed22 1f9a66f4 d74fc3ae 6afd51d7 8b7c2769 06ee214f 629ee628 ad4856ff 262a75ff 41a0cc94 ef43b697 c20cac01 ea835370 192193a4 2003af86 e51fd93b 405a8932 c8a7a990 2ee994fd 59dd1f9c e2ba4494 177531b3 bc247060 3269d4ac 85e50b8d 6b96b412 65290cfa fa4aec93 cd69092b 76ea839f 9a141a0d fa143719 0beda510 f4d96495 1756e3de c484d6a7 316f65db 8ae2d0d0 50617878 d8bc772a b0eaf93e d1f51e40 ba591d84 a40c7202 e94318d6 01e7c857 24ea86ad f1575901 dd506745 e10a85c8 6ad03588 ea6f23ba 5273f527 15d44b3e 05cbd93d 364f5291 9c7ec94a 77a6a294 2da47e80 6c172cf9 b5d89722 9d49dd14 08744ea7 da54257b 3f290424 affbec84 0f39595f 5f6d3b96 2fb2f319 814c1f32 5d564e81 21a93caf a0b29e04 95bc7bba 42b1c2e7 e99c2df1 d14bb140 acbff4d7 d4d4545c cad3a8ad 5bb7f243 80c0efa7 0a851100 5bcbba34 4db71a84 41b80b0e 45dc5006 c17556b8 3754235f a89bc445 26e54311 fd0d20d8 6985e76a 2719e9ef b26d6c93 ea8995cb 5889ae0a 92aeac1b d9e10af5 b38aac9c b353361d 0eeab09d f687f585 e491ed23 e9b76d8d ed9c44f9 1195d7f5 561814ba 286a012c 10ab1c64 6bddc986 6bca5cb7 b5ad302f a1e472b9 3c8a836f 477d73cb 7f3eae6f 7258eab6 821ad8e1 b08d2487 7c9a4400 5f8d7d5d a461c8f5 177ad09d 52facb92 df082b4a 55238154 03d3574d a04a79c6 967704eb 6d4491ce b7d1e964 822273e5 7373551e c2baec02 fa72fe33 fe007b7e 446d6868 7815489a 88ea03d6 cfdb32c1 d590ff7c 9f915abe dcac4f5f deb6cdbc 77aacd14 fc9b279e 7af20e2b 3a6f62c1 a541d7c0 66e76d50 59a0d716 7756ae9e 2ea53fc9 a8bfc103 d0dfb4e2 d93967d3 ec9a2a25 d83360ab 34bb04a9 c35eb8fa 60dd3b25 dfb90043 ddfd9afb d71a7548 9192b353 ff17a8e4 a1bcca18 d8598c43 4dd951c9 6471fbf6 ede5d37e b1787b8d 06a5ac7c a6c67641 f13e7b71 59b0b04a 3e65cb33 55eae72d b6801a9c 4b101967 d35c6261 eb3460e7 c3dd611b 1c417239 6bcbd960 29558b5d f8300bc7 60d34e6b d4b7f5f2 081175b7 206a590f f16781d4 00573208 697daa6b 1405a7fd bb6b3106 d994955f f0c0d27f 0e1d83d2 833ded4a e7a00e5b 979d4326 4cd55cf6 f6875150 45e69999 e5dc9f36 8f1ab481 997521ae bb43c81c 34113b36 1b6d073a e1e85a68 675aa312 51e39c89 be6bab41 20e0632e df2f10ea daa56579 e0bc6cd9 322ff7ca 2b7aa4ef c0fae8d3 cf0cd4b2 365553ad bd340d0f eb621194 b36ddbe7 d1e1ea17 32e841d5 b9e0c501 cc2fca0f 8c55079c 82d3b06c 0c33cb1c 40f32baa d297455f 402db936 c82e6b5f 8aebd0a4 47a843e0 6e92cdd1 ae86250d db2626f6 9fcc5ff0 9b303835 6ad84481 45fe03b5 e6984098 35eb53b3 d19aeeaa a6df4061 6c876d9a 249f9d56 b3a09cd3 355f637d 31f4c55a 14205031 304747d9 39ea165d 85af5228 11eb9e93 9667ae6b 2936d4cf e75a9b3f 2c897c6d 6deec600 b1c6a047 4c3989d9 dd0f908a 3573e448 6751e2d3 975f3ad9 f7d0c33b 40df09c7 1e7bcc63 83dbb77f 8985e7b8 41a5af48 f8d4537e 43fc9569 52d6b4fc 805a9138 409b03f9 30d9a415 d237edb0 3a338cb1 875b8641 d5208b35 d0411218 c5c3f080 adc8da7c 07e9265b 76d8121b 1814e57b 31a2134e 59d6bd68 ecc58690 19249381 7b8301c5 bd8ffa12 383ce6c4 d5ed5bdf dcb9f3b9 f1f1f1b3 38aeda9b a84f2cb5 ad598816 854f4f3f e2137e47 de1e2125 63e9d9e7 9fdbeef2 35a6daf1 a76a6cf3 ff4a1c3f f771c36e 1a7f88bc aeab461f e79ce0f8 b8b2c399 5ae065b0 412cfc24 493ae094 65017635 dc037753 af23c40c 79cdea78 e0928bf8 4b7ef197 74a67ad6 596beee5 0460370f 00f62aaa dafff84b 3cfca293 2bfd59a9 44a2de1b 1b1f8b9d f6ded34c 7b546c91 9e1a2967 e565eca1 22b386b6 0e5a4c9f ed8b695c 4b5b6ced 455e2095 edbfcdc0 756af0e0 1cd7ef68 e21edc46 314d3ec5 cd1c055f 050fc29a 69b5a6ed 24f581aa cc25177f ea65c0ba 6369cbd2 b1534e39 e5873c0a 1de65cd4 6caacc4f 4af8e312 34e22996 a713026f e79b3b67 4efd5213 9a028e3e 3b74a3c5 0b0e5815 1d8b54b5 d8f6a1ba b75fa8ab ad700a9f 39fb43b5 7fa70959 e066b05b fed5cc21 ead5878b 88caeb79 ea00ebce 91e356ad 7af5d453 4fbd9db7 a45e33e0 545d2c66 5e8a5654 e55feef1 de78f34d efb4d34f af330d17 fef18c9a d2476ae1 2a4cfb2c 3ab22174 b8815e54 7ff4b3d8 f6214c35 22ae1fbd 03e16c0f db5672ed b5081f48 59c64327 101a1703 b45a740b b0c877c1 9a45564b 5719503f f57b9f9c 04ac8f03 caa155c7 1fffea29 ef794f2f cb805710 1498f4db 682d0198 fa13fc25 95b1d8f8 d83e6f75 7b7b990e 14d74259 2bdc594b a3a0ac6e 826bad6d da83e555 f203b6bc ab4afdbc c5f4d78e d0a19a05 746f2267 b77f15fe 33155ef4 804be6d0 a8717133 424d1d58 b0bafb4e ce02d985 9fbc6012 16585f5e 45643dfd 8c336e4a 26938302 284b803c bde9d194 89aa5bb7 bd1c3be3 8c4545d5 8cb5be0b fdc99aee 645ab8db 66fba68b aae624e3 bea5a9aa 527357a4 e7ae3e32 6aad3f3b 0f973516 68f2b582 5c6a8176 e45cbb59 4075159f b8e063cf f334e071 7eafbf8b 29fe9ad5 edab9fa3 47fd1154 b304e01f 44f37efd ebadb1df fdf087cd c9816b57 4b6aa7b3 7eda2c87 d3b5b495 2c0ee820 b9d2b6eb b569d5c4 3a4f6015 656afd72 04fa3303 e0ab39a8 9f39ab5d f7592ba5 6920bf2e 8ab8e72e 382b5e80 22e7ebf4 02daaa49 e9beab02 55521fff 586a08b0 f6135d5f 3af6b855 e90f7df0 83f72e5f de3ac65f 9fe05d00 8f57fd1a bde1b747 ea7881fa a3925f20 75db767a 09ba2bac 0e6493c8 3a47dc06 087321db aa3f1355 497b43b6 d19722d8 5fe87661 f557911b b0e597d1 7f471599 59c5d68f 9a721504 164bed28 d0142eae 95d2b6c1 5a6b53e8 f6c87722 7c36acb7 c6b27302 555acf4f 9d3709bf 08587f4e 34ed3df7 03e77eed 94534fdd b66449c3 14ff729f f7f22bb9 d8272ebc 70c9fbce 3ceb44c9 d74a36aa 5e65db6d c0c0f47c 3a904921 a3415c0d 3f03a7e1 5064a36a 9715be12 5d7d7072 aec6d40b 24aebf3f 239f9d4b fe40d559 df38b069 06689f4f 37326964 36c041bf c8fe434e d89fa3d3 75b6e350 632b59ee a19324a3 3c94d6c7 bc409590 68ed791f d9070f8c 8d8fdf7d f4d1efbe f49cdf39 a7e784e3 8fdfb5b4 b9893f86 5657ff5b 279df421 5fb2f64f 6e28432b 07d61e0c cdc13af0 4d396de4 b58bec82 b3946d82 1d48756c 33ece4c2 a4c8f721 e7fabb8c bcfaeb85 5370523a 48dbe14e 38c3e5d3 b0fa5b47 db5ed243 49dd74a6 1940d165 007b66da 99a44c76 ab3c874c 0f2c90ca 2f5952b5 5d4e5d16 cec05d5c 1f32c286 349ddd66 3bac36b6 ee1ebab1 6f00d907 e1e5f0c6 92bfc978 0be55f3c fe44eb63 8ffdec96 dedeef8d 7cfbef6e d9bc503d ae1d8675 c059b838 0f0f539f 76ed2aa5 d467ad0e 0d58c57b a43e6c7f 725e498f f2b06ccc 3add81b2 b42bab35 953e9866 e5f652d6 0e67e1f9 fc924346 4f73a4c4 30d75db0 fce5da96 ec73654e b6528a4c 3aa45cd6 caa5aae8 4951ef64 9c2dd552 c995e989 49e99146 7cabdab1 a913562a 30897296 b3d89c25 3f27a143 ed92f000 f2c37309 cfd35f1f ed0782ed 9197de0e 584f564c 5da02c47 592e281f 36ef6ca6 7db6529b 2a760e23 2b1be6f4 8bd52d7b 734e3765 29e5abf5 a73adb67 bbf2f3c8 c91f4978 4e7f5b3b 52c8b5c3 6a231a86 07e01cac fb505a46 ff076a1e c88d0fb2 75330000 00004945 4e44ae42 6082>
This throws an error when trying to create the image, but the app continues on seemingly unaffected (aside from not displaying my image):
2011-12-21 21:17:43.440 Workshop Manager[7104:707] -[__NSCFString getBytes:length:]: unrecognized selector sent to instance 0x101017000
2011-12-21 21:17:43.442 Workshop Manager[7104:707] -[__NSCFString getBytes:length:]: unrecognized selector sent to instance 0x101017000
2011-12-21 21:17:43.444 Workshop Manager[7104:707] (
0 CoreFoundation 0x00007fff8ecdf286 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff9407bd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8ed6b4ce -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8eccc133 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8eccbf48 _CF_forwarding_prep_0 + 232
5 AppKit 0x00007fff8dcf7e48 +[NSEPSImageRep canInitWithData:] + 66
6 AppKit 0x00007fff8dd63d92 +[NSImageRep imageRepClassForData:] + 186
7 AppKit 0x00007fff8dd5e760 -[NSImage initWithData:] + 43
Any idea what I'm missing here?
You can't just print NSData to a string and expect to be able to recreate it from the string. Printing the NSData using a string formatting specifier just calls -description on the data object, which although it prints the data in hex is not a reliable way to encode an NSData object. You need to encode the data in a format that can be safely represented as a string and then converted back to data without error.
There are several ways to do this but one of the most common is to use Base64 encoding. You can use the OpenSSL library to do this, and Matt Gallagher has some excellent example code on his page about Base64 and NSData. The actual code for his example is here.
The stack trace and the exception are telling you that imageData is an NSString not an NSData.
Also [NSString stringWithFormat:#"%#", imageData] isn't a proper conversion from NSData to an NSString. You're probably looking for -[NSString initWithData:encoding:] instead.