nsstring

iOS ws服务连接

别来无恙 提交于 2019-11-29 00:30:58
参照一篇对SRWebSocket封装的文章,具体链接找不到了,文件名是SocketRocketUtility。 SDSocketRocketUtility.h #import "SDSocketRocketUtility.h" #define dispatch_main_async_safe(block)\ if ([NSThread isMainThread]) {\ block();\ } else {\ dispatch_async(dispatch_get_main_queue(), block);\ } NSString * const kNeedPayOrderNote = @"kNeedPayOrderNote"; NSString * const kWebSocketDidOpenNote = @"kWebSocketDidOpenNote"; NSString * const kWebSocketDidCloseNote = @"kWebSocketDidCloseNote"; NSString * const kWebSocketdidReceiveMessageNote = @"kWebSocketdidReceiveMessageNote"; @interface SDSocketRocketUtility()<SRWebSocketDelegate> {

使用runtime完成解档归档

南楼画角 提交于 2019-11-29 00:22:23
简单的创建一个Person对象,并声明几个属性 @interface Person : NSObject<NSCoding> // 归档问题 必须遵守该协议 /** */ @property(copy,nonatomic)NSString * name; /** */ @property(assign,nonatomic)int age; @property(assign,nonatomic)int age1; @end 设置哪些属性是需要归档的 //告诉系统,归档哪些属性 - (void)encodeWithCoder:(NSCoder *)coder { //利用runtime 来归档!! unsigned int count = 0; // 拷贝一个类 的属性列表 Ivar * ivars = class_copyIvarList([Person class], &count); // 在C语言中 但凡看到了一个传递了基本数据类型的指针 一般都是在函数中 改变外面参数的值 (这个ivars 可以形象的比喻为 数组 但是又区别于数组 如当我们 做ivars[100] 有可能不会报我们常见的数组越界而返回一个null 所以你懂得) for (int i = 0; i < count; i++) { //拿出每一个Ivar Ivar ivar = ivars[i]; const

How to remove the last unicode symbol from NSString

点点圈 提交于 2019-11-29 00:15:20
I have implemented a custom keyboard associated with a text field, so when the user presses the delete button, I remove the last character from the string, and manually update the current text field text. NSRange range = NSMakeRange(currentTextFieldString.length-1, 1); [currentTextFieldString replaceCharactersInRange:range withString:@""]; So far so good. Now, the problem is, that the user has the option to enter some special unicode symbols, these are not 1 byte, they can be 2 bytes too, now on pressing the delete button, I have to remove the entire symbol, but if I follow the above approach,

How to convert NSArray into NSString

天涯浪子 提交于 2019-11-29 00:09:58
How to convert NSArray into NSString in objective-c? Bearing in mind that you don't say what's in the NSArray, you can do this: NSArray *arr = [NSArray arrayWithObjects: @"foo", @"bar", @"baz"]; [arr componentsJoinedByString: @","] Aternatively to Frank's method, which works pretty well, you could also do NSString *myArrayString = [array description]; The default implementation of description on NSArray will print out the contents in a neatly formatted fashion. TheGreen This is how I have converted my NSArray to NSString NSError *error = nil; NSData *data = [NSJSONSerialization

How to get an array of sentences using CFStringTokenizer?

∥☆過路亽.° 提交于 2019-11-28 23:52:47
I've created an string tokenizer like this: stringTokenizer = CFStringTokenizerCreate( NULL , (CFStringRef)str , CFRangeMake(0, [str length]) , kCFStringTokenizerUnitSentence , userLocale); But how do I obtain those sentences now from the tokenizer? The CF String Programming Guide doesn't mention CFStringTokenizer or tokens (did a full-text search in the PDF). sbooth Here is an example of CFStringTokenizer usage: CFStringRef string; // Get string from somewhere CFLocaleRef locale = CFLocaleCopyCurrent(); CFStringTokenizerRef tokenizer = CFStringTokenizerCreate( kCFAllocatorDefault , string ,

