nsstring

In-App Purchases功能ECPurchase-ios

心已入冬 提交于 2019-12-19 13:00:51
在程序中,我们可以使用IOS内置库StoreKit.framework里提供的Api实现In-App Purchases产品的购买功能。但如果你不想根据文档再自己写purchase功能,那么有一个第三方的库ECPurchase会适合你。 ECPurchase库封装了purchase的内在逻辑,并且提供了几种验证方式(用于防止iap破解),调用简单方便。ECPurchase库可在文章后面我提供的例子里获得。ECPurchase提供了下面的接口需要开发者自己完成: 1.在App Delegate中添加Observer [[ECPurchase shared] addTransactionObserver]; 2.设置ECPurchase的product delegate(产品列表代理),transaction delegate(购买结果代理),验证方式 [[ECPurchase shared] setProductDelegate:self]; [[ECPurchase shared] setTransactionDelegate:self]; [[ECPurchase shared] setVerifyRecepitMode:ECVerifyRecepitModeiPhone]; 3.请求商品列表 [[ECPurchase shared] requestProductData

how to convert NSString to NSArray [duplicate]

怎甘沉沦 提交于 2019-12-19 12:21:23
问题 This question already has answers here : Comma-separated string to NSArray in Objective-C (2 answers) Closed 5 years ago . I have a string like NSString* str = @"[90, 5, 6]"; I need to convert it to an array like NSArray * numbers = [90, 5 , 6]; I did a quite long way like this: + (NSArray*) stringToArray:(NSString*)str { NSString *sep = @"[,"; NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:sep]; NSArray *temp=[str componentsSeparatedByCharactersInSet:set];

Replace characters (unique then wildcard value) in a string with other characters

不打扰是莪最后的温柔 提交于 2019-12-19 11:59:34
问题 I have an NSString, let's say "H,L,K,P" how can I detect a specific character than then a wild-car character... for example, checking for ",*" would return ",L" ",K" and ",P" because they all have the specific "," and then they all have a character after them. Then I want to replace that string with itself plus a "period" appended to it. So "H,L,K,P" would become "H,L.,K.,P." 回答1: Use a regular expression. The search pattern would be: ,(.) the replacement pattern would be: ,$1. Sample code:

Is it possible to set custom font & size for NSString?

走远了吗. 提交于 2019-12-19 11:56:25
问题 I'm working with Swift in iOS 9. I want to customize the font for a UIAlertAction . I searched these questions for a Swift answer: Change the Font of UIAlertAction in Swift Is it possible to customize the font and appearance of a UIAlertController in the new XCode w/ iOS8? And this question for an Objective-C answer: UIAlertController custom font, size, color But there was no solution for customizing the font for a UIAlertAction . I believe the problem is that a UIAlertAction uses an NSString

How do I properly encode Unicode characters in my NSString?

▼魔方 西西 提交于 2019-12-19 10:14:03
问题 Problem Statement I create a number of strings, concatenate them together into CSV format, and then email the string as an attachment. When these strings contain only ASCII characters, the CSV file is built and emailed properly. When I include non-ASCII characters, the result string becomes malformed and the CSV file is not created properly. (The email view shows an attachment, but it is not sent.) For instance, this works: uncle bill's house of pancakes But this doesn't (note the curly

Truncate part of an NSString starting at a particular character

我是研究僧i 提交于 2019-12-19 09:55:16
问题 I have a string NSString * myOldString = @"This is a string (and this part is between brackets)" Now, I want to truncate the string in such a way, that basically everything between the brackets, including the brackets, is truncated. More precisely: I don't care what is happening after the first bracket at all. I can't do a simple stringByReplacingOccurrencesOfString: , because I cannot predict what will be between the brackets. So, the resulting string should be: "This is a string" 回答1: One

NSSortDescriptor with arbitrary sorting

萝らか妹 提交于 2019-12-19 09:04:17
问题 I can't wrap my head around how to do arbitrary sorting with a NSSortDescriptor. I want to do something like this: NSArray *sortAlgorithm = [NSArray arrayWithObjects:@"@", @"#", @"!", @"&", @"r", @"a", nil]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES comparator: ^(id obj1, id obj2) { NSComparisonResult comparisonResult; //Some code that uses sortAlgorithm. return comparisonResult; } ]; This would sort the objects by the key name so that any

Calling method sizeToFit on a UILabel that has subscripts is not working

耗尽温柔 提交于 2019-12-19 07:51:17
问题 I have a subclass of UILabel, which is supposed to update its text when the user types something. Naturally, as the length of text increases, the size of the label must adjust to accommodate the text. I called the sizeToFit method, and while the label adjusts its width correctly, the bottom of the text is cut off. The problem is that the text includes subscripts and superscripts , and the label is not adjusting itself with the subscripts in consideration (for example, with H₂O the bottom of

Sensitive data: NSString VS NSMutableString (iPhone)

ぃ、小莉子 提交于 2019-12-19 07:10:54
问题 I have some sensitive data I want to clear directly after use. Currently, the sensitive data is in the form of NSString. NSString is in my understanding immutable, meaning that I can't really clear the data. NSMutableString seems more appropriate, though, as it is mutable and has methods like replaceCharactersInRange and deleteCharactersInRange. I have no knowledge of the implementation details so I wonder if NSMutableString would serve my purpose? 回答1: I would be afraid NSMutableString would

objective-c NSFilePosixPermissions to human readable NSString

匆匆过客 提交于 2019-12-19 06:56:08
问题 is there a way to get human readable string (@"drwxr-xr-x" for example) from an NSFilePosixPermissions integer ? 回答1: The file system permissions attribute is simply an unsigned long value. The code below could obviously be made more efficient but it shows [more or less] what needs to be done to get the string you want: // The indices of the items in the permsArray correspond to the POSIX // permissions. Essentially each bit of the POSIX permissions represents // a read, write, or execute bit