nsstring

Check if an NSString is just made out of spaces

浪子不回头ぞ 提交于 2019-11-28 20:03:30
I want to check if a particular string is just made up of spaces. It could be any number of spaces, including zero. What is the best way to determine that? Alexsander Akers NSString *str = @" "; NSCharacterSet *set = [NSCharacterSet whitespaceCharacterSet]; if ([[str stringByTrimmingCharactersInSet: set] length] == 0) { // String contains only whitespace. } Try stripping it of spaces and comparing it to @"": NSString *probablyEmpty = [myString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; BOOL wereOnlySpaces = [probablyEmpty isEqualToString:@""]; It's significantly

ios 内购 恢复内购

陌路散爱 提交于 2019-11-28 19:52:33
申请内购部分略。。。。。。。 代码部分 1 //准备工作 [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; <SKPaymentTransactionObserver,SKProductsRequestDelegate> //遵循代理 打开支付开关 如下图: 2 //商品查询 msg 是商品编号 if ([SKPaymentQueue canMakePayments]) { NSLog(@"用户允许内购"); NSArray *product = [[NSArray alloc] initWithObjects:msg,nil]; NSSet *nsset = [NSSet setWithArray:product]; //初始化请求 SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset]; request.delegate = self; //开始请求 [request start]; } else { NSLog(@"用户不允许内购"); } 3//请求到商品信息 然后在里面验证 在发起支付 #pragma mark - SKProductsRequestDelegate -

Is a literal NSString autoreleased or does it need to be released?

允我心安 提交于 2019-11-28 19:26:24
When creating a string using the following notation: NSString *foo = @"Bar"; Does one need to release foo ? Or is foo autoreleased in this case? Compiler allocated strings (of the format @"STRING") are constant, and so -retain, -release, and -autorelease messages to them are ignored. You don't have to release or autorelease foo in this case (but it won't hurt). As mentioned in the docs http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or

Converting int into NSString [duplicate]

我们两清 提交于 2019-11-28 19:11:26
This question already has an answer here: How can I convert an int to an NSString? 4 answers I want to convert a random int number in the NSString and then assign the NSString to another NSString but it crashes the app I am doing the following int mynumber =(arc4random() % 1000 ); unique = [NSString stringWithFormat:@"%d",mynumber]; NSLog(unique) NSString*test=unique; it gives crash when i write last line; It also prints values when I nslog the unique string. Tendulkar If you want to change the int to string NSString *strFromInt = [NSString stringWithFormat:@"%d",yourintvalue]; This also works

AES256 NSString Encryption in iOS

依然范特西╮ 提交于 2019-11-28 18:53:54
My app encrypts and decrypts (or it should) an NSString (the text to be encrypted / decrypted) with another NSString (the keyword) using aes 256-Bit Encryption. When I run my project and run the encrypt method, nothing gets encrypted the textfield just clears itself. Here is the code I have: -(void)EncryptText { //Declare Keyword and Text NSString *plainText = DataBox.text; NSString *keyword = Keyword.text; //Convert NSString to NSData NSData *plainData = [plainText dataUsingEncoding:NSUTF8StringEncoding]; //Encrypt the Data NSData *encryptedData = [plainData AESEncryptWithPassphrase:keyword];

Get last path part from NSString

我怕爱的太早我们不能终老 提交于 2019-11-28 18:39:47
Hi all i want extract the last part from string which is a four digit number '03276' i:e http://www.abc.com/news/read/welcome-new-gig/03276 how can i do that. You can also use NSString *sub = [@"http://www.abc.com/news/read/welcome-new-gig/03276" lastPathComponent]; If you know how many characters you need, you can do something like this: NSString *string = @"http://www.abc.com/news/read/welcome-new-gig/03276"; NSString *subString = [string substringFromIndex:[string length] - 5]; If you just know that it's the part after the last slash, you can do this: NSString *string = @"http://www.abc.com

How to capture last 4 characters from NSString

你。 提交于 2019-11-28 18:12:36
I am accepting an NSString of random size from a UITextField and passing it over to a method that I am creating that will capture only the last 4 characters entered in the string . I have looked through NSString Class Reference library and the only real option I have found that looks like it will do what I want it to is - (void)getCharacters:(unichar *)buffer range:(NSRange)aRange I have used this once before but with static parameters 'that do not change', But for this implementation I am wanting to use non static parameters that change depending on the size of the string coming in. So far

Objective-C formatting string for boolean?

谁说胖子不能爱 提交于 2019-11-28 18:04:08
What formatter is used for boolean values? EDIT: Example: NSLog(@" ??", BOOL_VAL); , what is ?? ? One way to do it is to convert to strings (since there are only two possibilities, it isn't hard): NSLog(@" %s", BOOL_VAL ? "true" : "false"); I don't think there is a format specifier for boolean values. I would recommend NSLog(@"%@", boolValue ? @"YES" : @"NO"); because, um, BOOL s are called YES or NO in Objective-C. Use the integer formatter %d , which will print either 0 or 1 : NSLog(@"%d", myBool); In Objective-C, the BOOL type is just a signed char. From <objc/objc.h> : typedef signed char

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

橙三吉。 提交于 2019-11-28 17:14:32
问题 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

What is the difference between “copy” and “retain”?

有些话、适合烂在心里 提交于 2019-11-28 17:14:20
What is the difference between copy and retain for NSString ? - (void)setString:(NSString*)newString { string = [newString copy]; } Malaxeur In a general setting, retaining an object will increase its retain count by one. This will help keep the object in memory and prevent it from being blown away. What this means is that if you only hold a retained version of it, you share that copy with whomever passed it to you. Copying an object, however you do it, should create another object with duplicate values. Think of this as a clone. You do NOT share the clone with whomever passed it to you. When