nsstring

How to remove a null value from NSDictionary

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a JSON Feed: { "count1" = 2 ; "count2" = 2 ; idval = 40 ; level = " " ; "logo_url" = "/assets/logos/default_logo_medium.png" ; name = "Golf Club" ; "role_in_club" = Admin ; } The problem is the " " that I cannot figure out how to remove from the NSDictionary before saving it to NSUserDefaults. Please help me solve this issue. Thankyou! 回答1: Iterate through the dictionary and look for any null entries and remove them. NSMutableDictionary * prunedDictionary = [ NSMutableDictionary dictionary ]; for ( NSString * key in [

Drawing waveform with AVAssetReader

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I reading song from iPod library using assetUrl (in code it named audioUrl) I can play it many ways, I can cut it, I can make some precessing with this but... I really don't understand what I gonna do with this CMSampleBufferRef to get data for drawing waveform! I need info about peak values, how I can get it this (maybe another) way? AVAssetTrack * songTrack = [audioUrl.tracks objectAtIndex:0]; AVAssetReaderTrackOutput * output = [[AVAssetReaderTrackOutput alloc] initWithTrack:songTrack outputSettings:nil]; [reader addOutput:output];

Memory leak in NSString stringWithUTF8String

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am making a call to a database. After my call, I've found leaks in NSString. Anybody have a solution to remove it? NSString *pic = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 5)]; In above code, I found 90% leaks. I just read data from database. 回答1: please explain the question well else others can't identify your exact problem. I think you are you are assigning the value of [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 5)]; to your class object property. You can release the

Sending a JSON via POST in NSURLRequest

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a problem with sending a JSON to a Server with REST API. This is the code i use: NSString *jsonPostBody = [NSString stringWithFormat:@"'json' = '{\"user\":{\"username\":" "\"%@\"" ",\"password\":" "\"%@\"" "}}'", [username stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [password stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSData *postData = [jsonPostBody dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; NSString *apiPathParams = [NSString stringWithFormat:@"%@", @"getUser" ];

Objective-C convention to prevent “local declaration hides instance variable” warning

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using the following code ... -( id ) initWithVariableName :( NSString *) variableName withComparisonValue :( NSString *) comparisonValue { // super init self = [ super init ]; if (! self ) return nil ; // set instance variables self . mustExist = NO ; self . reverseCondition = NO ; self . regularExpression = NO ; self . variableName = variableName ; // generates warning self . comparisonValue = comparisonValue ; // generates warning return self ; } which generated the following two warnings ... Local declaration of

Losing a / when converting from NSURL to NSURLRequest

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm doing an HTTP Post in my iphone app and one of the parameters I send to the server is a URL. The problem is that when I convert from an NSURL to an NSURLRequest, the string http://www.slashdot.org becomes http:/ www.slashdot.org (one of the forward slashes is missing) is there a way around this? here is the code I'm using: NSString *host = @"example.host.com"; NSString *urlString = [NSString stringWithFormat:@"/SetLeaderUrl.json?leader_email=%@&url=%@",localEmail,urlToPublish]; NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:host

ProgressView for Downloading some files in Object-C

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: my problem is this: I want to show ProgressView for files downloading.For some reason the ProgressView gradually rises, showing how much file is already downloaded , and just immediately fills up when files are still not downloaded! What do I need to fix or how to implement it? Here is my source code: - (IBAction)download:(id)sender { // Determile cache file path NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); progressSlider.progress = 0.0; for (i=0;i<=7;i++) { //Updating progressView and

update marker position in Google Maps in IOS app

匿名 (未验证) 提交于 2019-12-03 01:44:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to update the marker position on the drawn route till it reaches its destination.Now here is the code for accessing server: NSURL * url = [ NSURL URLWithString :[ NSString stringWithFormat :@ "https://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=-32.90,151.80&waypoints=-33.30,151.50&alternatives=true" , marker . position . latitude , marker . position . longitude ]]; After this I am just updating the position of marker overtime I calculate the new position.The question arises how I am getting the new position

UInt8 XOR'd array result to NSString conversion returns nil every time

匿名 (未验证) 提交于 2019-12-03 01:44:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm having issues working with iOS Swift 2.0 to perform an XOR on a [UInt8] and convert the XORd result to a String. I'm having to interface with a crude server that wants to do simple XOR encryption with a predefined array of UInt8 values and return that result as a String. Using iOS Swift 2.0 Playground, create the following array: let xorResult : [ UInt8 ] = [ 24 , 48 , 160 , 212 ] // XORd result let result = NSString ( bytes : xorResult , length : xorResult . count , encoding : NSUTF8StringEncoding ) The result is always nil.

How to play multiple audio files in a row with AVAudioPlayer?

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have 5 songs in my app that I would like to play one after the other with AVAudioPlayer. Are there any examples of this? How can I accomplish this? Any example code would be greatly appreciated! Thanks! 回答1: For every song you want to make make a single AVPlayer . NSURL *url = [NSURL URLWithString:pathToYourFile]; AVPlayer *audioPlayer = [[AVPlayer alloc] initWithURL:url]; [audioPlayer play]; You can get a Notification when the player ends. Check AVPlayerItemDidPlayToEndTimeNotification when setting up the player: audioPlayer