Search Results

Search found 2356 results on 95 pages for 'nsstring'.

Page 1/95 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Encoded nsstring becomes invalid, "normal" nsstring remains

    - by shoreline
    I'm running into a problem with a string that contains encoded characters. Specifically, if the string has encoded characters it eventually becomes invalid while a "normal" string will not. in the .h file: @interface DirViewController : TTThumbsViewController <UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate> { NSString *sourceFolder; NSString *encodedSourceFolder; } @property (nonatomic, retain) NSString *sourceFolder; @property (nonatomic, retain) NSString *encodedSourceFolder; in the .m file: - (id)initWithFolder:(NSString*)folder query:(NSDictionary*)query { if (self = [super init]) { sourceFolder = folder; } return self; } Up to now everything seems to run as expected. In viewDidLoad I have the following: sourceFolderCopy = [self urlEncodeValue:(sourceFolder)]; //I also have this button, which I'll refer to later: UIBarButtonItem *importButton = [[UIBarButtonItem alloc] initWithTitle:@"Import/Export" style:UIBarButtonItemStyleBordered target:self action:@selector(importFiles:)]; self.navigationItem.rightBarButtonItem = importButton; Which uses the following method to encode the string (if it has characters I want encoded): - (NSString *)urlEncodeValue:(NSString *)str { NSString *result = (NSString *) CFURLCreateStringByAddingPercentEscapes (kCFAllocatorDefault, (CFStringRef)str, NULL, CFSTR(":/?#[]@!$&’()*+,;="), kCFStringEncodingUTF8); return [result autorelease]; } If I NSLog result, I get the expected values. If the string has characters like a white space, I get a string with encoding. If the string doesn't have any characters that need to be encoded, it just gives me the original string. I have a button on the nav bar which begins an image import process by opening an action sheet. Once the method for the action sheet starts, my string is invalid - but only if it contains encoded characters. If it is just a "normal" string, everything is fine and acts as expected. Am I off on my encoding? At first I thought it might be a memory problem but I can't figure out why that would affect only encoded strings. Here's where the action sheet is defined (and the first place I can see the encoded string becoming invalid) the NSLog statements are where it crashes: - (IBAction)importFiles:(id)sender { NSLog(@"logging encodedSF from import files:"); NSLog(@"%@",encodedSourceFolder);//crashes right here NSLog(@"%@",sourceFolder); if (shouldNavigate == NO) { NSString *msg = nil; msg = @"It is not possible to import or export images while in image selection mode."; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unable to Import/Export" message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; [msg release]; } else{ UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"What would you like to do?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Import Photos (Picker)", @"Export Photos", nil, nil]; [actionSheet showInView:self.view]; [actionSheet release]; } } I don't get any crash errors going to the console. By using breakpoints I was able to see that the encodedSourceFolder is invalid in the action sheet method.

    Read the article

  • NSString drawAtPoint Crash on the iPhone (NSString drawAtPoint)

    - by Kyle
    Hey. I have a very simple text output to buffer system which will crash randomly. It will be fine for DAYS, then sometimes it'll crash a few times in a few minutes. The callstack is almost exactly the same for other guys who use higher level controls: http://discussions.apple.com/thread.jspa?messageID=7949746 http://stackoverflow.com/questions/1978997/iphone-app-crashed-assertion-failed-function-evictglyphentryfromstrike-file It crashes at the line (below as well in drawTextToBuffer()): [nsString drawAtPoint:CGPointMake(0, 0) withFont:clFont]; I have the same call of "evict_glyph_entry_from_cache" with the abort calls immediately following it. Apparently it happens to other people. I can say that my NSString* is perfectly fine at the time of the crash. I can read the text from the debugger just fine. static CGColorSpaceRef curColorSpace; static CGContextRef myContext; static float w, h; static int iFontSize; static NSString* sFontName; static UIFont* clFont; static int iLineHeight; unsigned long* txb; /* 256x256x4 Buffer */ void selectFont(int iSize, NSString* sFont) { iFontSize = iSize; clFont = [UIFont fontWithName:sFont size:iFontSize]; iLineHeight = (int)(ceil([clFont capHeight])); } void initText() { w = 256; h = 256; txb = (unsigned long*)malloc_(w * h * 4); curColorSpace = CGColorSpaceCreateDeviceRGB(); myContext = CGBitmapContextCreate(txb, w, h, 8, w * 4, curColorSpace, kCGImageAlphaPremultipliedLast); selectFont(12, @"Helvetica"); } void drawTextToBuffer(NSString* nsString) { CGContextSaveGState(myContext); CGContextSetRGBFillColor(myContext, 1, 1, 1, 1); UIGraphicsPushContext(myContext); /* This line will crash. It crashes even with constant Strings.. At the time of the crash, the pointer to nsString is perfectly fine. The data looks fine! */ [nsString drawAtPoint:CGPointMake(0, 0) withFont:clFont]; UIGraphicsPopContext(); CGContextRestoreGState(myContext); } It will happen with other non-unicode supporting methods as well such as CGContextShowTextAtPoint(); the callstack is similar with that as well. Is this any kind of known issue with the iPhone? Or, perhaps, can something outside of this cause be causing an exception in this particular call (drawAtPoint)?

    Read the article

  • NSMutableArray to NSString and Passing NSString to Another View IOS5.1

    - by Space Dust
    I have an NSMutableArray of names. I want the pass the data (selected name) inside of NSMutableArray as text to another view's label. FriendsController.m: - (void)viewDidLoad { [super viewDidLoad]; arrayOfNames=[[NSMutableArray alloc] init]; arrayOfIDs=[[NSMutableArray alloc] init]; userName=[[NSString alloc] init]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { long long fbid = [[arrayOfIDs objectAtIndex:indexPath.row]longLongValue]; NSString *user=[NSString stringWithFormat:@"%llu/picture",fbid]; [facebook requestWithGraphPath:user andDelegate:self]; userName=[NSString stringWithFormat:@"%@",[arrayOfNames objectAtIndex:indexPath.row]]; FriendDetail *profileDetailName = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil]; profileDetailName.nameString=userName; [profileDetailName release]; } - (void)request:(FBRequest *)request didLoad:(id)result { if ([result isKindOfClass:[NSData class]]) { transferImage = [[UIImage alloc] initWithData: result]; FriendDetail *profileDetailPicture = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil]; [profileDetailPicture view]; profileDetailPicture.profileImage.image= transferImage; profileDetailPicture.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:profileDetailPicture animated:YES]; [profileDetailPicture release]; } } In FriendDetail.h NSString nameString; IBOutlet UILabel *profileName; @property (nonatomic, retain) UILabel *profileName; @property (nonatomic, retain) NSString *nameString; In FriendDetail.m - (void)viewDidLoad { [super viewDidLoad]; profileName.text=nameString; } nameString in second controller(FriendDetail) returns nil. When i set a breakpoint in firstcontroller I see the string inside of nameString is correct but after that it returns to nil somehow.

    Read the article

  • UITableView's NSString memory leak on iphone when encoding with NSUTF8StringEncoding

    - by vince
    my UITableView have serious memory leak problem only when the NSString is NOT encoding with NSASCIIStringEncoding. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"cell"; UILabel *textLabel1; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; textLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(105, 6, 192, 22)]; textLabel1.tag = 1; textLabel1.textColor = [UIColor whiteColor]; textLabel1.backgroundColor = [UIColor blackColor]; textLabel1.numberOfLines = 1; textLabel1.adjustsFontSizeToFitWidth = NO; [textLabel1 setFont:[UIFont boldSystemFontOfSize:19]]; [cell.contentView addSubview:textLabel1]; [textLabel1 release]; } else { textLabel1 = (UILabel *)[cell.contentView viewWithTag:1]; } NSDictionary *tmpDict = [listOfInfo objectForKey:[NSString stringWithFormat:@"%@",indexPath.row]]; textLabel1.text = [tmpDict objectForKey:@"name"]; return cell; } -(void) readDatabase { NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; databasePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",myDB]]; sqlite3 *database; if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { const char sqlStatement = [[NSString stringWithFormat:@"select id,name from %@ order by orderid",myTable] UTF8String]; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { while(sqlite3_step(compiledStatement) == SQLITE_ROW) { NSString *tmpid = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]; NSString *tmpname = [NSString stringWithCString:(const char *)sqlite3_column_text(compiledStatement, 1) encoding:NSUTF8StringEncoding]; [listOfInfo setObject:[[NSMutableDictionary alloc] init] forKey:tmpid]; [[listOfInfo objectForKey:tmpid] setObject:[NSString stringWithFormat:@"%@", tmpname] forKey:@"name"]; } } sqlite3_finalize(compiledStatement); debugNSLog(@"sqlite closing"); } sqlite3_close(database); } when i change the line NSString *tmpname = [NSString stringWithCString:(const char *)sqlite3_column_text(compiledStatement, 1) encoding:NSUTF8StringEncoding]; to NSString *tmpname = [NSString stringWithCString:(const char *)sqlite3_column_text(compiledStatement, 1) encoding:NSASCIIStringEncoding]; the memory leak is gone i tried NSString stringWithUTF8String and it still leak. i've also tried: NSData *dtmpname = [NSData dataWithBytes:sqlite3_column_blob(compiledStatement, 1) length:sqlite3_column_bytes(compiledStatement, 1)]; NSString *tmpname = [[[NSString alloc] initWithData:dtmpname encoding:NSUTF8StringEncoding] autorelease]; and the problem remains, the leak occur when u start scrolling the tableview. i've actually tried other encoding and it seems that only NSASCIIStringEncoding works(no memory leak) any idea how to get rid of this problem?

    Read the article

  • Need help with NSString that returns (null)

    - by Guy Dor
    Hi, I have a problem with my string that returns (null) Here's the MainViewController: NSString *leftWebViewUrl; MainViewController *mainViewController; @property (nonatomic, retain) NSString *leftWebViewUrl; @property (nonatomic, retain) MainViewController *mainViewController; leftWebViewUrl = [NSString stringWithString:leftWebView.request.URL.absoluteString]; leftSharingViewController.leftWebViewUrl = leftWebViewUrl; Here's the leftSharingViewController (just the NSString declaration) NSString *leftWebViewUrl; @property (nonatomic, retain) NSString *leftWebViewUrl; From some reason I get (null) Thanks

    Read the article

  • ios - UISegmentedControl and NSString

    - by Jeff Kranenburg
    Hello I have the following code: if(_deviceSegmentCntrl.selectedSegmentIndex == 0) { deviceOne = [[NSString alloc] initWithFormat:@"string01"]; } if(_deviceSegmentCntrl.selectedSegmentIndex == 1) { deviceOne = [[NSString alloc] initWithFormat:@"string02"]; } if(_deviceSegmentCntrl.selectedSegmentIndex == 2) { deviceOne = [[NSString alloc] initWithFormat:@"string03"]; } NSString *deviceType = [[NSString alloc] initWithFormat:_deviceSegmentCntrl]; I am wanting to have the NSString output the string the user selects in the segmented control. How do I append the initWithFormat: so that it reflects the chosen index? Cheers

    Read the article

  • NSString stringWithFormat swizzled to allow missing format numbered args

    - by coneybeare
    Based on this SO question asked a few hours ago, I have decided to implement a swizzled method that will allow me to take a formatted NSString as the format arg into stringWithFormat, and have it not break when omitting one of the numbered arg references (%1$@, %2$@) I have it working, but this is the first copy, and seeing as this method is going to be potentially called hundreds of thousands of times per app run, I need to bounce this off of some experts to see if this method has any red flags, major performance hits, or optimizations #define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int)) @implementation NSString (UAFormatOmissions) + (id)uaStringWithFormat:(NSString *)format, ... { if (format != nil) { va_list args; va_start(args, format); // $@ is an ordered variable (%1$@, %2$@...) if ([format rangeOfString:@"$@"].location == NSNotFound) { //call apples method NSString *s = [[[NSString alloc] initWithFormat:format arguments:args] autorelease]; va_end(args); return s; } NSMutableArray *newArgs = (NSMutableArray *)[NSMutableArray arrayWithCapacity:NUMARGS(args)]; id arg = nil; int i = 1; while (arg = va_arg(args, id)) { NSString *f = (NSString *)[NSString stringWithFormat:@"%%%d\$\@", i]; i++; if ([format rangeOfString:f].location == NSNotFound) continue; else [newArgs addObject:arg]; } va_end(args); char *newArgList = (char *)malloc(sizeof(id) * [newArgs count]); [newArgs getObjects:(id *)newArgList]; NSString* result = [[[NSString alloc] initWithFormat:format arguments:newArgList] autorelease]; free(newArgList); return result; } return nil; } The basic algorithm is: search the format string for the %1$@, %2$@ variables by searching for %@ if not found, call the normal stringWithFormat and return else, loop over the args if the format has a position variable (%i$@) for position i, add the arg to the new arg array else, don't add the arg take the new arg array, convert it back into a va_list, and call initWithFormat:arguments: to get the correct string. The idea is that I would run all [NSString stringWithFormat:] calls through this method instead. This might seem unnecessary to many, but click on to the referenced SO question (first line) to see examples of why I need to do this. Ideas? Thoughts? Better implementations? Better Solutions?

    Read the article

  • Where is my object allocation and memory leak in this iPhone/objective C code?

    - by Spottswoode
    Hello, I'm still a rookie when it comes to this programming gig and was wondering if someone could help me smooth out this code. Functionally, the code works great and does what I need it to do. But when I run the performance tool the allocation graph peaks, the CPU load is high, there's a leak(s), and I've also confirmed when running on my iPhone it seems noticeably slower then the rest of the components in my app. I'd appreciate any advice/tips/help anyone could give me. :) Thanks in advance! .h file // // Time_CalculatorViewController.h // Time Calculator // // Created by Adam Soloway on 2/19/10. // Copyright Legacy Pilots 2010. All rights reserved. // #import <UIKit/UIKit.h> @interface Time_CalculatorViewController : UIViewController { //BOOL moveViewUp; //CGFloat scrollAmount; IBOutlet UILabel *hoursLabel; IBOutlet UILabel *minutesLabel; IBOutlet UILabel *hoursDecimalLabel; IBOutlet UILabel *minutesDecimalLabel; IBOutlet UILabel *errorLabel; IBOutlet UITextField *minTextField1; IBOutlet UITextField *minTextField2; IBOutlet UITextField *minTextField3; IBOutlet UITextField *minTextField4; IBOutlet UITextField *minTextField5; IBOutlet UITextField *minTextField6; IBOutlet UITextField *minTextField7; IBOutlet UITextField *minTextField8; IBOutlet UITextField *minTextField9; IBOutlet UITextField *minTextField10; IBOutlet UITextField *hourTextField1; IBOutlet UITextField *hourTextField2; IBOutlet UITextField *hourTextField3; IBOutlet UITextField *hourTextField4; IBOutlet UITextField *hourTextField5; IBOutlet UITextField *hourTextField6; IBOutlet UITextField *hourTextField7; IBOutlet UITextField *hourTextField8; IBOutlet UITextField *hourTextField9; IBOutlet UITextField *hourTextField10; IBOutlet UIButton *resetAll; NSString *minutesString1; NSString *minutesString2; NSString *minutesString3; NSString *minutesString4; NSString *minutesString5; NSString *minutesString6; NSString *minutesString7; NSString *minutesString8; NSString *minutesString9; NSString *minutesString10; NSString *hoursString1; NSString *hoursString2; NSString *hoursString3; NSString *hoursString4; NSString *hoursString5; NSString *hoursString6; NSString *hoursString7; NSString *hoursString8; NSString *hoursString9; NSString *hoursString10; int hourDecimalNumber; int totalTime; int leftOverMinutes; int minuteNumber1; int minuteNumber2; int minuteNumber3; int minuteNumber4; int minuteNumber5; int minuteNumber6; int minuteNumber7; int minuteNumber8; int minuteNumber9; int minuteNumber10; int hourNumber1; int hourNumber2; int hourNumber3; int hourNumber4; int hourNumber5; int hourNumber6; int hourNumber7; int hourNumber8; int hourNumber9; int hourNumber10; } //- (void)scrollTheView:(BOOL)movedUp; - (void)calculateTime; - (IBAction)resetAllValues; @end .m file // // Time_CalculatorViewController.m // Time Calculator // // Created by Adam Soloway on 2/19/10. // Copyright Legacy Pilots 2010. All rights reserved. // #import "Time_CalculatorViewController.h" @implementation Time_CalculatorViewController - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if( minTextField1.editing || minTextField2.editing || minTextField3.editing || minTextField4.editing || minTextField5.editing || minTextField6.editing || minTextField7.editing || minTextField8.editing || minTextField9.editing || minTextField10.editing || hourTextField1.editing || hourTextField2.editing || hourTextField3.editing || hourTextField4.editing || hourTextField5.editing || hourTextField6.editing || hourTextField7.editing || hourTextField8.editing || hourTextField9.editing || hourTextField10.editing) { [minTextField1 resignFirstResponder]; [minTextField2 resignFirstResponder]; [minTextField3 resignFirstResponder]; [minTextField4 resignFirstResponder]; [minTextField5 resignFirstResponder]; [minTextField6 resignFirstResponder]; [minTextField7 resignFirstResponder]; [minTextField8 resignFirstResponder]; [minTextField9 resignFirstResponder]; [minTextField10 resignFirstResponder]; [hourTextField1 resignFirstResponder]; [hourTextField2 resignFirstResponder]; [hourTextField3 resignFirstResponder]; [hourTextField4 resignFirstResponder]; [hourTextField5 resignFirstResponder]; [hourTextField6 resignFirstResponder]; [hourTextField7 resignFirstResponder]; [hourTextField8 resignFirstResponder]; [hourTextField9 resignFirstResponder]; [hourTextField10 resignFirstResponder]; [self calculateTime]; //if (moveViewUp) [self scrollTheView:NO]; } [super touchesBegan:touches withEvent:event]; } /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [minutesString1 release]; [minutesString2 release]; [minutesString3 release]; [minutesString4 release]; [minutesString5 release]; [minutesString6 release]; [minutesString7 release]; [minutesString8 release]; [minutesString9 release]; [minutesString10 release]; [hoursString1 release]; [hoursString2 release]; [hoursString3 release]; [hoursString4 release]; [hoursString5 release]; [hoursString6 release]; [hoursString7 release]; [hoursString8 release]; [hoursString9 release]; [hoursString10 release]; [super dealloc]; } -(BOOL)textFieldShouldReturn:(UITextField *)theTextField { //[minTextField10 resignFirstResponder]; //if (moveViewUp) [self scrollTheView:NO]; [self calculateTime]; return YES; } - (IBAction)resetAllValues { minTextField1.text = 0; minTextField2.text = 0; minTextField3.text = 0; minTextField4.text = 0; minTextField5.text = 0; minTextField6.text = 0; minTextField7.text = 0; minTextField8.text = 0; minTextField9.text = 0; minTextField10.text = 0; hourTextField1.text = 0; hourTextField2.text = 0; hourTextField3.text = 0; hourTextField4.text = 0; hourTextField5.text = 0; hourTextField6.text = 0; hourTextField7.text = 0; hourTextField8.text = 0; hourTextField9.text = 0; hourTextField10.text = 0; totalTime = 0; leftOverMinutes = 0; hoursLabel.text = [NSString stringWithFormat:@"0"]; hourDecimalNumber = 0; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; minutesDecimalLabel.text = [NSString stringWithFormat:@"0"]; self.calculateTime; } - (void)calculateTime { minutesString1 = minTextField1.text; minutesString2 = minTextField2.text; minutesString3 = minTextField3.text; minutesString4 = minTextField4.text; minutesString5 = minTextField5.text; minutesString6 = minTextField6.text; minutesString7 = minTextField7.text; minutesString8 = minTextField8.text; minutesString9 = minTextField9.text; minutesString10 = minTextField10.text; hoursString1 = hourTextField1.text; hoursString2 = hourTextField2.text; hoursString3 = hourTextField3.text; hoursString4 = hourTextField4.text; hoursString5 = hourTextField5.text; hoursString6 = hourTextField6.text; hoursString7 = hourTextField7.text; hoursString8 = hourTextField8.text; hoursString9 = hourTextField9.text; hoursString10 = hourTextField10.text; minuteNumber1 = [minutesString1 intValue]; minuteNumber2 = [minutesString2 intValue]; minuteNumber3 = [minutesString3 intValue]; minuteNumber4 = [minutesString4 intValue]; minuteNumber5 = [minutesString5 intValue]; minuteNumber6 = [minutesString6 intValue]; minuteNumber7 = [minutesString7 intValue]; minuteNumber8 = [minutesString8 intValue]; minuteNumber9 = [minutesString9 intValue]; minuteNumber10 = [minutesString10 intValue]; hourNumber1 = ([hoursString1 intValue] * 60); hourNumber2 = ([hoursString2 intValue] * 60); hourNumber3 = ([hoursString3 intValue] * 60); hourNumber4 = ([hoursString4 intValue] * 60); hourNumber5 = ([hoursString5 intValue] * 60); hourNumber6 = ([hoursString6 intValue] * 60); hourNumber7 = ([hoursString7 intValue] * 60); hourNumber8 = ([hoursString8 intValue] * 60); hourNumber9 = ([hoursString9 intValue] * 60); hourNumber10 = ([hoursString10 intValue] * 60); totalTime = (hourNumber1 + hourNumber2 +hourNumber3 +hourNumber4 +hourNumber5 +hourNumber6 +hourNumber7 +hourNumber8 +hourNumber9 +hourNumber10 + minuteNumber1 + minuteNumber2 + minuteNumber3 + minuteNumber4 + minuteNumber5 +minuteNumber6 + minuteNumber7 + minuteNumber8 + minuteNumber9 + minuteNumber10); if (totalTime <= 59) { leftOverMinutes = totalTime; hoursLabel.text = [NSString stringWithFormat:@"0"]; hourDecimalNumber = 0; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >59 && totalTime <= 119){ leftOverMinutes = totalTime - 60; hoursLabel.text = [NSString stringWithFormat:@"1"]; hourDecimalNumber = 1; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >119 && totalTime <= 179){ leftOverMinutes = totalTime - 120; hoursLabel.text = [NSString stringWithFormat:@"2"]; hourDecimalNumber = 2; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >179 && totalTime <= 239){ leftOverMinutes = totalTime - 180; hoursLabel.text = [NSString stringWithFormat:@"3"]; hourDecimalNumber = 3; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >239 && totalTime <= 299){ leftOverMinutes = totalTime - 240; hoursLabel.text = [NSString stringWithFormat:@"4"]; hourDecimalNumber = 4; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >299 && totalTime <= 359){ leftOverMinutes = totalTime - 300; hoursLabel.text = [NSString stringWithFormat:@"5"]; hourDecimalNumber = 5; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >359 && totalTime <= 419){ leftOverMinutes = totalTime - 360; hoursLabel.text = [NSString stringWithFormat:@"6"]; hourDecimalNumber = 6; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >419 && totalTime <= 479){ leftOverMinutes = totalTime - 420; hoursLabel.text = [NSString stringWithFormat:@"7"]; hourDecimalNumber = 7; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >479 && totalTime <= 539){ leftOverMinutes = totalTime - 480; hoursLabel.text = [NSString stringWithFormat:@"8"]; hourDecimalNumber = 8; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >539 && totalTime <= 599){ leftOverMinutes = totalTime - 540; hoursLabel.text = [NSString stringWithFormat:@"9"]; hourDecimalNumber = 9; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >599 && totalTime <= 659){ leftOverMinutes = totalTime - 600; hoursLabel.text = [NSString stringWithFormat:@"10"]; hourDecimalNumber = 10; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >659 && totalTime <= 719){ leftOverMinutes = totalTime - 660; hoursLabel.text = [NSString stringWithFormat:@"11"]; hourDecimalNumber = 11; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >719 && totalTime <= 779){ leftOverMinutes = totalTime - 720; hoursLabel.text = [NSString stringWithFormat:@"12"]; hourDecimalNumber = 12; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >779 && totalTime <= 839){ leftOverMinutes = totalTime - 780; hoursLabel.text = [NSString stringWithFormat:@"13"]; hourDecimalNumber = 13; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >839 && totalTime <= 899){ leftOverMinutes = totalTime - 840; hoursLabel.text = [NSString stringWithFormat:@"14"]; hourDecimalNumber = 14; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >899 && totalTime <= 959){ leftOverMinutes = totalTime - 900; hoursLabel.text = [NSString stringWithFormat:@"15"]; hourDecimalNumber = 15; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >959 && totalTime <= 1019){ leftOverMinutes = totalTime - 960; hoursLabel.text = [NSString stringWithFormat:@"16"]; hourDecimalNumber = 16; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1019 && totalTime <= 1079){ leftOverMinutes = totalTime - 1020; hoursLabel.text = [NSString stringWithFormat:@"17"]; hourDecimalNumber = 17; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1079 && totalTime <= 1139){ leftOverMinutes = totalTime - 1080; hoursLabel.text = [NSString stringWithFormat:@"18"]; hourDecimalNumber = 18; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1139 && totalTime <= 1199){ leftOverMinutes = totalTime - 1140; hoursLabel.text = [NSString stringWithFormat:@"19"]; hourDecimalNumber = 19; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1199 && totalTime <= 1259){ leftOverMinutes = totalTime - 1200; hoursLabel.text = [NSString stringWithFormat:@"20"]; hourDecimalNumber = 20; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1259 && totalTime <= 1319){ leftOverMinutes = totalTime - 1260; hoursLabel.text = [NSString stringWithFormat:@"21"]; hourDecimalNumber = 21; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1319 && totalTime <= 1379){ leftOverMinutes = totalTime - 1320; hoursLabel.text = [NSString stringWithFormat:@"22"]; hourDecimalNumber = 22; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1379 && totalTime <= 1439){ leftOverMinutes = totalTime - 1380; hoursLabel.text = [NSString stringWithFormat:@"23"]; hourDecimalNumber = 23; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1439 && totalTime <= 1499){ leftOverMinutes = totalTime - 1440; hoursLabel.text = [NSString stringWithFormat:@"24"]; hourDecimalNumber = 24; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1499 && totalTime <= 1559){ leftOverMinutes = totalTime - 1500; hoursLabel.text = [NSString stringWithFormat:@"25"]; hourDecimalNumber = 25; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1559 && totalTime <= 1619){ leftOverMinutes = totalTime - 1560; hoursLabel.text = [NSString stringWithFormat:@"26"]; hourDecimalNumber = 26; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1619 && totalTime <= 1679){ leftOverMinutes = totalTime - 1620; hoursLabel.text = [NSString stringWithFormat:@"27"]; hourDecimalNumber = 27; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1679 && totalTime <= 1739){ leftOverMinutes = totalTime - 1680; hoursLabel.text = [NSString stringWithFormat:@"28"]; hourDecimalNumber = 28; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1739 && totalTime <= 1799){ leftOverMinutes = totalTime - 1740; hoursLabel.text = [NSString stringWithFormat:@"29"]; hourDecimalNumber = 29; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1799 && totalTime <= 1859){ leftOverMinutes = totalTime - 1800; hoursLabel.text = [NSString stringWithFormat:@"30"]; hourDecimalNumber = 30; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1859){ hoursLabel.text = [NSString stringWithFormat:@"Error"]; hoursDecimalLabel.text = [NSString stringWithFormat:@"Error"]; errorLabel.hidden = FALSE; } //Minutes Label if (leftOverMinutes < 10) { minutesLabel.text = [NSString stringWithFormat:@"0%d", leftOverMinutes]; } else minutesLabel.text = [NSString stringWithFormat:@"%d", leftOverMinutes]; //Minutes Decimal Label if (leftOverMinutes >=0 && leftOverMinutes <=2) { minutesDecimalLabel.text = [NSString stringWithFormat:@"0"]; } else if (leftOverMinutes >=3 && leftOverMinutes <=8){ minutesDecimalLabel.text = [NSString stringWithFormat:@"1"]; } else if (leftOverMinutes >=9 && leftOverMinutes <=14){ minutesDecimalLabel.text = [NSString stringWithFormat:@"2"]; } else if (leftOverMinutes >=15 && leftOverMinutes <=20){ minutesDecimalLabel.text = [NSString stringWithFormat:@"3"]; } else if (leftOverMinutes >=21 && leftOverMinutes <=26){ minutesDecimalLabel.text = [NSString stringWithFormat:@"4"]; } else if (leftOverMinutes >=27 && leftOverMinutes <=32){ minutesDecimalLabel.text = [NSString stringWithFormat:@"5"]; } else if (leftOverMinutes >=33 && leftOverMinutes <=38){ minutesDecimalLabel.text = [NSString stringWithFormat:@"6"]; } else if (leftOverMinutes >=39 && leftOverMinutes <=44){ minutesDecimalLabel.text = [NSString stringWithFormat:@"7"]; } else if (leftOverMinutes >=45 && leftOverMinutes <=50){ minutesDecimalLabel.text = [NSString stringWithFormat:@"8"]; } else if (leftOverMinutes >=51 && leftOverMinutes <=56){ minutesDecimalLabel.text = [NSString stringWithFormat:@"9"]; } else if (leftOverMinutes >=57 && leftOverMinutes <=60){ minutesDecimalLabel.text = [NSString stringWithFormat:@"0"]; hourDecimalNumber = hourDecimalNumber + 1; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; } } @end

    Read the article

  • Adding Custom Object to NSMutableArray

    - by Fozz
    Developing ios app. I have an object class Product.h and .m respectively along with my picker class which implements my vehicle selection to match products to vehicle. The files product.h #import <Foundation/Foundation.h> @interface Product : NSObject { } @property (nonatomic, retain) NSString *iProductID; @property (nonatomic, retain) NSString *vchProductCode; @property (nonatomic, retain) NSString *vchPriceCode; @property (nonatomic, retain) NSString *vchHitchUPC; @property (nonatomic, retain) NSString *mHitchList; @property (nonatomic, retain) NSString *mHitchMap; @property (nonatomic, retain) NSString *fShippingWeight; @property (nonatomic, retain) NSString *vchWC; @property (nonatomic, retain) NSString *vchCapacity; @property (nonatomic, retain) NSString *txtNote1; @property (nonatomic, retain) NSString *txtNote2; @property (nonatomic, retain) NSString *txtNote3; @property (nonatomic, retain) NSString *txtNote4; @property (nonatomic, retain) NSString *vchDrilling; @property (nonatomic, retain) NSString *vchUPCList; @property (nonatomic, retain) NSString *vchExposed; @property (nonatomic, retain) NSString *vchShortDesc; @property (nonatomic, retain) NSString *iVehicleID; @property (nonatomic, retain) NSString *iProductClassID; @property (nonatomic, retain) NSString *dtDateMod; @property (nonatomic, retain) NSString *txtBullet1; @property (nonatomic, retain) NSString *txtBullet2; @property (nonatomic, retain) NSString *txtBullet3; @property (nonatomic, retain) NSString *txtBullet4; @property (nonatomic, retain) NSString *txtBullet5; @property (nonatomic, retain) NSString *iUniqueIdentifier; @property (nonatomic, retain) NSString *dtDateLastTouched; @property (nonatomic, retain) NSString *txtNote6; @property (nonatomic, retain) NSString *InstallTime; @property (nonatomic, retain) NSString *SGID; @property (nonatomic, retain) NSString *CURTID; @property (nonatomic, retain) NSString *SGRetail; @property (nonatomic, retain) NSString *SGMemPrice; @property (nonatomic, retain) NSString *InstallSheet; @property (nonatomic, retain) NSString *mHitchJobber; @property (nonatomic, retain) NSString *CatID; @property (nonatomic, retain) NSString *ParentID; -(id) initWithDict:(NSDictionary *)dic; -(NSString *) description; @end Product implementation .m #import "Product.h" @implementation Product @synthesize iProductID; @synthesize vchProductCode; @synthesize vchPriceCode; @synthesize vchHitchUPC; @synthesize mHitchList; @synthesize mHitchMap; @synthesize fShippingWeight; @synthesize vchWC; @synthesize vchCapacity; @synthesize txtNote1; @synthesize txtNote2; @synthesize txtNote3; @synthesize txtNote4; @synthesize vchDrilling; @synthesize vchUPCList; @synthesize vchExposed; @synthesize vchShortDesc; @synthesize iVehicleID; @synthesize iProductClassID; @synthesize dtDateMod; @synthesize txtBullet1; @synthesize txtBullet2; @synthesize txtBullet3; @synthesize txtBullet4; @synthesize txtBullet5; @synthesize iUniqueIdentifier; @synthesize dtDateLastTouched; @synthesize txtNote6; @synthesize InstallTime; @synthesize SGID; @synthesize CURTID; @synthesize SGRetail; @synthesize SGMemPrice; @synthesize InstallSheet; @synthesize mHitchJobber; @synthesize CatID; @synthesize ParentID; -(id) initWithDict:(NSDictionary *)dic { [super init]; //Initialize all variables self.iProductID = [[NSString alloc] initWithString:[dic objectForKey:@"iProductID"]]; self.vchProductCode = [[NSString alloc] initWithString:[dic objectForKey:@"vchProductCode"]]; self.vchPriceCode = [[NSString alloc] initWithString:[dic objectForKey:@"vchPriceCode"]]; self.vchHitchUPC = [[NSString alloc] initWithString:[dic objectForKey:@"vchHitchUPC"]]; self.mHitchList = [[NSString alloc] initWithString:[dic objectForKey:@"mHitchList"]]; self.mHitchMap = [[NSString alloc] initWithString:[dic objectForKey:@"mHitchMap"]]; self.fShippingWeight = [[NSString alloc] initWithString:[dic objectForKey:@"fShippingWeight"]]; self.vchWC = [[NSString alloc] initWithString:[dic objectForKey:@"vchWC"]]; self.vchCapacity = [[NSString alloc] initWithString:[dic objectForKey:@"vchCapacity"]]; self.txtNote1 = [[NSString alloc] initWithString:[dic objectForKey:@"txtNote1"]]; self.txtNote2 = [[NSString alloc] initWithString:[dic objectForKey:@"txtNote2"]]; self.txtNote3 = [[NSString alloc] initWithString:[dic objectForKey:@"txtNote3"]]; self.txtNote4 = [[NSString alloc] initWithString:[dic objectForKey:@"txtNote4"]]; self.vchDrilling = [[NSString alloc] initWithString:[dic objectForKey:@"vchDrilling"]]; self.vchUPCList = [[NSString alloc] initWithString:[dic objectForKey:@"vchUPCList"]]; self.vchExposed = [[NSString alloc] initWithString:[dic objectForKey:@"vchExposed"]]; self.vchShortDesc = [[NSString alloc] initWithString:[dic objectForKey:@"vchShortDesc"]]; self.iVehicleID = [[NSString alloc] initWithString:[dic objectForKey:@"iVehicleID"]]; self.iProductClassID = [[NSString alloc] initWithString:[dic objectForKey:@"iProductClassID"]]; self.dtDateMod = [[NSString alloc] initWithString:[dic objectForKey:@"dtDateMod"]]; self.txtBullet1 = [[NSString alloc] initWithString:[dic objectForKey:@"txtBullet1"]]; self.txtBullet2 = [[NSString alloc] initWithString:[dic objectForKey:@"txtBullet2"]]; self.txtBullet3 = [[NSString alloc] initWithString:[dic objectForKey:@"txtBullet3"]]; self.txtBullet4 = [[NSString alloc] initWithString:[dic objectForKey:@"txtBullet4"]]; self.txtBullet5 = [[NSString alloc] initWithString:[dic objectForKey:@"txtBullet5"]]; self.iUniqueIdentifier = [[NSString alloc] initWithString:[dic objectForKey:@"iUniqueIdentifier"]]; self.dtDateLastTouched = [[NSString alloc] initWithString:[dic objectForKey:@"dtDateLastTouched"]]; self.txtNote6 = [[NSString alloc] initWithString:[dic objectForKey:@"txtNote6"]]; self.InstallTime = [[NSString alloc] initWithString:[dic objectForKey:@"InstallTime"]]; self.SGID = [[NSString alloc] initWithString:[dic objectForKey:@"SGID"]]; self.CURTID = [[NSString alloc] initWithString:[dic objectForKey:@"CURTID"]]; self.SGRetail = [[NSString alloc] initWithString:[dic objectForKey:@"SGRetail"]]; self.SGMemPrice = [[NSString alloc] initWithString:[dic objectForKey:@"SGMemPrice"]]; self.InstallSheet = [[NSString alloc] initWithString:[dic objectForKey:@"InstallSheet"]]; self.mHitchJobber = [[NSString alloc] initWithString:[dic objectForKey:@"mHitchJobber"]]; self.CatID = [[NSString alloc] initWithString:[dic objectForKey:@"CatID"]]; self.ParentID = [[NSString alloc] initWithString:[dic objectForKey:@"ParentID"]]; return self; } -(NSString *) description { return [NSString stringWithFormat:@"iProductID = %@\n vchProductCode = %@\n vchPriceCode = %@\n vchHitchUPC = %@\n mHitchList = %@\n mHitchMap = %@\n fShippingWeight = %@\n vchWC = %@\n vchCapacity = %@\n txtNote1 = %@\n txtNote2 = %@\n txtNote3 = %@\n txtNote4 = %@\n vchDrilling = %@\n vchUPCList = %@\n vchExposed = %@\n vchShortDesc = %@\n iVehicleID = %@\n iProductClassID = %@\n dtDateMod = %@\n txtBullet1 = %@\n txtBullet2 = %@\n txtBullet3 = %@\n txtBullet4 = %@\n txtBullet4 = %@\n txtBullet5 = %@\n iUniqueIdentifier = %@\n dtDateLastTouched = %@\n txtNote6 = %@\n InstallTime = %@\n SGID = %@\n CURTID = %@\n SGRetail = %@\n SGMemPrice = %@\n InstallSheet = %@\n mHitchJobber = %@\n CatID = %@\n ParentID = %@\n", iProductID, vchProductCode, vchPriceCode, vchHitchUPC, mHitchList, mHitchMap, fShippingWeight, vchWC, vchCapacity, txtNote1, txtNote2, txtNote3, txtNote4, vchDrilling, vchUPCList, vchExposed, vchShortDesc, iVehicleID, iProductClassID, dtDateMod, txtBullet1, txtBullet2, txtBullet3, txtBullet4,txtBullet5, iUniqueIdentifier, dtDateLastTouched,txtNote6,InstallTime,SGID,CURTID,SGRetail,SGMemPrice,InstallSheet,mHitchJobber,CatID, ParentID]; } @end Ignoring the fact that its really long I also tried to just set the property but then my product didnt have any values. So I alloc'd for all properties, not sure which is "correct" the use of product picker.h #import <UIKit/UIKit.h> @class Vehicle; @class Product; @interface Picker : UITableViewController <NSXMLParserDelegate> { NSString *currentRow; NSString *currentElement; Vehicle *vehicle; } @property (nonatomic, retain) NSMutableArray *dataArray; //@property (readwrite, copy) NSString *currentRow; //@property (readwrite, copy) NSString *currentElement; -(void) getYears:(NSString *)string; -(void) getMakes:(NSString *)year; -(void) getModels:(NSString *)year: (NSString *)make; -(void) getStyles:(NSString *)year: (NSString *)make: (NSString *)model; -(void) getHitch:(NSString *)year: (NSString *)make: (NSString *)model: (NSString *)style; -(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName; -(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string; -(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict; @end The implementation .m #import "Product.h" #import "Picker.h" #import "KioskAppDelegate.h" #import "JSON.h" #import "Vehicle.h" @implementation Picker @synthesize dataArray; -(void) getHitch:(NSString *)year: (NSString *)make: (NSString *)model: (NSString *)style{ currentRow = [NSString stringWithString:@"z:row"]; currentElement = [NSString stringWithString:@"gethitch"]; //Reinitialize data array [self.dataArray removeAllObjects]; [self.dataArray release]; self.dataArray = [[NSArray alloc] initWithObjects:nil]; //Build url & string NSString *thisString = [[NSString alloc] initWithString:@""]; thisString = [NSString stringWithFormat:@"http://api.curthitch.biz/AJAX_CURT.aspx?action=GetHitch&dataType=json&year=%@&make=%@&model=%@&style=%@",year,make,model,style]; //Request NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:thisString]]; //Perform request and fill data with json NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; //Get string from data NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; //set up parser SBJsonParser *parser = [[SBJsonParser alloc] init]; //parse json into object NSArray *tempArray = [parser objectWithString:json_string error:nil]; for (NSDictionary *dic in tempArray) { Product *tempProduct = [[Product alloc] initWithDict:dic]; NSLog(@"is tempProduct valid %@", (tempProduct) ? @"YES" : @"NO"); [self.dataArray addObject:tempProduct]; } } @end So I stripped out all the table methods and misc crap that doesnt matter. In the end my problem is adding the "tempProduct" object to the mutable array dataArray so that I can customize the table cells. Using the json framework im parsing out some json which returns an array of NSDictionary objects. Stepping through that my dictionary objects look good, I populate my custom object with properties for all my fields which goes through fine, and the values look right. However I cant add this to the array, I've tried several different implementations doesn't work. Not sure what I'm doing wrong. In some instances doing a po tempProduct prints the description and sometimes it does not. same with right clicking on the variable and choosing print description. Actual error message 2011-02-22 15:53:56.058 Kiosk[8547:207] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x4e1ba40 2011-02-22 15:53:56.060 Kiosk[8547:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x4e1ba40' *** Call stack at first throw: ( 0 CoreFoundation 0x00dbabe9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f0f5c2 objc_exception_throw + 47 2 CoreFoundation 0x00dbc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00d2c366 ___forwarding___ + 966 4 CoreFoundation 0x00d2bf22 _CF_forwarding_prep_0 + 50 5 Kiosk 0x00003ead -[Picker getHitch::::] + 1091 6 Kiosk 0x00003007 -[Picker tableView:didSelectRowAtIndexPath:] + 1407 7 UIKit 0x0009b794 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140 8 UIKit 0x00091d50 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219 9 Foundation 0x007937f6 __NSFireDelayedPerform + 441 10 CoreFoundation 0x00d9bfe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19 11 CoreFoundation 0x00d9d594 __CFRunLoopDoTimer + 1220 12 CoreFoundation 0x00cf9cc9 __CFRunLoopRun + 1817 13 CoreFoundation 0x00cf9240 CFRunLoopRunSpecific + 208 14 CoreFoundation 0x00cf9161 CFRunLoopRunInMode + 97 15 GraphicsServices 0x0102e268 GSEventRunModal + 217 16 GraphicsServices 0x0102e32d GSEventRun + 115 17 UIKit 0x0003442e UIApplicationMain + 1160 18 Kiosk 0x0000239a main + 104 19 Kiosk 0x00002329 start + 53 ) terminate called after throwing an instance of 'NSException'

    Read the article

  • Nil string with [NSString stringWithFormat:] appears as "(null)"

    - by Supernico
    I have a 'Contact' class with two properties : firstName and lastName. When I want to display a contact's full name, here is what I do: NSString *fullName = [NSString stringWithFormat:@"%@ %@", contact.firstName, contact.lastName]; But when the firstName and/or lastName is set to nil, I get a "(null)" in the fullName string. To prevent it, here's what I do: NSString *first = contact.firstName; if(first == nil) first = @""; NSString *last = contact.lastName; if(last == nil) last = @""; NSString *fullName = [NSString stringWithFormat:@"%@ %@", first, last]; Does someone know a better/more concise way to do this?

    Read the article

  • I don't know How to release NSString.

    - by Beomseok
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [path objectAtIndex:0]; NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"DB"]; NSString *fileName = [newWordbookName stringByAppendingString:@".csv"]; NSString *fullPath = [databasePath stringByAppendingPathComponent:fileName]; [[NSFileManager defaultManager] createFileAtPath:fullPath contents:nil attributes:nil]; [databasePath release]; //[fileName release]; Error! //[fullPath release]; Error! //NSLog(@"#1 :databasePath: %d",[databasePath retainCount]); //NSLog(@"#1 :fileName: %d",[fileName retainCount]); //NSLog(@"#1 :fullPath: %d",[fullPath retainCount]); Hi guys, I'm using this code and want to release NSString* .. so, I declare fileName, fullPath, and databasePath of NSString. But database is released, fileName, fullpath doen't release. I don't know why it happen. I know that NSArray is Autoreleased. But Is documentsDirectory autoreleased? (newWordbookName is nsstring type) I hope that I look through a document about iPhone memory management. Please advice for me.

    Read the article

  • Convert NSString to fetch synthesized information.

    - by Max
    //COPY THIS CODE IN A FRESH PROJECT!!! //THIS 2 LINES ARE JUST EXAMPLES, IN REAL THEY ARE NOT STATIC! NSString *messagelevel1 = @"45"; NSString *messagelevel = @"1"; NSString *HuidigLevel = messagelevel; NSDecimalNumber *huidigleveldec = [[NSDecimalNumber alloc] initWithString: HuidigLevel]; float HuidigLevelRek = [huidigleveldec floatValue]; //HERE IS THE PROBLEM NSString* LevelTotaal=[[NSString alloc] initWithFormat:@"messagelevel%.f",HuidigLevelRek]; NSString*result = LevelTotaal; NSLog(@"%@",result); // THIS RESULT SHOULD RETURN THE SAME VALUE AS THE LINE UNDER THIS LINE! NSLog(@"%@",messagelevel1); I want the *result string behaves like the *huidiglevel string and fetch some information, but because the LevelTotaal is a NSString, It doesn't fetch this information. I really got no idea where to google for this problem, searching the Developer docs didn't helped either . Maybe you guys can help me out? Actually the second NSLog returns the value and to first NSLog just returns messagelevel1. To tell you in short ;) I hope you guys get what I'm saying!

    Read the article

  • Problem with a NSString that equals to (null)

    - by Guy Dor
    Hi, I have an UIViewController named MainViewController I have another UIViewController named LeftSharingViewController; I would like to get and use the NSString from MainViewController in my LeftSharingViewController I have a problem, I always get (null) instead of the NSString wanted value. Here's my code and how does the NSString get it's value MainViewController: - (void)webViewDidFinishLoad:(UIWebView *)webView { leftWebViewString = [NSString stringWithString:leftWebView.request.URL.absoluteString]; } LeftSharingViewController.h: #import <UIKit/UIKit.h> #import "MainViewController.h" #import <MessageUI/MessageUI.h> #import <MessageUI/MFMailComposeViewController.h> @class MainViewController; @interface LeftSharingViewController : UIViewController <MFMailComposeViewControllerDelegate> { MainViewController *mainViewController; NSString *leftWebViewUrl; } @property (nonatomic, retain) MainViewController *mainViewController; @property (nonatomic, retain) NSString *leftWebViewUrl; @end LeftSharingViewController.m: #import "LeftSharingViewController.h" #import "MainViewController.h" @implementation LeftSharingViewController @synthesize mainViewController; @synthesize leftWebViewUrl; - (void)viewWillAppear:(BOOL)animated { self.leftWebViewUrl = self.mainViewController.leftWebViewString; } #pragma mark - #pragma mark Compose Mail -(void)displayComposerSheet { MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init]; mailPicker.mailComposeDelegate = self; [mailPicker setSubject:@"Check Out This Website!"]; [mailPicker setMessageBody:[NSString stringWithFormat:@"Take a look at this site:%@", leftWebViewUrl] isHTML:YES]; mailPicker.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:mailPicker animated:YES]; [mailPicker release]; } Thanks!

    Read the article

  • NSString copy not copying?

    - by Scotty Allen
    NSString *myString = @"sample string"; NSString *newString = [NSString stringWithString: myString]; If I set a breakpoint after these two lines, the pointer for myString is the same as the pointer for newString. WTF? Isn't NSString copy supposed to return a pointer to a new object? Or am I missing something fundamental about how copy is supposed to work?

    Read the article

  • Foundation framework. No NSString.h file

    - by pawelini1
    Hello I'm getting a few errors just after I updated my working copy via SVN. /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:8:0 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:8:32: error: Foundation/NSString.h: No such file or directory /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:45:0 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:45: error: expected ')' before 'unichar' /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSPathUtilities.h:10:0 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSPathUtilities.h:10: error: cannot find interface declaration for 'NSString' All that errors tell that compiler is unable to find NSString.h file in Foundation framework and I have opened the Foundation framework in Xcode/Frameworks/Foundation.framework/Headers and noticed that there is no NSString header file there. Could anyone tell me what happened? I tried to delete the framework and add it again but it failed to. Still I don't have NSString header file.

    Read the article

  • How do I convert a NSString into TIS-620 encoded string

    - by MacPC
    In the apple document, I can see that there's a way to convert from UTF8 string to ASCII string like this NSData *asciiData = [theString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *asciiString = [[NSString alloc] initWithData:asciiData encoding:NSASCIIStringEncoding]; But my app requires a TIS-620 string to post to a site so I try to do the same thing NSData *asciiData = [newPost.header dataUsingEncoding:kCFStringEncodingMacThai allowLossyConversion:YES]; NSString *asciiString = [[NSString alloc] initWithData:asciiData encoding:kCFStringEncodingMacThai]; NSLog(@"%@", asciiString); The output I got is like this ???????????. Does anyone know how to convert the NSString to TIS-620 properly? Thanks so much.

    Read the article

  • Iphone SDK: pathFoResource:Nsstring problem -> playin MP3 files

    - by Kaya
    I am trying to get 10 mp3 files in the resources folder and play them when a button is pressed. I have entered name of the mp3 files in a NSMutableArray and read each one after the button is pressed. The problem is that pathForResource: is not working (returns nil). If i use the file name explicitly -like pathFoResource:@"song1.mp3" ofType:@"mp3"- but if i use pathForResource:valuem whwre valuem is an NSstring with value of song1 Hope you can help Regards NSString *cellValue0 = [listOfmp3 objectAtIndex:anumber]; NSString *valuem; if ( [cellValue0 length] 0 ) valuem = [cellValue0 substringToIndex:[cellValue0 length] - 4]; NSString *pdfPath2 = [[NSBundle mainBundle] pathForResource:valuem ofType:@"mp3"]; NSURL *url = [NSURL fileURLWithPath:pdfPath2];

    Read the article

  • Turning NSData to NSString is failing

    - by Ricky D'Amelio
    Hi there. I have an NSData object which I am trying to turn into an NSString using the following line of code: NSString *theData = [[NSString alloc] initWithData:photo encoding:NSASCIIStringEncoding]; Unfortunately I am getting the following result, instead of my desired binary output (can I expect a binary output here?); ÿØÿà I'd appreciate any help. Thanks. Ricky.

    Read the article

  • Converting NSData to an NSString representation is failing

    - by Ricky D'Amelio
    Hi there. I have an NSData object which I am trying to turn into an NSString using the following line of code: NSString *theData = [[NSString alloc] initWithData:photo encoding:NSASCIIStringEncoding]; Unfortunately I am getting the following result, instead of my desired binary output (can I expect a binary output here?); ÿØÿà I'd appreciate any help. Thanks. Ricky.

    Read the article

  • Break NSString using an NSString, get everything after the string that was used to break/separate.

    - by Cole
    I'm trying to get the DOE,JOHN from the below NSString: IDCHK9898960101DL00300171DL1ZADOE,JOHN I was trying to split the string on 1ZA, as that will be constant. Here's what I've tried so far, but it's giving me the opposite of what I'm looking for: NSString *getTheNameOuttaHere = @"IDCHK9898960101DL00300171DL1ZADOE,JOHN"; // scan for "1ZA" NSString *separatorString = @"1ZA"; NSScanner *aScanner = [NSScanner scannerWithString:getTheNameOuttaHere]; NSString *thingsScanned; [aScanner scanUpToString:separatorString intoString:&thingsScanned]; NSLog(@"container: %@", thingsScanned); Output: container: IDCHK9898960101DL00300171DL Any help would be great! Thanks!

    Read the article

  • NSString to NSURL objects

    - by user337844
    Hello, I have an array that I populated with my plist file, which looks something like this: <array> <string>http://www.apple.com</string> <string>http://www.google.com</string> <string>http://www.amazon.com</string> </array> So, I'm looking to convert these NSString objects to NSURL objects when I call them in my didSelectRowAtIndexPath method. Any ideas? This is what I have right now: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = [indexPath row]; if (self.viewController == nil) { TemplateViewController *details = [[TemplateViewController alloc] initWithNibName:@"TemplateViewController" bundle:nil]; self.viewController = details; [details release]; } NSString *tempURLString = [tieroneurlArray objectAtIndex:row]; NSURL *loadingUrl = [NSURL URLWithString:tempURLString]; [tieroneurlArray addObject:loadingUrl]; viewController.title = [NSString stringWithFormat:@"%@", [tieroneArray objectAtIndex:row]]; [self.viewController setTableURL:[tieroneurlArray objectAtIndex:row]]; TemplateAppAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; [delegate.templateNavController pushViewController:viewController animated:YES]; } And this is how I load the array with the plist: - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"tier1Names" ofType:@"plist"]; tieroneArray = [[NSMutableArray alloc] initWithContentsOfFile:path]; NSString *tableURL = [[NSBundle mainBundle] pathForResource:@"tier1URL" ofType:@"plist"]; tieroneurlArray = [[NSMutableArray alloc] initWithContentsOfFile:tableURL]; }

    Read the article

  • NSString stringWithFormat

    - by Leo
    Hi Guys, I don't know what I am missing here. I am trying to concatenate strings using NSString stringWithFormat function. This is what I am doing. NSString *category = [row objectForKey:@"category"]; NSString *logonUser = [row objectForKey:@"username"]; user.text = [NSString stringWithFormat:@"In %@ by %@", category, logonUser]; The problem here is that it always print only one variable. Say if there is "Sports" in category and "Leo" in logonUser it will print "In Sports" and skip the remaining text. It should print "In Sports by Leo". Thanks

    Read the article

  • Memory Management - Objective C NSString

    - by reising1
    I have an NSMutableDictionary called "output" and I am adding an NSString into it that is an integer. What is the proper way to do this? I can't figure it out. Everything I've tried ends up giving memory leaks. This is what I currently have: val is an int countryName is an NSString Here is how I declare "output": NSMutableDictionary *output = [[[NSMutableDictionary alloc] init] autorelease]; Here is the code that causes a memory leak: NSString *temp = [NSString stringWithFormat:@"%d",val]; [output setValue:temp forKey:countryName];

    Read the article

  • [iPhone app] Inserting special char un NSString for URL use

    - by Dough
    Hi, I'm using HTTP connection to share data with my JSON server. I use URLs like "MyServlet?param1=value1" and so on... I'm now facing a problem with one of my servlet (I can't change it because some other views are using it) : The servlet is working with a syntax including those symbols "{" and "}". The exact syntax is {(value1_value2)(value3_value4)(value5_value6)}{(value7_value8)(value9_value10)(value11_value12)}{(value13_value14)(value15_value16)(value17_value18)} Values are integers, the problem is only when I use "{" and "}" my UrlConnection returns an error for bad URL. I use this to instantiate my NSString : NSString *myURL = [NSString stringWithFormat:@"http://somesite.com/Servlet?PARAM={(%@)}"]; How can I code those char in my NSString ? Thanks in advance !

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >