nsstring

Memory Leak - NSString & NSURL

三世轮回 提交于 2020-01-05 22:42:09
问题 @property ( nonatomic, strong ) NSURL * urlPath; self.urlPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bark" ofType:@"caf"]]; Running ARC, deployment target 4.3. Instruments gives a leak on the self.urlPath = line. The self.urlPath is used later on after the view has appeared to setup the AVSoundPlayer. There is NO leak indicated now on the soundplayer, only on this NSURL line. The audio plays, but when the view is pop'd a memory leak occurs. Any ideas as I've been at

NSString value returning before Block has run

旧巷老猫 提交于 2020-01-05 18:37:10
问题 I'm trying to use a value generated inside of a block ("fid") outside of a block. The problem being that the value is being pulled before the block has run, and so the value returns as (null), even though the data is present. Does anyone know how I can make this work? See code: .h @property (nonatomic, strong) NSString *fid; .m [DIOSFile fileSave:file success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"File uploaded!"); [file setObject:[responseObject objectForKey:@"fid"

Objective-C: Substring and replace

二次信任 提交于 2020-01-05 08:04:39
问题 I have a NSString which is a URL. This URL need to be cut: NSString *myURL = @"http://www.test.com/folder/testfolder"; NSString *test = [myURL stringByReplacingCharactersInRange:[myURL rangeOfString:@"/" options:NSBackwardsSearch] withString:@""]; I have this URL http://www.test.com/folder/testfolder and I want that the test variable should have the value http://www.test.com/folder/ , so the testfolder should be cut. So I tried to find the NSRange testfolder to replace it with an empty string

How should I store a large string, like a user agreement? [closed]

三世轮回 提交于 2020-01-05 07:27:50
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I can use a string literal like @"content" , but I think it’s a waste of memory. Is there a custom solution for this situation? I'm a new Xcoder, so may be this is not a good question, but I'm very confuse about

iOS-上拉刷新,下拉加载-----------详解

烈酒焚心 提交于 2020-01-05 02:02:34
一.使用的第三方库 1.AFNetworking ----> 网络请求 2. MJRefresh ----> 刷新 3. MBProgressHUD ----> 缓冲视图 二.原理 1. 上拉加载 每加载一次,用一个变量(_pageNumber)记载加载的页码数.这样每次获取的数据就会多一页的数据. 但是如果上拉之后,没有加载到数据(比如:1.网络请求失败. 2.网络请求成功,但是没有获取到数据. 3.网络请求成功,并且获取到数据,但是数据为空),这样的情况下,该变量(_pageNumber)计数减一. 2. 下拉刷新 (1) 页数设置为1.只请求一页的数据,达到刷新的目的. (2) 将数据源的数据清空 三. 代码 #import "ViewController.h" #import "AFNetworking.h" #import "MJRefresh.h" #import "MBProgressHUD.h" #import "Cell.h" #import "Model.h" #define kWidth [UIScreen mainScreen].bounds.size.width #define kHeight [UIScreen mainScreen].bounds.size.height @interface ViewController ()

How to concat a const char * to a NSString *

喜你入骨 提交于 2020-01-04 17:51:04
问题 Trying to append const char *str to a NSSting * : In .h @interface SomeViewController : UIViewController { NSString *consoleText; } @property (nonatomic, retain) NSString *consoleText; @end In .mm @synthesize consoleText; The following is OK: const char *str = "abc"; self.consoleText = [NSString stringWithFormat: @"%@%@", self.consoleText, [NSString stringWithUTF8String:str]]; but the following failed: self.consoleText = [self.consoleText stringByAppendingString:[NSString stringWithUTF8String

Breakline in UIButton title

谁说胖子不能爱 提交于 2020-01-04 06:30:17
问题 in the following button is an address showed. My problem is the addresses are very long and how can i get between the two variables in the title of the button an breakline?? NSString *sitz = map.kordinate.herkunft; NSString *strasse = map.kordinate.strasse; NSString *strasseMitKomma = [strasse stringByAppendingString:@","]; NSString *fertigesSitzFeld = [strasseMitKomma stringByAppendingString:sitz]; UIButton *firmensitz = [UIButton buttonWithType:UIButtonTypeRoundedRect]; the breakline must

Which way to initialize NSString* pointer in class

我的梦境 提交于 2020-01-04 06:18:49
问题 I'm using NSString in my classes and often need to copy string value to another class. But my question is how should I initialize string in, for example init ? (value is class member and the following calls are in init) value = [NSString stringWithCString:inStrning encoding:NSASCIIStringEncoding]; or value = [[NSString alloc] initWithCString:inStrning encoding:NSASCIIStringEncoding]; What is the difference here? Does a memory allocated in 1st call released when init finishes? I'm using value

IOS Convert URL string to NSString?

a 夏天 提交于 2020-01-04 02:29:13
问题 I have a problem to convert an URL string , which I extract from XML file to NSString . The URL string look like this, it looks like odd but it is URL format. %3CTEXTFORMAT%20LEADING%3D%222%22%3E%3CP%20ALIGN%3D%22LEFT%22%3E%3CFONT%20FACE%3D%22Arial%22%20SIZE%3D%2212%22%20COLOR%3D%22%23000000%22%20LETTERSPACING%3D%220%22%20KERNING%3D%220%22%3E%u53F0%u5317%u7E2323141%u65B0%u5E97%u6C11%u6B0A%u8DEF130%u5DF714%u865F5%u6A13%3C/FONT%3E%3C/P%3E%3C/TEXTFORMAT%3E However, when I use

Problem using NSRange: Index out of bounds

爷,独闯天下 提交于 2020-01-03 19:33:22
问题 I am trying to detect website URL's in my string and then doing some attribution string stuff like bolding it etc. My regex is defined as: static NSRegularExpression *websiteRegularExpression; static inline NSRegularExpression * WebsiteRegularExpression() { if (!websiteRegularExpression) { websiteRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|]" options:NSRegularExpressionCaseInsensitive error:nil]; } return