javascript与Objective-C的交互

大城市里の小女人 提交于 2019-11-28 22:31:08
在iOS开发中, 苹果api味我们提供了多种javascript和Objective-C交互的方法, 使用还是比较简单的. 1. 普通的方式实现javascript和Objective-C交互 1.1 oc原生代码调用js代码 通过webView的stringByEvaluatingJavaScriptFromString:方法调用js代码. 此方法可以无限制的执行任何的js代码. /** 原生调用js, 普通的方法: * 通过webView的stringByEvaluatingJavaScriptFromString:方法, 可以无限制的执行任意的js代码,可以通过js代码操控webView上面的任意元素, 也可以直接通过js调用webView中的js代码. 实现从原生代码到javascript的联系. * */ [self.webView stringByEvaluatingJavaScriptFromString:@"showAlert('javascript message')"]; [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('abshdfnb').style.backgroundColor = 'blue';"]; 1.2 通过js调用js代码

【iOS】去除字符串首尾空格或某字符

梦想与她 提交于 2019-11-28 22:18:01
在iOS的实际开发中,常会出现需要去除空格的情况,总结有三种情况: 去除字符串首尾连续字符(如空格); 去除字符串首部连续字符(如空格); 去除字符串尾部连续字符(如空格); 去除字符串首尾连续字符(如空格) NSString *a = @" a sdf "; [a stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 去除字符串首部连续字符(如空格); NSString *a = @" a sdf "; NSString *leftResult = [a stringByTrimmingLeftCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; #import "NSString+util.h" @implementation NSString (util) - (NSString *)stringByTrimmingLeftCharactersInSet:(NSCharacterSet *)characterSet { NSUInteger location = 0; NSUInteger length = [self length]; unichar charBuffer[length]; [self

React Native 学习记录

寵の児 提交于 2019-11-28 21:23:34
由于 node_modules文件夹在别的地方,所以执行命令时,有下面改动的地方: 在植入到原生应用中 http://reactnative.cn/docs/embedded-app-ios.html#content 通过CocoaPods安装React Native # 取决于你的工程如何组织,你的node_modules文件夹可能会在别的地方。 # 请将:path后面的内容修改为正确的路径。 pod 'React', :path => './node_modules/react-native', :subspecs => [ 'Core', 'RCTImage', 'RCTNetwork', 'RCTText', 'RCTWebSocket', # 添加其他你想在工程中使用的依赖。 ] 这里的path 指定的是本地路劲,此目录下一定要有.podspec文档,使用时候相对路劲总是不对,后来改用绝对路径 启动开发服务器 官方文档写的 配置的JS_DIR 路径不对,后来改成 npm run start -- --root " /Users/huhmf/Desktop/myCode/facebook/reactDemo/reactDemo/ReactComponent " npm start -- --root ../reactDemo/reactDemo/ReactComponent

NSString question - rangeOfString method

≯℡__Kan透↙ 提交于 2019-11-28 21:07:57
I am having an issue that I can't figure out. I'm trying to run the rangeOfString method on a string, and I'm not sure how to determine if the string was not found. For example: NSRange range = [@"abc" rangeOfString:@"d" options:NSCaseInsensitiveSearch range:NSMakeRange(0,3)]; Clearly, "d" is not contained in the string "abc." I'd like to be able to do this: if(the range is empty since "d" is not in "abc") //do something What is the code for this? Thanks!! Jared Pochtar From the documentation of NSString -[NSString rangeOfString] Return Value An NSRange structure giving the location and length

Get current city and country from CLGeocoder?

独自空忆成欢 提交于 2019-11-28 20:37:56
问题 I've been all over the internet trying to find out how to get the city and country from CLGeocoder . I can get the longitude and latitude easily but I need the city and country information, and I keep running into deprecated methods and such, any ideas? It basically needs to get the location, then have an NSString for the country, and an NSString for the city, so I can use them to look up more info or put them on labels, etc. 回答1: You need to revise your terminology a bit - CLGeocoder (and