#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    66
    Rep Power
    2

    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

    int example;


    and if the variable had a decimal you would write

    float example;

    but what about if it is a piece of literal text?
  2. #2
  3. No Profile Picture
    Still Learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Montreal, Canada
    Posts
    55
    Rep Power
    39
    you should search for the keywords i your question before you ask it.

    I found
    http://blog.bignerdranch.com/398-objective-c-literals-part-1/
  4. #3
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,073
    Rep Power
    1802
    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.

IMN logo majestic logo threadwatch logo seochat tools logo