nsstring

Managing UITextField.text property

Well, I have a UITextField. Inside it is a property UITextField.text. Is it ok to do: // Assume we have UITextField * tf somewhere.. // now set its text.. tf.text = [ [ NSString alloc ] initWithUTF8String:"Init'd with utf8" ] ; My problem with this is memory. What happens to the old value of the UITextField's text property. Don't ...

NSString no 'assign', 'retain', or 'copy' attribute is specified

I'm declaring an NSString property in a class and objective-c is complaining that: NSString no 'assign', 'retain', or 'copy' attribute is specified It then casually lets me know that "assign is used instead". Can someone explain to me the difference between assign, retain and copy in terms of normal C memory management functions? ...

I am trying to learn Objective C but maybe my enviroment is wrong?

#import <stdio.h> #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { printf("Hello World!!\n"); return 0; } I have a MacAir running OS X 10.6.1 with XCode version 3.2.1. When I attempt to compile the lines above I get 3951 errors. Most of them seem to be NSObjCRunntime.h file where NSString is defined. ...

Cocoa iPhone Programming: Encoding/Decoding NSString

Is their a method to encode/decode HTML and URL (in Xcode, using Objective-C)? [NSString stringWithContentsOfFile:<#(NSString *)path#> encoding:<#(NSStringEncoding)enc#> error:<#(NSError **)error#>] This doesn't seem to work how i expected. I thought it will convert special characters like "<" to equivalent HTML entities i.e. "<" in ...

multiline text, sqlite and uitextview, is not working

I tried many things, i can't display multiline texts from database into uitextview, the \n characters appear as they are instead creating new lines. NSString *aDescription2 = [NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 2) encoding:NSUTF8StringEncoding]; The problem must be here, because if i hardcode the...

algorithm to add randomly-generated NSStrings to NSMutableArray

The goal is to generate an NSString chars in length and assign each string to an array. I'm getting stuck on what I need to do with my algorithm to get the correct result. Here's the sample. The result I get is the same randomly generated string added to my array 26 times instead of 26 DIFFERENT strings added. I've thought about de...

How do I divide NSString into smaller words?

Greetings, I am new to objective c, and I have the following issue: I have a NSString: "There are seven words in this phrase" I want to divide this into 3 smaller strings (and each smaller string can be no longer than 12 characters in length) but must contain whole words separated by a space, so that I end up with: String1 = "Ther...

Append a newline to an NSString

I have this: if (soapResults != nil) { soapResults = [soapResults stringByAppendingString:@"\n"]; } But I get a warning: Assignment from distinct Objective-C type on build. When I run it on device I get: Program received signal: "EXC_BAD_ACCESS". from gdb. Any ideas how to append a newline to an NSString without getting a warn...

Detect Unicode characters in NSString on iPhone

I am working on an SMS application for the iPhone. I need to detect if the user has entered any unicode characters inside the NSString they wish to send. I need to do this is because unicode characters take up more space in the message, and also because I need to convert them into their hexadecimal equivalents. So my question is how d...

decodeHexString obj-c implementation, Should I support odd lengthed hexstrings, and if so, how?

I may be missing something in the standard libs, but I don't think so. I have this current implementation: int char2hex(unsigned char c) { switch (c) { case '0' ... '9': return c - '0'; case 'a' ... 'f': return c - 'a' + 10; case 'A' ... 'F': return c - 'A' + 10; default: WARNING(@"pa...

Trim file extension UITableView

I want to trim the file extension from text I have NSMutableArray'd in table cells. NSMutableArray *theFiles; NSFileManager *manager = [NSFileManager defaultManager]; NSArray *fileList = [manager directoryContentsAtPath:@"/Test"]; for (NSString *s in fileList){ theFiles = fileList; } cell.textLabel.text = [theFiles obje...

iphone compare &#160; with NSString

Hi, i was comparing A string coming from XML with another String and results were showing that they are not equal. but in NSLog() both were same ( e.g. Valore Books ). then i checked the Source of the XML and i came to know that the actual string is "Valore&#160;Books" and &#160; is infact a space. but the problem is this when i am co...

What is the purpose of having both NSMutableString and NSString?

Why does Objective C provide both class NSString and subclass NSMutableString rather than just provide NSMutableString? Isn't a NSString equivalent to "const NSMutableString"? In C++, you have only one string class, std::string, and if you want a constant you declare a const std:string. I'm interested in knowing why I shouldn't just u...

Integer Casting in dealing with strings in Cocoa

I have what I hope to be a pretty simple problem. I'm very simply trying to convert a char to it's lowercase version. Here's my code: - (IBAction)click:(id)sender { [outputLabel setText:[inputField text]]; NSString* textFieldString = [inputField text]; NSLog(@"String is %@", textFieldString); int textFieldLength = textF...

How to get the first N words from a NSString in Objective-C?

What's the simplest way, given a string: NSString *str = @"Some really really long string is here and I just want the first 10 words, for example"; to result in an NSString with the first N (e.g., 10) words? EDIT: I'd also like to make sure it doesn't fail if the str is shorter than N. ...

How to convert a unichar value to an NSString in Objective-C?

Hi there, I've got an international character stored in a unichar variable. This character does not come from a file or url. The variable itself only stores an unsigned short(0xce91) which is in UTF-8 format and translates to the greek capital letter 'A'. I'm trying to put that character into an NSString variable but i fail miserably. ...

Checking if a nsstring matches another string

Suppose I have a string "167282". How can I check if the string contains "128"? Is there any provision to know the percentage of the 2nd string that matches the first string? (If all the characters of the 2nd string are present in the first string or not.) Please help and thanx in advance. ...

[iphone] use NSString in other method?!

It's really embarrassing but i stuck on it for two hours of trial and error. I declared an NSString in the interface as: NSString *testString; Then i made a property and synthesized it. I allocate it in viewDidLoad with: testString = [[NSString alloc] initWithFormat:@"thats my value: %i", row]; If i want to get the value of the st...

NS String comparison fails with stringWithFormat

I have two NSStrings with the same value this failed for me: if (button.controlName == controlName) { return button; } this worked: if ([button.controlName compare: controlName] == NSOrderedSame) { return button; } Is this just how strings are compared in objective c? Or should the first statement have worked as well? Why ...

Iphone Caching Problem

Hello, when I call -(IBAction)goback:(id)sender { NSURL *xmlURL=[NSURL URLWithString:@"http://demo.komexa.com/sicherungsbereich.xml"]; NSURLRequest *request = [NSURLRequest requestWithURL:xmlURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:2]; NSURLResponse *theResponse; NSError *theError; NSData ...