Search Results

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

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

  • How to get arc4Sin() output into label/NSString

    - by Moshe
    I'm trying to take the output of arc4sin and put it into a label. (EDIT: You can ignore this and just post sample code, if this is too irrelevant.) I've tried: // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; NSString *number = [[NSString alloc] stringWithFormat: @"%@", arc4random() % 9]; label.text = number; } I've created an IBOutlet for "label" and connected it. What's wrong here?

    Read the article

  • Unicode data from NSData to NSString

    - by Jeff
    So if I have NSData from an HTTP request, then I do something like this: NSString *test = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; This will result in null if the data contains weird unicode data (title is from reddit): {"title":"click..¦¦me..and..then¦¦________ ¦¦check¦¦_.your...¦¦.__...¦¦____ ¦¦....¦¦¦¦¦¦¦¦¦¦¦¦¦¦....¦¦____ ¦¦¦¦¦¦....¦¦¦¦¦¦....¦¦¦¦¦¦____ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦____ ....¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦______ ........¦¦..._recently....¦¦________ ....¦¦....viewed....links....¦¦_____"}, How would I convert the data to a string? Ideally, it would best if the string wasn't null so I could parse it as JSON, but even a lossy conversion is fine with me in these cases. I'm not familiar with unicode (naive American I am), so any enlightenment about that would be a nice bonus :)

    Read the article

  • Having a problem with reading a file using NSString initWithContents OfFile

    - by srikanth rongali
    In this program when I debug, it is showing the nil for fileNameString. I could not understand what is the problem. Please help me ? @implementation fromFileRead1 NSString *fileNameString; -(id)init { if( (self = [super init]) ) { fileNameString = [[NSString alloc] initWithContentsOfFile: @"enemyDetails.rtf" encoding:NSUTF8StringEncoding error:nil]; NSArray *lines = [fileNameString componentsSeparatedByString:@"\n"]; for (id *line in lines) { NSLog(@"Line1%@", line ); } } return self; } @end Thank You.

    Read the article

  • Strange hex formatting in NSString

    - by pseudopeach
    Try this: unsigned long long int N; = 23229877463LL; NSString* s = [NSString stringWithFormat:@"dec:%qi, hex:%qX",N,N]; NSLog(@"output: %@",s); output: dec:23229877460, hex:689BCCD400000005 What's up with the 00000005??? In mySQL, hex(23229877460) = 5689BCCD4. Also, every other language seems to do this correctly. A 16 digit long hex is like 4 gazillion (16^16), right? How can I get objective-c to format hex numbers that other languages can understand?

    Read the article

  • Troubles with NSString writeToFile

    - by Jesse
    Hi everyone, I have been working on a simple text editor in Cocoa/Objective-C for a practice project and I have come across an error that I would never have expected. I have an NSString for my file's contents as well as an NSString for it's path. When I attempt to write the contents to a file, I use the following method: [FileContents writeToFile: CurrentFileName atomically: NO encoding: NSStringEncoding error: nil]; I've used this method many times without error yet today, I am getting an error: "Expected expression before 'NSStringEncoding'" If anyone can help me out with this it would be greatly appreciated. I can't figure out what could be causing the error. Thanks a lot!

    Read the article

  • Validate NSString

    - by Chris
    I am validating an NSString to ensure that the string does not contain apostrophes. The code I'm using to do this is NSCharacterSet * invalidNumberSet = [NSCharacterSet characterSetWithCharactersInString:@"'"]; NSScanner * scanner = [NSScanner scannerWithString:string]; NSString * scannerResult; [scanner setCharactersToBeSkipped:nil]; [scanner scanUpToCharactersFromSet:invalidNumberSet intoString:&scannerResult]; if(![string isEqualToString:scannerResult]) { return 2; } Returning 2 represents an error. This code works, except for the case where the string is an apostrophe. To get around this issue, I added the following code above the preceding block. if([string isEqualToString:@"'"]); { return 2; } This code is evaluating to true, regardless of the input. I need to either prevent the first block from crashing with the input of ', or get the second block to work. What am I missing?

    Read the article

  • NSString's stringByAppendingPathComponent: removes a '/' in http://

    - by Jasarien
    I've been modifying some code to work between Mac OS X and iPhone OS. I came across some code that was using NSURL's URLByAppendingPathComponent: (added in 10.6), which as some may know, isn't available in the iPhone SDK. My solution to make this code work between OS's is to use NSString *urlString = [myURL absoluteString]; urlString = [urlString stringByAppendingPathComponent:@"helloworld"]; myURL = [NSURL urlWithString:urlString]; The problem with this is that NSString's stringByAppendingPathComponent: seems to remove one of the /'s from the http:// part of the URL. Is this intended behaviour or a bug? Edit Ok, So I was a bit too quick in asking the question above. I re-read the documentation and it does say: Note that this method only works with file paths (not, for example, string representations of URLs) However, it doesn't give any pointers in the right direction for what to do if you need to append a path component to a URL on the iPhone... I could always just do it manually, adding a /if necessary and the extra string, but I was looking to keep it as close to the original Mac OS X code as possible...

    Read the article

  • Convert NSString to CFURLRef

    - by carloe
    How can I convert a NSString that contains an absolute path to a file to a CFURLRef? I tried CFURLRef myFileUrl = CFURLCreateWithString(kCFAllocatorDefault, (CFStringRef)filePathString, NULL); and about half a dozend other ways.

    Read the article

  • Convert nsdata to nsstring

    - by ashwini
    Hi, I have utf8 encoded nsdata from windows server. I want to convert it to nsstring for iphone. Since data contains characters(like degree symbol) which have different values on both platforms, how do I convert data to string.

    Read the article

  • objective C NSString retain

    - by Amarsh
    If I create a String with [NSString StringWithFormat], do I have to [retain] it? My understanding is that convenience methods add the objects to autorelease pool. If that is the case, shouldnt we retain the object so that it doesnt get drained with pool at the end of the event loop?

    Read the article

  • Replace occurences of NSString - iPhone

    - by ncohen
    Hi everyone, I have a long NSString in which I m trying to replace special characters. Part of my string looks like this: "veau (c\u00f4telette)","veau (filet)","agneau (gigot)","agneau (c\u00f4telette)","b*\u0153*uf (hach\u00e9)","porc (hach\u00e9)" I would like to replace all the \u0153 with "oe". I ve tried: [response stringByReplacingOccurrencesOfString:@"\u0153" withString:@"oe"]; but it doesn't work.... I don't understand why! Thanks

    Read the article

  • How to find out if a method exists in Obj-C when given an NSString

    - by Justin
    I have a method as an NSString *. If it exists, I want to call it, and if not, do nothing. SEL eventSelector = NSSelectorFromString(eventSelectorStr); if ([delegate respondsToSelector:eventSelector]) { [delegate performSelector:eventSelector]; [delegate adapterDidFinishAdRequest:self]; } else { // Does not implement selector } This code does not work, since NSSelectorFromString will register the string as a selector, so respondsToSelector:eventSelector will cause a crash because the selector is actually invalid.

    Read the article

  • Leaks in passing the request using URL at NSString, Objective-C.

    - by Madan Mohan
    Hi Guys, I getting the leak in this method even the allocated nsstring is released. -(BOOL)getTicket:(NSString*)userName passWord:(NSString*)aPassword isLogin:(BOOL)isLogin { login =[self getloginList]; username = login.name; password = login.password; NSString* str=@""; if (isLogin == YES) { str = @"https://accounts.=true&LOGIN_ID="; str = [str stringByAppendingString:[self _encodeString:username]]; str = [str stringByAppendingString:@"&PASSWORD="]; str = [str stringByAppendingString:[self _encodeString:password]]; } else if (isLogin == NO) { str = @"https://accounts.=true&LOGIN_ID="; str = [str stringByAppendingString:[self _encodeString:userName]]; str = [str stringByAppendingString:@"&PASSWORD="]; str = [str stringByAppendingString: [self _encodeString:aPassword]]; } NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:str] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:25.0]; [request setHTTPMethod: @"POST"]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];//****************** i am getting leak here showing as nsstring is leaking NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; printf("\n returnString in getticket:%s",[returnString UTF8String]); NSRange textRange; textRange =[returnString rangeOfString:@"TICKET"]; if(textRange.location != NSNotFound) { printf("\n **********************"); NSArray* splitValues = [returnString componentsSeparatedByString:@"TICKET="]; NSString* str1 = [splitValues objectAtIndex:1]; NSArray* splitValues1 = [str1 componentsSeparatedByString:@"RESULT"]; NSString* ticket1 = [splitValues1 objectAtIndex:0]; self.ticket = ticket1; self.isCorrectLogin = YES; [returnString release]; return YES; } else { self.isCorrectLogin = NO; [returnString release]; return NO; } return NO; } Please help me out of this problem.

    Read the article

  • iPhone SDK NSString To NSDate

    - by disp
    I got a string from parsing a XML file which looks like this: Fri, 09 Apr 2010 00:00:45 +0200 and the corresponding pattern should be this "EEE, dd MMM yyyy HH:mm:ss ZZ", but I get (null). This is my code: NSString *dateString = @"Fri, 09 Apr 2010 00:00:45 +0200"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"]; NSDate *date = [dateFormatter dateFromString:dateString]; NSLog(@"date:%@",date); // result date:(null) Edit: This works for me now, I had to switch to en-US locale: NSLocale* usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:usLocale]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"]; NSDate *date = [dateFormatter dateFromString:dateString];

    Read the article

  • NSString within a link

    - by MN
    Hi, I have a UIWebView that loads a link, http://www.google.com/a/datacommsales.net. But I want to have the datacommsales.net part interchangable. What I would like it to be is http://www.google.com/a/stringOne, stringOne being the NSString, so I can set the value of the string and change the link without editing the code. But the link is inside quotes, @"http://www.google.com/a/datacommsales.net", so it doesn't recognize the string. How could I include the string's value as part of the link? Any help is appreciated.

    Read the article

  • How to get the size of a NSString

    - by camilo
    Hi. A "quicky": how can I get the size (width) of a NSString? I'm trying to see if the string width of a string to see if it is bigger than a given width of screen, case in which I have to "crop" it and append it with "...", getting the usual behavior of a UILabel. string.length won't do the trick since AAAAAAAA and iiiiii have the same length but different sizes (for example). I'm kind of stuck. Thanks a lot.

    Read the article

  • Save UITextView content in NSString.

    - by camilo
    Hi, I'm trying to save the contents of an UITextView into a NSString which I will somehow persist later. The problem is that the UITextView "text" property doesn't save all the rows in the textView (after touching "return"). I tried print the TextView object and the textView.text, and they're different. Does anybody know how (after editing the textView) I can save its content into a String (or something else that I can later access and share through different views and persist in the database)? Thanks a lot. Pretty sure it is simple, but I'm honestly not finding the solution.

    Read the article

  • Concatenating NSString inside of UITextView

    - by Jason
    I'm some trouble adding strings together for a UITextView in my app. The method I've been using is this (header) #import <UIKit/UIKit.h> @interface calculatorViewController : UIViewController { IBOutlet UITextView *output; } -(IBAction)b1; @property(nonatomic, copy) NSString *output; @end (main) #import "calculatorViewController.h" @implementation calculatorViewController -(void)b1 { [output stringByAppendingString:@"hi"]; } The problem I've been having with this method is when I use the button the app crashes. The warning it gives me is 'UITextView' may not respond to '-stringByAppendingString:' When I replace output with at string it works though and that confused me. Any suggestions? Am I doing something wrong? Thanks

    Read the article

  • NSString sizeWithAttributes: Inaccuracy

    - by dave-gennel
    I want to know the width of an NSString displayed on the screen in pixels. So I can fit an NSTextField its bounds to be exactly the length of the string itself. So I used IB's "Label" NSTextField and for those who don't know what I mean, I got a label with title "Label", font "Lucida Grande 13px", not selectable, not editable, regular size, no background and according to IB its width is 38px wide. If I want to get its width programatically I use [@"Label" sizeWithAttributes: [NSDictionary dictionaryWithObject: [NSFont fontWithName: @"Lucida Grande" size: 13] forKey: NSFontAttributeName]].width Which will give me 33.293457 . So that's about 5 px of the real width..

    Read the article

  • Return a Const Char* by reading an @property NSString in separate class

    - by Andrew
    I'm probably being an idiot here, but I cannot for the life of me find the answer that I'm looking for. I have an array of CalEvents returned from a CalendarStore query, and for other reasons I am finding the first location of any upcoming event for today that is not an all-day or multi-day event. +(const char*) suggestFirstiCalLocation{ CalCalendarStore *store = [CalCalendarStore defaultCalendarStore]; NSPredicate *allEventsPredicate = [CalCalendarStore eventPredicateWithStartDate:[NSDate date] endDate:[[NSDate date] initWithTimeIntervalSinceNow:3600] calendars:[store calendars]]; NSArray *currentEventCalendarArray = [store eventsWithPredicate:allEventsPredicate]; for (int i = 0; i< [currentEventCalendarArray count]; i++){ if (![[currentEventCalendarArray objectAtIndex:i] isAllDay]){ //Now that other events are cleared, check for multi-day NSDate *startOnDate = [[currentEventCalendarArray objectAtIndex:i] startDate]; NSDate *endOnDate = [[currentEventCalendarArray objectAtIndex:i] endDate]; if ([endOnDate timeIntervalSinceDate:startOnDate ] < 86400.0){ NSString * iCalLocation = [[currentEventCalendarArray objectAtIndex:i] location]; return [iCalLocation UTF8String]; } } } return ""; } For other reasons, I am returning a const char with the value of the location that is found. However, I cannot seem to return "iCalLocation" at all. The compiler fails on the line where I am initializing the "iCalLocation" variable: "Cannot convert to pointer type" Being frank: I am new to Objective-C, and I am still trying to figure points, properties, and such out.

    Read the article

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