Nsarray and nsset actually implement similar basic functions. This is very different from other languages such as Java. nsarray's data storage method is continuous, the latter data is stored in the memory followed by the previous data, while the
In objective-C, @ property is used to identify attributes (generally instance variables ). Use @ synthesize in the implementation file to identify the declared variables, so that the system can automatically generate the setting and obtaining
When defining classes in objective-C, you can also use public and private variables similar to C ++ to modify member variables, as shown below:
@ Intterface test: nsobject {@ publicint I; Int J; @ protectedfloat m; float N; @ privatedouble X;
Category is one of the most common functions in objective-C.
Category can add methods for existing classes without adding a subclass.
The standard syntax format of the category interface is as follows:
# Import "class name. H" @ Interface
Common nsfilehandle operations
+ (Nsfilehandle *) filehandleforreadingatpath: path // open a file for the read operation + (nsfilehandle *) filehandleforwritingatpath: path // open a file for the write operation + (nsfilehandle *)
During iPhone development, you will often encounter multiple strings to be connected. The following is my summary:
Nsstring * Hello = @ "hello ,";
Nsstring * World = @ "world! ";
Nsstring * helloworld;
Connect the hello and world strings.
[STR hasprefix: @ "12"]; // return value bool starting with 12[STR hassuffix: @ "TXT"]; // whether to return bool at the end of txt
// Search for strings[STR rangeofstring: @ "345"]; // returns the return location of the nsange parameter. If the
The Demo code is as follows:There are four methods to sort Arrays:1. Basic sorting method:Use the compare method provided in nsstring for sorting. For details, see arraysort1 of the demo.2. Custom compareCustomize the comparestudent method in the
How can I add instance variables to all objects? You can use category to easily add methods to existing classes, but you cannot directly add instance variables. (If you use the look-up table method, you can save your money ). However, since Mac OS X
Apple expands block syntax in C, objective-C, and C ++ and supports it in gcc4.2. Now we can use it in MAC 10.6 and iOS 4. For Mac 10.6 or IOS 4.0 platforms, it is said that blocksyntax can be supported using http://code.google.com/p/plblocks.
The
In objective-C, when a class needs to reference another class, that is, to establish a composite relationship, you need to create a pointer to the referenced class in the Class header file. For example:
Car. h
#import @interface Car:NSObject{
In objective-C, when a class is used to another class and the referenced pointer needs to be created in the Class header file,
I. # import and @ Class
The following code is used:
A. H file
#import "B.h"@interface A : NSObject { B *b;}@end
For
A collection (nsset) object is a combination of Single-value objects. For example, a set of 1 to 50 numbers.
Operations on collection objects include searching, adding, and deleting members in a set, comparing two sets, and calculating the
The unique data types in objective-C are listed here:
I. String
In objective-C, A String constant is a string sequence enclosed by a pair of @ and a pair of quotation marks. For example, @ "China" and @ "objective-c" are all valid string constants.
Category is one of the most commonly used functions in objective-C. Category can add methods for existing classes without adding a subclass. In addition, we can add methods for a class without knowing its internal implementation. If we want to add a
Struct is often used in C/C ++ development to help us encapsulate basic data types. In objective-C, struct can also be used to encapsulate data types. At the same time, cocoa touch also provides an nsvalue to help us better use struct in development.
Cocos2d-x learning exchange group: 140326755
Email: hahayacoder@gmail.com
Background
I have been interested in mobile development and mobile game development, but has been in the soy sauce status, recently also learning cocos2d-x, and then by the
Http://www.cocoachina.com/macdev/cocoa/2009/0611/255.html
Some readers mentioned the need to develop email programs on the iPhone a few days ago. In addition to sending emails using mailto, there are no other better methods in the iPhone SDK.
Here
1. Install the Compiler
There are many Objective-C compilers. LLVM is developed from GCC and is mainly used on Apple's platform. GNU can use GnuStep, which is a program called Objective c.Go to the download page and download the above three software
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service