nsstring

分析Runtime的属性Property

£可爱£侵袭症+ 提交于 2019-12-04 04:47:10
一、介绍 在OC中我们可以给任意的一个类以@property的格式声明属性,当然对于这个属性也会采用某一些属性关键字进行修饰,那么属性的真正的面目是啥样子的呢?其实,runtime源码中可以看到,property是一个结构,如下所示,只不过苹果为这个结构体另外定义了一个结构体指针。 //属性结构体指针 typedef struct objc_property *objc_property_t; 二、函数 正如我们所知,MJExtension是一个非常流行的json解析框架,其内部对对象的每一个属性进行解析的方式其实就是通过runtime来实现的。runtime源码中提供了属性的相关API函数。通过这些函数,我们可以轻松的得到每一个属性名和类型以及特性,相关函数如下: //获取一个属性 objc_property_t _Nullable class_getProperty(Class _Nullable cls, const char * _Nonnull name); //添加一个属性 class_addProperty(Class _Nullable cls, const char * _Nonnull name, const objc_property_attribute_t * _Nullable attributes,unsigned int attributeCount)

Objective-C: How to find the most common string in an array?

你说的曾经没有我的故事 提交于 2019-12-04 04:40:18
问题 I have an array of strings from an online database that I trying to determine the most commonly used word. The values inside the arrays will vary but I want to check the most common words of whatever collection or words I'm using. If theoretically I had an array of the following... NSArray *stringArray = [NSArray arrayWithObjects:@"Duck", @"Duck", @"Duck", @"Duck", @"Goose"]; How do I iterate through this array to determine the most common string, which would obviously be "Duck"? 回答1:

NSString Backslash escaping

对着背影说爱祢 提交于 2019-12-04 04:30:06
问题 I am working on an iPhone OS application that sends an xml request to a webservice. In order to send the request, the xml is added to an NSString. When doing this I have experienced some trouble with quotation marks " and backslashes \ in the xml file, which have required escaping. Is there a complete list of characters that need to be escaped? Also, is there an accepted way of doing this escaping (ie replacing \ with \\ and " with \" ) or is it a case of creating a method myself? Thanks 回答1:

Getting actual NSString of AvCaptureVideoDataOutput availableVideoCVPixelFormatTypes

限于喜欢 提交于 2019-12-04 03:18:28
I am trying to find the accepted formats on an AVFoundation output: self.theOutput=[[AVCaptureVideoDataOutput alloc]init]; if ([self.theSession canAddOutput:self.theOutput]) [self.theSession addOutput:self.theOutput]; I am then inserting a breakpoint right after and: po [self.theOutput availableVideoCVPixelFormatTypes] and I get this: (NSArray *) $5 = 0x2087ad00 <__NSArrayM 0x2087ad00>( 875704438, 875704422, 1111970369 ) How do I get the string values of these format types? Thanks On an iPhone5 running iOS6, here are the AVCaptureVideoDataOuput availableVideoCVPixelFormatTypes:

UILineBreakMode Vs NSLineBreakMode

与世无争的帅哥 提交于 2019-12-04 02:45:55
I see some UIStringDrawing methods have been updated to use NSLineBreakMode instead of UILineBreakMode in iOS 6.0: E.g. - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode How can I check for this to ensure my iOS 5 users and below continue to use UILineBreakMode? No checking is necessary. These are just enums and they map to the same values You can see there is no real difference here: UILineBreakMode vs NSLineBreakMode enum { NSLineBreakByWordWrapping = 0, NSLineBreakByCharWrapping, NSLineBreakByClipping,

NSString with Unicode issue from Web Service

Deadly 提交于 2019-12-04 02:05:57
问题 I have tried to search in Stackoverflow. But I could not get the correct solution. Can someone please help me? I have this data from a web service. KEY: 1036 TYPE: string VALUE = French (fran\u00E7aise) KEY: 1032 TYPE: string VALUE = Greek (\u03B5\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC) Does anyone know how to print this Unicode string correctly? I have tried to encode and decode it back (as shown below). But it is not working. :( NSString *value = [NSString stringWithFormat:@"%@", t

Character occurrences in a String Objective C

落花浮王杯 提交于 2019-12-04 01:52:40
How can I count the occurrence of a character in a string? Example String: 123-456-7890 I want to find the occurrence count of "-" in given string You can simply do it like this: NSString *string = @"123-456-7890"; int times = [[string componentsSeparatedByString:@"-"] count]-1; NSLog(@"Counted times: %i", times); Output: Counted times: 2 This will do the work, int numberOfOccurences = [[theString componentsSeparatedByString:@"-"] count]; I did this for you. try this. unichar findC; int count = 0; NSString *strr = @"123-456-7890"; for (int i = 0; i<strr.length; i++) { findC = [strr

Objective-C how to check if a string is null

限于喜欢 提交于 2019-12-04 01:50:48
SO I wish to check to see if the item in my array [clientDataArray objectForKey:@"ClientCompany"] is nil . temp = [clientDataArray objectForKey:@"ClientCompany"]; if (temp != [NSNull null]) infofieldCompany.text = temp; So far I have been able to achieve this through the above code, but it does give me the warnings warning: NSArray may not respond to -objectForKey: warning: comparison of distinct Objective-C types struct NSNull * and struct NSString * lacks a cast My main interest is the second warning, but the first warning also interest me. How should I adapt my above code? Your first

Why does NSLog sometimes print out octal for ucode characters?

我们两清 提交于 2019-12-04 01:43:01
I'm running the following code in the viewDidLoad function of a vanilla iPad single view app: /* * Print the string. A lot. */ for (int i = 0; i < 300; i++) { NSLog(@"%d\n", i); NSLog(@"⊢ ⊣ ⊥ ⊻ ⊼ ⊂ ⊃ ⊑ ⊒ \n"); } The output looks like this: 2013-02-04 20:17:49.718 testplay[59585:c07] 228 2013-02-04 20:17:49.718 testplay[59585:c07] ⊢ ⊣ ⊥ ⊻ ⊼ ⊂ ⊃ ⊑ ⊒ 2013-02-04 20:17:49.719 testplay[59585:c07] 229 2013-02-04 20:17:49.719 testplay[59585:c07] ⊢ ⊣ ⊥ ⊻ ⊼ ⊂ ⊃ ⊑ ⊒ 2013-02-04 20:17:49.719 testplay[59585:c07] 230 2013-02-04 20:17:49.720 testplay[59585:c07] ⊢ ⊣ ⊥ ⊻ ⊼ ⊂ ⊃ ⊑ ⊒ 2013-02-04 20:17:49.720

NSString to NSURL?

被刻印的时光 ゝ 提交于 2019-12-04 01:34:59
Trying to convert a string to NSURL and this is not happening. barcodeTextLabel.text = foundCode.barcodeString; urlToGrab = [NSString stringWithFormat:@"%@", foundCode.barcodeString]; // foundCode.barcodeString is an NSString urlToGrab shows the following "error invalid CFStringRef" Dimme This is how you create an NSURL from an NSString : NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; swapnali patil You can use following for creating the file path to url. NSURL *yourURL = [NSURL fileURLWithPath:@"/Users/xyz/Desktop/abc.sqlite"]; If foundCode.barcodeString is the string you want