Tag: nsstring

如何在NSString stringWithFormat中使用%字符

如何在NSString stringWithFormat使用%字符? 我正在尝试: [NSString stringWithFormat:@"%%@,%@",string1,string2]; 第一个%不显示。

extern NSString * const在一个类中。

嗨,我有这个头文件: #import <Foundation/Foundation.h> @interface PCConstants : NSObject extern NSString *const kPCUserProfileKey; extern NSString *const kPCUserProfileNameKey; extern NSString *const kPCUserProfileFirstNameKey; extern NSString *const kPCUserProfileLocationKey; extern NSString *const kPCUserProfileGenderKey; extern NSString *const kPCUserProfileBirthDayKey; extern NSString *const kPCUserProfileInterestedInKey; @end 执行: #import "PCConstants.h" @implementation PCConstants NSString *const kPCUserProfileKey = @"profile"; NSString *const kPCUserProfileNameKey = @"name"; NSString *const kPCUserProfileFirstNameKey = […]

淡出不符合文本标签string的结尾(而不是截断)

我不确定“淡出”是否是正确的术语,因为它看起来很像animation效果,但是我想在iPhone Safari应用程序的地址栏中看到。 当URL显示的时间太长时,string的末尾“淡出”而不是被截断为“…”。 我认为这可以很容易地通过在XIB文件中将换行符设置从“截断尾部”更改为“剪辑”,然后使用具有透明度的图像来创build效果来完成。 但设置为“剪辑”似乎夹在一个单词的结尾,而不是一个字的中间,或者甚至是一个字母的中间,如在Safari或Chrome for iPhone中所见。 这对我来说并不合适,实际上给人的印象是文本是完整的,经过仔细观察,用户会注意到文本没有意义。 什么是最好的方式来“淡出”不符合文本标签的string? 提前致谢。

从NSString中提取子string

我想从NSString中提取子string。 怎么可能。 示例:string是abcdefwww.google.comabcdef 输出: www.google.com 在主要string中,不会预定义哪个url来,可能是google.com或yahoo.com等。 所以我必须在www中findw的起始位置,在.com中findm的最后一个位置。 所以我的问题是,我怎样才能findWW的起始位置和在.com中的m的位置,所以我提取这部分 由于问题编辑: 我们如何从这个string中提取www.mywebsite.co.uk asdfwww.mywebsite.co.ukasdfajsf 谢谢

文件名NSString在空间中添加不必要的%20

解决(感谢Regexident) 我有一个应用程序将PDF的文件path传递给一个自定义的-(id)init init方法。 它被添加到表中,当它被选中时,它调用一个不存在的文件的else语句: – (void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index { NSLog (@"Selected theArgument=%d\n", index); UIViewController *viewController = [[[UIViewController alloc]init]autorelease]; { //if file is built-in, read from the bundle if (index <= 3) { // first section is our build-in documents NSString *fileURLs = [_documentIconsURLs objectAtIndex:index]; NSLog(@"file url -%@", fileURLs); viewController = [[[xSheetMusicViewController alloc]initWithContentURL:fileURLs]autorelease]; } //if […]

核心数据是否会限制string的长度?

我想知道在iOS中使用Core Data存储的string的长度是否有限制。 (设备上可用的RAM或磁盘空间除外)

Safari扩展上的应用程序传输安全

我的应用程序扩展需要打开来自许多网站的url。 我做如下: for (NSExtensionItem *item in self.extensionContext.inputItems) { for (NSItemProvider *itemProvider in item.attachments) { if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) { [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url, NSError *error) { NSLog(@"URL: %@",url); 我可以得到的URL,但在这一点上,我得到这个错误: 应用传输安全已阻止明文HTTP(http://)资源加载,因为它是不安全的。 临时例外可以通过您的应用程序的Info.plist文件进行configuration。 我试图完全closuresATS, <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> 但它不起作用,我不能列出NSExceptionDomain内的网站。 我尝试在模拟器和设备上。 有人可以帮忙吗? 编辑 我认为导致问题的代码是这样的: NSString* htmlString = [NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding] 我在URLlogin后使用这行代码来获取纯文本的HTML。

如何将此string转换为json或ios中的字典

我厌倦了链接,但这些都不适合我的情况。 任何人都可以build议我如何将此string转换为JSON或字典。 这个string有一个string数组的字典。 NSString *temp=@"{\n name = {\n dob = \"\";\n age = \"61\";\n family = (\n {\n location = location;\n mobile = mobile;\n }\n );\n };\n}"; 这里的家庭是一个arrays。

addSkipBackupAttributeToItemAtURL – > NSString参数?

为了遵循数据存储指南,我必须使用下面的方法添加一个标志来说明不支持iCloud。 但是,这里的参数是NSURL的。 我需要像这样从一行传递一个NSString return [[self offlineQueuePath] stringByAppendingPathComponent:@"SHKOfflineQueue.plist"]; 这是接收URL的方法。 – (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1 const char* filePath = [[URL path] fileSystemRepresentation]; const char* attrName = "com.apple.MobileBackup"; u_int8_t attrValue = 1; int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); return result == 0; } else { // iOS […]

NSAttributedString:设置FontAttributes不会改变字体

我正在尝试更改NSAttributedString上的字体。 我有一个迭代每个字符的方法,并为该字符创build一个新的NSFontAttribute字典。 但是,最后,string保持不变。 为了演示,这里是我如何设置string: UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithName:@"Avenir-Book" size:14.0f]; NSDictionary *fontAttributes = [fontDescriptor fontAttributes]; [fontAttributes setValue:[NSString stringWithFormat:@"%u",[fontDescriptor symbolicTraits]] forKey:UIFontSymbolicTrait]; [mutableAttributedString setAttributes:fontAttributes range:(NSRange){0,length}]; 这将为整个string生成以下NSFontAttribute字典: Font Attributes: { NSCTFontSymbolicTrait = 2147483648; NSFontNameAttribute = "Avenir-Book"; NSFontSizeAttribute = 14; } 我通过并修改每个字符的FontAttribute来添加粗体或斜体,如下所示: for (int i = (int)range.location; i < (range.location + range.length); i++){ /* Extract Font Attributes */ NSDictionary […]