nsstring

Objective-C 语言中的类类型

╄→гoц情女王★ 提交于 2019-12-04 19:17:27
小菜鸟在学习使用UICollectionView的时候发现个函数: - ( void ) registerClass: ( Class ) cellClass forCellWithReuseIdentifier: ( NSString * ) identifier ; 这个函数允许用户为不同的标示设置对应的类型,生成UICollectionCell组建UICollectionView时,会根据 identifier的不同创建不同类型的Cell。 其中这个 Class 就是Obj-c中的类类型。 从UICllection的使用可以看出类类型在自定义类的使用中非常方便。 下面是类类型的使用: 得到类类型 每个类都有类类型生成方法: + ( Class ) class ; 接受类类型 Class CLString = [ NSString class ]; 使用类类型 使用类类型也非常简单 id aString = [ CLString new ]; 或者 id aString = [[ CLString alloc ] init ]; 这时 aString就是NSString的一个实例了。 来源: oschina 链接: https://my.oschina.net/u/1262158/blog/205320

How do you join an NSArray of [Number numberWithChar: c]'s into an NSString?

不问归期 提交于 2019-12-04 19:14:45
When I use componentsJoinedByString , I just get a long string of digits. Edit: I realize this task is confusing. Why on earth would anyone populate an NSArray with NSNumbers if they wanted an NSString? The answer is that I'm writing an extensible unit test framework. The basic functions genNum , genBool , and genChar generate NSNumbers with random int, BOOL, and char values respectively. Then there's genArray which generates a random array using a specified generator. So to construct a random NSString, one would run genArray using the genChar generator, and transform the resulting NSArray

Hybrid App: 看看第三方WebViewJavascriptBridge是如何来实现Native和JavaScript交互

一笑奈何 提交于 2019-12-04 19:13:56
一、简介 在前面两篇文章中已经介绍了Native与JavaScript交互的几种方式,依次是JavaScriptCore框架、UI组件UIWebView、WebKit框架,这几种方式都是苹果公司提供的,除了UIWebView在IOS8之后被苹果淘汰了外,其他基本都能很好地满足开发者的使用。作为一个技术人员,每个人心里都有造轮子的想法,可能有时觉得原生的API使用起来感觉还是不够方便,就对苹果原生的API再进行一层封装,这不WebViewJavascriptBridge这个轮子出来了。WebViewJavascriptBridge的star和fork量还是比较高的,仔细看看WebViewJavascriptBridge类文件相当简单,使用起来也很方便,很受开发者欢迎,它的原理还是利用WKWebView或者UIWebView的相关API,通过bridge桥梁来实现OC与JS互相注册和调用。大致结构图如下: 可以看出:OC调用JS,JS需要注册函数; JS调用OC,OC需要注册函数。 二、分析 了解基本原理结构图后,再来看看框架中的类以及它们的作用定义,如下: WebViewJavascriptBridge_JS :Javascript环境的Bridge初始化和处理。负责接收OC发给Javascript的消息,并且把Javascript环境的消息发送给OC。

Get result from shell script objective-c

試著忘記壹切 提交于 2019-12-04 19:10:06
I would like to run a shell script, from a file or from an objective-c string (within the code). I would also like the shell script's result to be stored to a variable. I would not like the shell script to be split into arguments (such as setLaunchPath when I run it). For example: running this shell script "mount_webdav idisk.mac.com/mac_username /Volumes/mac_username" instead of "/bin/mount_webdav" then the arguments. Is there anyway to do this? I am using NSTask right now, but it has caused me some errors when I try to put the arguments with it. Here is the posed code: (some of the .m file)

Passing NSString from one view to another view

倖福魔咒の 提交于 2019-12-04 19:00:02
I have 2 views that are sharing the same class files (.h and .m). In the first view, I have a UIPicker with a list of items and a button. If the user clicks the button, I want my second view to come up with the appropriate Picture (based on the item that was selected in the UIPicker). My thinking was to set an NSString in the first view based on the selected item. Then when the user clicks the button to push the second view onto the screen, i could pass that string with the new view. I've been "googling" for awhile but I can't seem to wrap my finger around it. If it matters, I am using a

Split string into parts

徘徊边缘 提交于 2019-12-04 18:47:27
I want to split NSString into array with fixed-length parts. How can i do this? I searched about it, but i only find componentSeparatedByString method, but nothing more. It's also can be done manually, but is there a faster way to do this ? Depends what you mean by "faster" - if it is processor performance you refer to, I'd guess that it is hard to beat substringWithRange: , but for robust, easy coding of a problem like this, regular expressions can actually come in quite handy. Here's one that can be used to divide a string into 10-char chunks, allowing the last chunk to be of less than 10

Objective c: Check if integer/int/number

拜拜、爱过 提交于 2019-12-04 17:42:11
问题 In objective c, how can i check if a string/NSNumber is an integer or int 回答1: You can use the intValue method on NSString: NSString *myString = @"123"; [myString intValue]; // returns (int)123 Here is the Apple documentation for it - it will return 0 if it's not a valid integer: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/intValue Hope that helps! 回答2: If you're trying to

If NSString stringWithContentsOfFile is deprecated, what is its replacement?

≯℡__Kan透↙ 提交于 2019-12-04 17:39:51
问题 I have some sample code from Tuaw which is probably 3 releases old ;) The compiler is issuing a warning that the method is deprecated, but I do not see that mentioned in the SDK docs. If it is deprecated, there must be an alternative approach or replacement method. Does anyone know what the replacement is for this method? The specific code was: NSArray *crayons = [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt"]] componentsSeparatedByString:@

IOS NSPredicate 查询、搜索

隐身守侯 提交于 2019-12-04 17:33:16
简述:Cocoa框架中的NSPredicate用于查询,原理和用法都类似于SQL中的where,作用相当于数据库的过滤取。 最常用到的函数 + (NSPredicate *)predicateWithFormat:(NSString *)predicateFormat, ...; 1.比较运算符 > 、< 、== 、 >= 、<= 、 != 例:@"number >= 99" 2.范围运算符:IN 、BETWEEN 例:@"number BETWEEN {1,5}" @"address IN {'shanghai','nanjing'}" 3.字符串本身:SELF 例:@"SELF == 'APPLE'" 4.字符串相关:BEGINSWITH、ENDSWITH、CONTAINS 例:@"name CONTAIN[cd] 'ang'" //包含某个字符串 @"name BEGINSWITH[c] 'sh'" //以某个字符串开头 @"name ENDSWITH[d] 'ang'" //以某个字符串结束 注:[c]不区分大小写 , [d]不区分发音符号即没有重音符号 , [cd]既不区分大小写,也不区分发音符号。 5.通配符:LIKE 例:@"name LIKE[cd] '*er*'" //*代表通配符,Like也接受[cd]. @"name LIKE[cd] '???er*'" 6

How do I get the text from UITextField into an NSString?

跟風遠走 提交于 2019-12-04 17:25:43
问题 I've tried various methods, which all give me warnings. Such as userName = [NSString stringWithFormat:@"%@", [yournamefield stringValue]]; which just gives me a warning of 'UITextField' may not respond to '-stringValue' How do i do this? 回答1: Get the text inside the text field using the text property NSString *name = yourNameField.text; 回答2: Use the text property of UITextField : NSString *userName = yourNameField.text; 回答3: How about: userName = [NSString stringWithFormat:@"%@",