archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • The History of Objective-C - Techotopia
    is known as a procedural language As such this means that it lacks features such as object oriented programming Object oriented programming advocates the creation of small clearly defined code objects that can be assembled and reused to create more complex systems An early attempt at an object oriented programming language was developed by a team including Alan Kay who later went to work for Apple and Dan Ingalls at Xerox PARC Palo Alto Research Center in the 1970s This language is known as Smalltalk C meets Smalltalk An interesting history lesson so far but what does this have to with Objective C Well in the 1980s two developers named Brad Cox and Tom Love extended the C programming language to support the object oriented features of Smalltalk This melding of languages ultimately culminated in the creation of Objective C Objective C was subsequently adopted by the Free Software Foundation and released under the terms of the GNU Public License GPL Objective C and Apple To understand how Objective C a language based on two 40 year old programming languages ended up being the language of choice on Mac OS X and the latest cutting edge smartphones from Apple it is necessary to move away from technology for a while and talk about business In the 1980s Steve Jobs and Steve Wozniak founded Apple Computer After many years of success Steve Jobs hired a marketing wizard from PepsiCo called John Sculley to help take Apple to the next level of business success To cut a long story short a boardroom battle ensued and Steve Jobs got pushed out of the company for the long version of the story pick up a used copy of John Sculley s book Odyssey From Pepsi to Apple leaving John Sculley in charge After leaving

    Original URL path: http://www.techotopia.com/index.php/The_History_of_Objective-C (2016-02-13)
    Open archived version from archive


  • Installing Xcode and Compiling Objective-C on Mac OS X - Techotopia
    in the dock to launch the tool Once Xcode has loaded and assuming this is the first time you have used Xcode on this system you will be presented with the Welcome screen from which you are ready to proceed Click on the option to Create a new Xcode project to display the template selection screen Within the template selection screen select the Application entry listed beneath MacOS X in the left hand panel followed by Command Line Tool in the main panel Click Next and on the resulting options panel name the project sampleApp and select Foundation from the Type menu Also verify that the Use Automatic Reference Counting option is selected Before Automatic Reference Counting ARC support was introduced to recent versions of Apple s compiler an Objective C programmer was responsible for retaining and releasing objects in application code This typically entailed manually adding retain and release method calls to code in order to manage memory usage Failing to release an object would result in memory leaks whereby a running application s memory usage increases over time whilst releasing an object too soon typically caused an application to crash ARC is implemented by Apple s LLVM compiler which scans the source code and automatically inserts appropriate retain and release calls prior to compiling the code thereby making the life of the Objective C programmer much easier Click Next and on the subsequent screen choose a suitable location on the local file system for the project to be created before clicking on the Create button Xcode will subsequently create the new project and open the main Xcode window Writing an Objective C Application with Xcode Xcode will create skeleton versions of the files needed to build a command line based Objective C application Objective C source files are identified by the m filename extension In the case of our example Xcode has pre created a main source file named main m and populated it with some basic code ready for us to edit To view the code select main m from the list of files so that the code appears in the editor area The skeleton code reads as follows import Foundation Foundation h int main int argc const char argv autoreleasepool insert code here NSLog Hello World return 0 Modify the NSLog line so that it reads NSLog This is my first Objective C App With the change made the next step is to compile and run the application Since the code is intended to display a message in the console the first step is to make sure the Xcode console window is displayed b y selecting the View Debug Area Activate Console menu option Next run the application by selecting the Run option located in the Xcode toolbar Once this option has been selected Xcode will compile the source code and run the application displaying the message in the Xcode console panel Compiling Objective C from the Command Line While Xcode provides a powerful environment that

    Original URL path: http://www.techotopia.com/index.php/Installing_Xcode_and_Compiling_Objective-C_on_Mac_OS_X (2016-02-13)
    Open archived version from archive

  • Installing and using GNUstep and Objective-C on Windows - Techotopia
    The MinGW package is contained in the GNUstep System download and the GNUstep core is contained unsurprisingly in the GNUstep Core download Both must be downloaded before proceeding with the installation Installing MinGW and GNUstep on Windows Once the required packages have been downloaded locate the GNUstep System file and launch it to initiate the installation process To complete the installation simply follow the prompts in the installation wizard using the default installation settings unless you have specific requirements In particular should you decide to install the package in a location other than C GNUstep you will need to adjust the instructions in the remainder of this chapter accordingly Once MinGW is installed repeat the process for the GNUstep Core package Running the GNUstep Shell To begin using Objective C and GNUstep start the GNUstep shell by selecting Start All Programs GNUstep Shell Once loaded the shell will appear as follows google IOSBOX google Testing the Installation The shell environment is a minimalist version of the shell environment you might find on a Linux or Unix system If you are unfamiliar with such an environment then it is unlikely you will want to perform the code editing in this window Fortunately it is still possible to use your favorite editor on Windows When the shell is first started it places you in the home directory for the GNUstep MinGW environment In terms of the Windows file system and assuming you used the default installation location for MinGW and GNUstep this is equates to C GNUstep home username Where username is the name by which you logged into the Windows system To create a simple application open a suitable editor Notepad will do and enter the following code import Foundation Foundation h int main int argc const char argv NSAutoreleasePool pool

    Original URL path: http://www.techotopia.com/index.php/Installing_and_using_GNUstep_and_Objective-C_on_Windows (2016-02-13)
    Open archived version from archive

  • Installing and Using GNUstep and Objective-C on Linux - Techotopia
    sudo apt get install gnustep The apt get utility will gather together a list of all the packages required for a successful GNUstep runtime installation and ask for confirmation that the installation is to proceed Once confirmation is provided the packages will be downloaded and installed onto the system The next step is to install the GNUstep development packages This is achieved using the following command sudo apt get install gnustep devel Once again apt get will list the packages required and seek confirmation before performing the installation process Once the installation is complete it can be tested by opening your favorite editor if you don t have a favorite try GEdit by selecting Applications Accessories Text Editor and entering some Objective C code import Foundation Foundation h int main int argc const char argv NSAutoreleasePool pool NSAutoreleasePool alloc init NSLog hello world pool drain return 0 Objective C source files have a m file name extension so save the file as hello m in a suitable folder such that you will be able to locate the file in the next section Compiling Objective C Code Before an Objective C program can be run it must first be compiled Compilation is a process whereby the human readable Objective C code in the source file in our case hello m is converted to the machine code understood by the CPU Prior to performing this compilation however the GNUstep environment must first be set up Thankfully a shell script is provided to perform this task for us and may be executed as follows usr share GNUstep Makefiles GNUstep sh Note that this setup script will need to be executed each time you start a new Terminal window with the intention of compiling Objective C For this reason you may find it advantageous

    Original URL path: http://www.techotopia.com/index.php/Installing_and_Using_GNUstep_and_Objective-C_on_Linux (2016-02-13)
    Open archived version from archive

  • Building and Installing GNUstep on Linux - Techotopia
    system in order to gain access to the full power of Objective C and to be able to work with the examples in the remainder of this book Fortunately a single package called GNUstep Startup is provided that contains the source code for all four of the above packages This package can be downloaded from the GNUstep org website download page Be sure to download the latest stable release of the GNUstep Startup software Once the package has been downloaded to a suitable work folder it can be unpacked as follows where version is replaced by the version number of the package you downloaded tar xvfz gnustep startup version tar gz The source files will be unpacked into a new directory named gnustep startup version once again substituting version for the version you downloaded Change directory into this folder as follows cd gnustep startup version Configuring the Build Process Before the build process can be started it must first be configured This is an automated process that scans the system on which the build is to take place to find out about the packages that are installed and then creates a build configuration file and a Makefile This configuration is performed by executing the following command in the GNUstep directory created in the previous section of this chapter configure Building GNUstep Once the configuration script process is complete it is time to begin the GNUstep build This is achieved by typing the following command make Once executed the build process will display an opening message similar to the following GNUstep Installation This is an automatic installation script for GNUstep This script tries to build and install the core libraries for GNUstep Log files of the build process are kept so that if some part of the build does not work you can send the log files to our attention at email protected From these we can try to determine what the problem is Press the Return key to begin continue Press any key to continue to the system check phase At the end of this phase a list of errors and warnings may appear Any errors will prevent the build from completing and should be addressed before proceeding These typically involve installation of missing packages Warnings can usually be ignored without impacting the subsequent build process Having reviewed the information provided press any key to return to the build The duration of the build will depend on the speed of the system but will usually be completed within a few minutes and display a message containing information some useful information Installation Finished Now run the GNUstep initialization script put this in your bashrc or other type of startup script Note the at the beginning of the line usr GNUstep System Library Makefiles GNUstep sh Now you can install some applications and start using GNUstep Look for a few applications in the AppSources directory The typical way to install an application is tar zxf MyApplication tar gz cd MyApplication make make

    Original URL path: http://www.techotopia.com/index.php/Building_and_Installing_GNUstep_on_Linux (2016-02-13)
    Open archived version from archive

  • Objective-C 2.0 Data Types - Techotopia
    and 64 bit implementations respectively When writing an Objective C program the only guarantee you have is that an int will be at least 32 bits wide To avoid future problems when compiling the code on other platforms it is safer to limit int values to the 32 bit range rather than assume that 64 bit will be available By default int values are decimal i e based on number base 10 To express an int in Octal number base 8 simply precede the number with a zero 0 For example int myoctal 024 Similarly an int may be expressed in number base 16 hexadecimal by preceding the number with 0x for example int myhex 0xFFA2 char Data Type The Objective C char data type is used to store a single character such as a letter numerical digit or punctuation mark or space character For example the following lines assign a variety of different characters to char type variables char myChar w char myChar 2 char myChar Special Characters Escape Sequences In addition to the standard set of characters outlined above there is also a range of special characters also referred to as escape sequences available for specifying items such as a new line or tab These special characters are identified by prefixing the character with a backslash a concept referred to as escaping For example the following assigns a new line to the variable named newline char newline n In essence any character that is preceded by a backslash is considered to be a special character and is treating accordingly This raises the question as to what to do if you actually want a backslash character This is achieved by escaping the backslash itself char myslash Assign a backslash to a variable Commonly used special characters supported by Objective C are as follows a Sound alert b Backspace f Form feed n New line r Carriage return t Horizontal tab v Vertical tab Backslash Double quote used when placing a double quote into a string declaration Single quote used when placing a double quote into a string declaration float Data Type The Objective C float data type is used to store floating point values in other words values containing decimal places For example 456 12 would be stored in a float data type In practice all floating point values are stored as a different data type called double by default We will be covering the double data type next but if you specifically want to use a float data type you must append an f into the end of the value For example float myfloat 123 432f For convenience when working with exceptionally large number both floating point and double data type values can be specified using scientific notation also known as standard form or exponential notation For example we can express 67 7 x 10 4 in Objective C as float myfloat 67 7e4 double Data Type The Objective C double data type is used to store larger

    Original URL path: http://www.techotopia.com/index.php/Objective-C_2.0_Data_Types (2016-02-13)
    Open archived version from archive

  • Working with Variables and Constants in Objective-C - Techotopia
    particular type it cannot subsequently be changed to a different type While this may come as a shock to those familiar with loosely typed languages such as Ruby it will be familiar to Java C C or C programmers Whilst it is not possible to change the type of a variable it is possible to disguise the variable as another type under certain circumstances This involves a concept known as type casting and will be covered later in this chapter Variable declarations require a type a name and optionally a value assignment The following example declares an integer variable called interestRate but does not initialize it int interestRate The following example declares and initializes a variable using the assignment operator int interestRate 10 Similarly a new value may be assigned to a variable at any point after it has been declared double interestRate 5 5456 Declare the variable and initialize it to 5 5456 interestRate 10 98 variable now equals 10 98 interestRate 20 87 variable now equals 20 87 What is an Objective C Constant google ADSDAQBOX FLOW google A constant is similar to a variable in that it provides a named location in memory to store a data value Constants differ in one significant way in that once a value has been assigned to a constant it cannot subsequently be changed Constants are particularly useful if there is a value which is used repeatedly throughout the application code Rather than use the value each time it makes the code easier to read if the value is first assigned to a constant which is then referenced in the code For example it might not be clear to someone reading your Objective C code why you used the value 5 in an expression If instead of the value 5 you use a constant named interestRate the purpose of the value becomes much clearer Constants also have the advantage that if the programmer needs to change a widely used value it only needs to be changed once in the constant declaration and not each time it is referenced As with variables constants have a type a name and a value Unlike variables constants must be initialized at the same time that they are declared and must be prefixed with the const keyword const int interestRate 10 Once declared it is not possible to assign a new value to the constant The following code will cause the Objective C compiler to report an error that reads error assignment of read only variable const int interestRate 10 interestRate 5 invalid attempt to assign new value to read only const Note that the value of a constant unlike a variable must be assigned at the point it is declared For example the following code will not compile const int interestRate interestRate 10 invalid attempt to initialize constant after declaration The above code will once again result in a compilation error Type Casting Objective C Variables As previously mentioned Objective C is a strongly typed

    Original URL path: http://www.techotopia.com/index.php/Working_with_Variables_and_Constants_in_Objective-C (2016-02-13)
    Open archived version from archive

  • Objective-C Operators and Expressions - Techotopia
    are most frequently used in constructing program flow control logic For example an if statement may be constructed based on whether one value matches another if x y Perform task The result of a comparison may also be stored in a BOOL variable For example the following code will result in a true 1 value being stored in the variable result BOOL result int x 10 int y 20 result x y Clearly 10 is less than 20 resulting in a true evaluation of the x y expression The following table lists the full set of Objective C comparison operators Operator Description x y Returns true if x is equal to y x y Returns true if x is greater than y x y Returns true if x is greater than or equal to y x y Returns true if x is less than y x y Returns true if x is less than or equal to y x y Returns true if x is not equal to y Boolean Logical Operators Objective C also provides a set of so called logical operators designed to return boolean true and false In practice true equates to 1 and false equates to 0 These operators both return boolean results and take boolean values as operands The key operators are NOT AND OR and XOR The NOT operator simply inverts the current value of a boolean variable or the result of an expression For example if a variable named flag is currently 1 true prefixing the variable with a character will invert the value to 0 false bool flag true variable is true bool secondFlag secondFlag flag secondFlag set to false The OR operator returns 1 if one of its two operands evaluates to true otherwise it returns 0 For example the following example evaluates to true because at least one of the expressions either side of the OR operator is true if 10 20 20 10 NSLog Expression is true The AND operator returns 1 only if both operands evaluate to be true The following example will return 0 because only one of the two operand expressions evaluates to true if 10 20 20 10 NSLog Expression is true The XOR operator returns 1 if one and only one of the two operands evaluates to true For example the following example will return 1 since only one operator evaluates to be true if 10 20 20 10 NSLog Expression is true If both operands evaluated to be true or both were false the expression would return false The Ternary Operator Objective C uses something called a ternary operator to provide a shortcut way of making decisions The syntax of the ternary operator also known as the conditional operator is as follows condition true expression false expression The way this works is that condition is replaced with an expression that will return either true 1 or false 0 If the result is true then the expression that replaces the true expression is evaluated

    Original URL path: http://www.techotopia.com/index.php/Objective-C_Operators_and_Expressions (2016-02-13)
    Open archived version from archive