During the work, when chatting with iOS colleagues, found that iOS development is also very interesting, so want to learn iOS development, colleagues recommend this book, Objective-c, because before have done Android development, so study this book, Just familiar with objective-c grammar habits, use habits, see if there is nothing in Java, but also remember some notes, because there is the original Android Foundation, so some of the same did not write down, suitable for Java to objective-c, just getting started, If you want to study, or take a good look at the book----objective-c program design to find.
1. Keyboard Input:
scanf ("%i", &number);
2. The system automatically implements the get, set method
In the interface section @property int numerator,denominator
In implementing part @synthesize Numerator,denominator
So you do not have to write the get, set method, and run a higher efficiency, do not declare variables;
3. Methods with multiple parameters
-(void) Setto: (int) n over: (int) D;
-(int) set: (int) n: (int) d;//method without parameter name
4. Passing the class object as a parameter
-(void) Add: (fraction *) f;//incoming reference to class object
5. Declaring a reference to a class
@class Xypoint; Just a simple explanation xypoint is a class, in the subsequent references will not error, but if used to Xypoint method, or use #import "";
6.id DataValue;
Complex *c = [[Complex alloc]init];
DataValue = C;
DataValue can call all the methods of complex, at run time to determine the method that needs to be called dynamically.
[C Ismemberofclass: [Complex class]];//to determine if C is a member of Complex
[C Iskindofclass: [Complex class]];//determines if C is a member of Complex or its subclasses
[C Respondstoselector: @selector (setreal:andimaginary:)]//c response Setreal:andimaginary: Method
[Complex instancesresponsetoselector: @selector (setreal:andimaginary:)]//complex response Setreal:andimaginary: Method
[C Performselector @selector (setreal:andimaginary:)]//execution Setreal:andimaginary: Method
7. Define a global variable and an external variable
Declare global variables outside of all methods, classes, and function definitions
Use an extern + variable to use or change the value of a global variable when used
Define a global but not an external variable
Using the static definition, only the part after which the variable is defined in this file can be used, and no other file can
8. Assigning another name to the data type
typedef int Counter;
Counter J;
typedef number *NUMBEROBJECT;
Numberobject myvalue;
Number *myvalue;
9. Classification
You can modularize the definition of a class into groups or categories of related methods. Provides an easy way to extend existing classes without having to access the class's source code or create subclasses
Create an interface section of a taxonomy
The name of the @interface fraction (mathops)//classification is mathop, which expands the fraction
Create an implementation section of a taxonomy
@implementation Fraction (Mathops)
Extension of Class-(unnamed category) @interface fraction ()//Do not specify a name
It is possible to extend a class by defining additional instance variables, as opposed to named classifications, which are disallowed in named classes, and declared methods must be implemented in the main implementation area and not implemented in separate implementation areas
10. Agreement
A list of methods for multiple file shares, only the method name, is not implemented in the class that adheres to the protocol. --Similar interface
@protocol Name
@optional//Select the Implementation method
@required//methods that need to be implemented
Compliance Agreement class name:nsobject< protocol name >
Determine compliance with an agreement [object Conformstoprotocol: @prot (protocol name)]
11. Block
Block definition
^ (void)
{
NSLog (@ "programing is Fun");
}
Block use
void (^printmessage) (int) =
^ (int n)
{
Nslogin (@ "program was fun%i", N);
};//definition of a block with; end
Printmessage (2);
Accessing the foundation document in 13.xcode Help-documentation
To display the desired one, press option and click the mouse
14. In the Nsarray array, only objects can be placed in, not using the basic data type (int, float, etc.), so for the number should use NSNumber, put the data to NSNumber ([NSNumber numberwithinteger:1]) In the Nsarray and in the
15. Variable string nsmutablestring subclasses of NSString
16. Immutable arrays Nsarray, variable array nsmutablearray (refers to the length of the array is not variable)
17. Dictionaries
Nsmutabledictionary----Variable Dictionary
Nsdictionary----Enumeration Dictionary (immutable, Dictionarywithobjectsandkeys all key values at initialization time)
When created, ends with nil
18. Documents
nsfilemanager--file creation, read data, write, rename, delete, exist, attribute, copy, two file contents are the same
Nsfilemanager *FM = [Nsfilemanager defaultmanager];//initialization
NSData used to set a buffer, read the contents of a file into a buffer, or write the contents of a buffer to a file
NSData *filedata;
FILEDATA = [FM contentsatpath:@ "File1name"];//reads the contents of the File1name file into FileData
[FM createfileatpath:@ "File2name" Contents:filedata attributes:nil]//writes the contents of FileData to File2name
nsfilehandle--Open, read and write to a file, find a specified location, read or write a specific number of bytes
Nsurl
Datawithcontentsofurl (Dictionarywithcontentsofurl, Arraywithcontentsofurl) can be used to read any type of data on the website
NSBundle
When creating an app, the system stores the relevant data into the app package, accessing these resources using NSBundle
[[NSBundle mainbundle]pathforresource:@ "filename" OfType: @ "TXT"];
[[NSBundle mainbundle]pathsforresourcesoftype:@ "jpg" indirectory:@ "birdimages"];
(/) indicates the root directory
(~) indicates the household directory ~/filename
19. Copying
Compliance <NSCopying><NSMutableCopying> Agreements
Direct "=" copy, which will be two variables pointing to the same object
Use
[Array Copy] (Shallow copy) copies another copy, but still points to the same address
20. Archive
WRITETOFILE:ATOMICALLY://Archive data to a file, you can use arrays, nsstring,nsdata and other objects to send messages,
DICTIONARYWITHCONTENTSOFFILE://read data to the object that sent the message
[Nskeyedarchiver archiverootobject:tofile:]//Archive content to file
[Nskeyedunarchiver unarchiveobjectwithfile:]//read content in a file
The above deposit is an array that reads the array, what type is stored, what type is read
Custom objects to follow
<NSCoding> protocols to implement Encodewithcoder, and Initwithcoder methods
Some common methods for common classes are summarized
http://download.csdn.net/detail/damengzai/8415179 Download
Objective-c programming of Android to iOS