nsstring

NSUrl from NSString returns null

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to parse the location of my Documents Directory to NSUrl from NSString I have. when my console NSLog(stringURL) i get: "/var/mobile/Applications/2B35D06D-6E4A-40F2-833E-28463A946834/Library/Application Support/MyAppDirectory" as an output. but when I do NSURL* url = [NSURL URLWithString:stringUrl]; and NSLog(url) i get (null) as an output. WHat am I doing wrong here? 回答1: From the apple documentation "An NSURL object initialized with URLString. If the URL string was malformed or nil, returns nil." Your stringURL isn't a correct formed

NSString is empty

一世执手 提交于 2019-12-03 01:12:16
问题 How do you test if an NSString is empty? or all whitespace or nil? with a single method call? 回答1: You can try something like this: @implementation NSString (JRAdditions) + (BOOL)isStringEmpty:(NSString *)string { if([string length] == 0) { //string is empty or nil return YES; } if(![[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]) { //string is all whitespace return YES; } return NO; } @end Check out the NSString reference on ADC. 回答2: This

Retaining UITableViewCell selection statuses [resolved]

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've tried literally everything and anything I could think of. Can anyone figure out why the UITableViewCell s don't reload the checkmarks after selecting, scrolling away, then scrolling back? - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { #define CHECK_NULL_STRING(str) ([str isKindOfClass:[NSNull class]] || !str)?@"":str static NSString *CellIdentifier = @"inviteCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell

Wanted: Up-to-date example for JSON/POST with basic auth using AFNetworking-2

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a toy app which submits an https JSON/POST using basic auth security. I've been told I should consider using AFNetworking. I've been able to install AFNetwork-2 into my XCode project (ios7 target, XCode5) just fine. But none of the examples out there seem to be relevant to current versions of AFNetworking-2, but rather previous versions. The AFNetworking docs are pretty sparse, so I'm struggling how to put the pieces together. The non-AFNetworking code looks something like: NSURL *url = [NSURL URLWithString:@"https://xxx.yyy.zzz.aaa

drawInRect:withAttributes vs drawInRect:withFont:lineBreakMode:alignment

拜拜、爱过 提交于 2019-12-03 01:08:24
I'm working on a new version of my app and am attempting to replace deprecated messages, but am not able to get past this one. I can't figure out why drawInRect:withAttributes is not working. The code displays properly when drawInRect:withFont:lineBreakMode:alignment message is sent, but does not work when drawInRect:withAttributes is sent. I'm using the same rect and font and I what I believe is the same text style. The constants are just positioning the rect just below an image, but I'm using the same rect for both calls, so I'm certain the rectangle is correct. (note that bs.name used below

NSString no 'assign', 'retain', or 'copy' attribute is specified

匿名 (未验证) 提交于 2019-12-03 01:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm declaring an NSString property in a class and objective-c is complaining that: NSString no 'assign', 'retain', or 'copy' attribute is specified It then casually lets me know that "assign is used instead". Can someone explain to me the difference between assign , retain and copy in terms of normal C memory management functions? 回答1: I think it is drawing your attention to the fact that a assign is being used, as opposed to retain or copy . Since an NSString is an object, in a reference-counted environment (ie without Garbage Collection)

timeout stringwithcontentsofurl

倖福魔咒の 提交于 2019-12-03 01:05:06
I have this call to stringwithcontentsofurl: [NSString stringWithContentsOfURL:url usedEncoding:nil error:nil]; How can I give that a simple timeout? I don't want to use threads or operation queues (the content of the url is about 100 characters), I just don't want to wait too long when the connection is slow. In this case, you might be best off using the NSURLConnection class method +sendSynchronousRequest:returningResponse:error: ; it'll return a data object you can initialize your string with (using -initWithData:encoding: ). You can specify a timeout by creating an NSURLRequest using its

how to remove particular words from strings?

匿名 (未验证) 提交于 2019-12-03 01:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an NSString *str, having value @"I like Programming and gaming." I have to remove "I" "like" & "and" from my string so it should look like as "Programming gaming" How can I do this, any Idea? 回答1: NSString *newString = @"I like Programming and gaming."; NSString *newString1 = [newString stringByReplacingOccurrencesOfString:@"I" withString:@""]; NSString *newString12 = [newString1 stringByReplacingOccurrencesOfString:@"like" withString:@""]; NSString *final = [newString12 stringByReplacingOccurrencesOfString:@"and" withString:@""];

Modified EXIF data doesn't save properly

匿名 (未验证) 提交于 2019-12-03 00:59:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: After countless attempts and sieving through every SO answer + google result, it baffles me that working with EXIF on iOS is so frustrating. Below is working code with its results. [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) { NSData *imageNSData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; CGImageSourceRef imgSource = CGImageSourceCreateWithData((__bridge_retained CFDataRef)imageNSData,

How do I include superscripts in NSString?

匿名 (未验证) 提交于 2019-12-03 00:59:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there any way I can include a superscript with NSString? For example, I want to write square feet, like this: foot 2 . 回答1: In this particular case, there is in fact a single Unicode character that represents a small "2" written above the line. It is U+00B2 (Superscript Two). You should be able to do something like: NSString *aString = [NSString stringWithUTF8String:"foot\u00b2"]; 文章来源: How do I include superscripts in NSString?