December 29th, 2012, 09:00 AM
Declaring a Literal
Hello :) I am still very new to objective C and I was wondering how do you declare a variable to be a string literal. For example if the variable is an integer you would write
and if the variable had a decimal you would write
but what about if it is a piece of literal text?
January 3rd, 2013, 03:12 PM
you should search for the keywords i your question before you ask it.
January 3rd, 2013, 03:53 PM
You must first understand that there is no built-in data type in either C, C++ or Objective-C. Unlike C however C++ and Objective-C standard libraries provide standard string classes that essentially add a string type. In C a string is merely a convention using a character array with a nul terminator, which is supported by a library for performing operations such as assignment and comparison.
I am no Objective-C expert and find the language syntax arcane and the documentation unfathomable, however I believe that this may be what you are after.
The pedant in me feels the need to clarify some terms used in your question:
A float does not represent a decimal, it represents an approximation of a real number (as opposed to an integer) using a binary representation. That representation is typically a binary-floating-point representation and as such there are many decimal values that it cannot precisely represent. There are decimal-floating-point representations that can accurately represent decimal values, but there is no built-in type in Objective-C for that, and most underlying FPU hardware does not directly support it, so it is intrinsically slower. C# is one language that does have a decimal data type.
A "literal" is a direct value rather than a variable, so "declaring a literal" is an oxymoron. For example "ABC123" is a string literal, 12345 is an integer literal.
I believe that what you intended to ask is how you can declare a variable of string type, or possibly how to declare a variable and assign or initialise it with a string literal?
Last edited by clifford; January 3rd, 2013 at 03:57 PM.