nsstring

'(NSObject, AnyObject)' is not convertible to 'String'

落花浮王杯 提交于 2020-01-13 09:31:52
问题 How do I convert an object of type (NSObject, AnyObject) to the type String ? At the end of the first line of the method below, as String causes the compiler error: '(NSObject, AnyObject)' is not convertible to 'String' Casting street to NSString instead of String compiles, but I'm casting street to String because I want to compare it to placemark.name , which has the type String! , not NSString . I know name and street are optionals, but I'm assuming they're not nil for now because all the

Parse NSDictionary to a string with custom separators

泪湿孤枕 提交于 2020-01-12 18:48:22
问题 I have an NSMutableDictionary with some values in it, and I need to join the keys and values into a string, so > name = Fred > password = cakeismyfavoritefood > email = myemailaddress@is.short becomes name=Fred&password=cakeismyfavoritefood&email=myemailaddress@is.short How can I do this? Is there a way to join NSDictionaries into strings? 回答1: You can easily do that enumerating dictionary keys and objects: NSMutableString *resultString = [NSMutableString string]; for (NSString* key in

策略模式vs工厂模式的区别

帅比萌擦擦* 提交于 2020-01-12 16:00:26
定义: 工厂模式的思想主要为:多个类似的子类继承同一个父类,对其父类中的变量进行操作;工厂类负责判断、控制哪个子类被执行,而工厂类调用子类完成后,返回的结果是该子类的父类,该父类中的变量已经被操作过了,访问该父类,得到我们想要的结果 策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换。策略模式让算法独立于使用它的客户而独立变化。 1. 相似: 在模式结构上,两者很相似; 2.差别: 用途不一样 工厂是创建型模式,它的作用就是创建对象; 策略是行为型模式,它的作用是让一个对象在许多行为中选择一种行为; 关注点不一样 一个关注对象创建 一个关注行为的封装 解决不同的问题 工厂模式是创建型的设计模式,它接受指令,创建出符合要求的实例;它主要解决的是资源的统一分发,将对象的创建完全独立出来,让对象的创建和具体的使用客户无关。主要应用在多数据库选择,类库文件加载等。 策略模式是为了解决的是策略的切换与扩展,更简洁的说是定义策略族,分别封装起来,让他们之间可以相互替换,策略模式让策略的变化独立于使用策略的客户。 工厂相当于黑盒子,策略相当于白盒子; 策略模式例子 例1、 (1)策略模式的核心就是对算法变化的封装。 定义一个通用算法协议,让每个算法遵守其规则。 @protocol LHPlayerProtocol <NSObject> /** * Player开启视频

Getting actual NSString of AvCaptureVideoDataOutput availableVideoCVPixelFormatTypes

依然范特西╮ 提交于 2020-01-12 14:31:11
问题 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 回答1: On an

iOS 支付宝支付

谁说我不能喝 提交于 2020-01-12 11:41:52
在开发过程中,经常需要接入第三方支付。下面对支付进行一个概括。 支付宝支付 支付宝SDK下载地址: https://doc.open.alipay.com/doc2/detail?treeId=54&articleId=103419&docType=1 支付宝集成 在支付宝集成的过程中,会遇到一些报错,下面就碰到的报错,和大家一起解决。 集成参考官方文档: 导入代码文档: https://doc.open.alipay.com/doc2/detail.htm?spm=0.0.0.0.RiFaVa&treeId=59&articleId=103676&docType=1 Demo运行注意: https://doc.open.alipay.com/doc2/detail.htm?spm=0.0.0.0.Ravnv1&treeId=59&articleId=103677&docType=1 1.新建一个aliPaySDK文件夹,提取SDK包中以下文件到此文件夹里,把文件拉到xcode里 2.在xcode中,点击项目名,选择Build Phases -->Link Binary With Libraries 添加依赖库。 注意:如果漏了部分没有添加的,有时会报其它各种错。 3.编译项目,会出现以下错误。 1) Cannot find interface declaration for

Substring from NSString [closed]

故事扮演 提交于 2020-01-12 01:46:28
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I am using NSString and I want to get a substring of it that contains the first 20 characters of my string. How can I do that? 回答1: You can use substringToIndex . NSString *mystring = @"This is a test message having more than 20 characters"; NSString *newString = [mystring

iOS- <项目笔记>UI控件常见属性总结

本小妞迷上赌 提交于 2020-01-11 17:39:34
1.UIView   // 如果userInteractionEnabled=NO,不能跟用户交互 @property ( nonatomic , getter =isUserInteractionEnabled) BOOL userInteractionEnabled; // 控件的标记(父控件通过标记可以找到对应的子控件) @property ( nonatomic ) NSInteger tag; // 控件的位置和尺寸(以父控件的左上角为坐标原点) @property ( nonatomic ) CGRect frame; // 控件的位置和尺寸(以控件本身的左上角为坐标原点) @property ( nonatomic ) CGRect bounds; // 控件的中点位置(以父控件的左上角为坐标原点) @property ( nonatomic ) CGPoint center; // 形变属性:旋转、缩放、平移 @property ( nonatomic ) CGAffineTransform transform; // 父控件 @property ( nonatomic , readonly ) UIView *superview; // 所有的子控件 @property ( nonatomic , readonly , copy ) NSArray

Convert TXT File of Unknown Encoding to String

女生的网名这么多〃 提交于 2020-01-11 09:18:47
问题 How can I convert Plain Text (.txt) files to a string if the encoding type is unknown? I'm working on a feature that would allow users to import txt files into my app. This means the file could have been created in any number of apps, utilizing any of a variety of encodings that would be considered valid for a plain text file. My understanding is this could include (ASCII, UTF-8, UTF-16, UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, or EBCDIC?!) Things had been going well using the

iOS防Charles抓包

本秂侑毒 提交于 2020-01-11 06:17:10
开发中使用代理抓网络请求很正常,那么如何防止被代理抓包呢 可以通过CFNetwork 通过ASIHTTPRequest的属性,可以提取出代理设置 代码先搞起来 /** @param 判断是否设置代理 */ + (BOOL)getProxyStatus { NSDictionary *proxySettings = NSMakeCollectable([(NSDictionary *)CFNetworkCopySystemProxySettings() autorelease]); NSArray *proxies = NSMakeCollectable([(NSArray *)CFNetworkCopyProxiesForURL((CFURLRef)[NSURL URLWithString:@"http://www.google.com"], (CFDictionaryRef)proxySettings) autorelease]); NSDictionary *settings = [proxies objectAtIndex:0]; NSLog(@"host=%@", [settings objectForKey:(NSString *)kCFProxyHostNameKey]); NSLog(@"port=%@", [settings objectForKey:

NSString representation of fractions using unicode

与世无争的帅哥 提交于 2020-01-11 05:05:32
问题 I am trying to "nicely" display fractions in my iPhone application. Previously I have been using a tedious switch statement leading to hardcoded unicode characters for the vulgar fractions, but I have learnt about the unicode fraction slash character which, if I am understanding it correctly, should mean that I can create a string as follows: [NSString stringWithFormat:@"%i\u2044%i",numerator,denominator]; And the "renderer" will automatically print it with a smaller, superscriped numerator