nsstring

Convert an NSURL to an NSString

半城伤御伤魂 提交于 2019-11-27 10:06:50
I have an app where the user can choose an image either from the built-in app images or from the iphone photo library. I use an object Occasion that has an NSString property to save the imagePath . Now in the case of the built-in app images I do get the file name as an NSString an save in the [occasion imagePath] . But in the 2nd case where the user picks an image form the photo library I get an NSURL which I want to convert to an NSString to be able to save it in [occasion imagePath ]. Is it possible to convert the NSURL to an NSString ? Randall In Objective-C: NSString *myString = myURL

How to convert from int to string in objective c: example code

ぃ、小莉子 提交于 2019-11-27 09:57:19
问题 I am trying to convert from an int to a string but I am having trouble. I followed the execution through the debugger and the string 'myT' gets the value of 'sum' but the 'if' statement does not work correctly if the 'sum' is 10,11,12. Should I not be using a primitive int type to store the number? Also, both methods I tried (see commented-out code) fail to follow the true path of the 'if' statement. Thanks! int x = [my1 intValue]; int y = [my2 intValue]; int sum = x+y; //myT = [NSString

Resulting lines of UILabel with UILineBreakModeWordWrap

随声附和 提交于 2019-11-27 09:48:16
问题 I have a UILabel whose size is calculated with sizeWithFont: method. The line break mode is set to UILineBreakModeWordWrap (same flag is used when calculating the size with sizeWithFont: )... Everything works great, label is properly sized and displays my text as required. Now I need to know the lines that are used to display the label (or the lines that are generated when sizeWithFont: is used). I could technically write my own implementation of line breaking based on spaces/caret returns,

iOS开发之如何在用户删除应用后保持一些数据

血红的双手。 提交于 2019-11-27 09:27:18
在开发过程中我们有时候在用户删除时候保存一些信息在用户下次安装应用时候使用,这个时候我们可以使用剪切版UIPasteboard的FindUIPasteboard和钥匙串keychain的使用 剪切版 剪切版主要分为以下两种 UIPasteboardNameGeneral和UIPasteboardNameFind 两种都是系统级的可以在应用删除后仍然保留数据 开发中我们常常使用UIPasteboard的Find UIPasteboard来保存一些用户删除应用后需要保留的数据如UUID,用户名,密码等 下面是一个保存uuid到UIPasteboard的代码 创建UDID + (NSString*) _uuidCreateNewUDID { NSString* _openUDID = nil; CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); CFStringRef cfstring = CFUUIDCreateString(kCFAllocatorDefault, uuid); const char *cStr = CFStringGetCStringPtr(cfstring, CFStringGetFastestEncoding(cfstring)); unsigned char result[16]; CC_MD5(cStr,

NSCocoaErrorDomain Code=256

匆匆过客 提交于 2019-11-27 09:13:15
I have been stuck with this for a while and don't seem to get around this. I am trying to read the contents of an URL as a string from an URL, But i get a weird Error -> Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" My code : fetchedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"www.example.com/iphone"] encoding:NSUTF8StringEncoding error:&error]; NSLog(@"%@",fetchedString); // if there is something wrong with the URL if (error) { NSLog(@"Error -> %@", error); return ; } What am I doing wrong? I tried using getting

How do I get word wrap information with the new iOS 7 APIs?

柔情痞子 提交于 2019-11-27 08:59:21
I noticed that iOS 7 introduces new classes related to text layout such as NSLayoutManager, NSTextStorage, and NSTextContainer. How can I use these in order to get information about word wrapping on an NSString? For example, say I have a long NSString which I put in a UILabel. If I enable multiple lines on the UILabel, it would produce a string such as the following: The quick brown fox jumps over the lazy dog. That's great, but I can't access the line breaks in code (e.g. after the word jumps I would want it to return \n or something similar). I would want to know at which character indexes

Convert NSString->NSDate?

有些话、适合烂在心里 提交于 2019-11-27 08:49:42
问题 I need to convert my NSString in the end to an NSDate but I am having problems doing so. How would I achieve the same functionality with this code while making the end result an NSDate? //Date and Format it NSDate *now = [NSDate date]; NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@"MM-dd-yyyy"]; NSString *dateString = [formatter stringFromDate:now]; Thanks! Edit: //Date and Format it NSDate *now = [NSDate date]; NSDateFormatter* formatter

NSString stringWithFormat swizzled to allow missing format numbered args

时间秒杀一切 提交于 2019-11-27 08:37:38
问题 Based on this SO question asked a few hours ago, I have decided to implement a swizzled method that will allow me to take a formatted NSString as the format arg into stringWithFormat , and have it not break when omitting one of the numbered arg references ( %1$@, %2$@ ) I have it working, but this is the first copy, and seeing as this method is going to be potentially called hundreds of thousands of times per app run, I need to bounce this off of some experts to see if this method has any red

How Can I Draw Image with Text Wrapping on iOS?

半城伤御伤魂 提交于 2019-11-27 08:22:15
I want to draw text just like the following style -- the image is always on the top right corner, and the text is around the image. Could anyone tell me how to implement this on iOS? Do I need to use Core Text? Thanks in advance! Yes, CoreText is the best way to do this. The code to do it is a little long to post here. Some code that may point you in the right direction is in the article "Clipping a CGRect to a CGPath." If the process for doing it is still confusing, ping me and I finally write the blog post I've been meaning to write on the subject. asetil Step 1 : Create an object inherited

Anyway to get string from variable name?

浪子不回头ぞ 提交于 2019-11-27 08:21:18
Say I have my class @interface Person : NSObject { NSString *name; } I need to get the name of NSString's within my class Person *person = [[Person alloc] init]; NSLog(@"Name of variable %s\n", _NameofVariable_(person->name)); Thanks for the answers, here's the solution I came up from the replies //returns nil if property is not found -(NSString *)propertyName:(id)property { unsigned int numIvars = 0; NSString *key=nil; Ivar * ivars = class_copyIvarList([self class], &numIvars); for(int i = 0; i < numIvars; i++) { Ivar thisIvar = ivars[i]; if ((object_getIvar(self, thisIvar) == property)) {