From C ++ to objective-C

Source: Internet
Author: User
Tags vars

1. the header file is still. h
2. cpp is changed to. M.
3. # import replaces # include, # import is guaranteed to be referenced only once, which is equivalent to # ifndef # define # endif mode in. h.
4. Use @ interface... @ End to declare the class and replace Class classname {}
5. Use @ implementation... @ End to implement classes
6. Put data members in @ interface classname: parent {... }, The default permission is @ protected, which is called instance variables in objc.
7. Put member functions in @ interface classname: parent {}... @ End, which is called instance methods in objc
8. The declaration method of instance methods is: scope (returntype) methodname: (parameter1type) parameter1name;
9. scope is divided into two types: instance and class, which are represented by-and + respectively.
10. The method is called [ Object Method], equivalent Object -> Method ()
11. The method with parameters is called [ Object Method: parameter]
12. No Object , Only pointer Object
13. Common constructor: Object * OBJ = [[ Object Alloc] init]
14. destructor method: [OBJ release] 15. method declaration with multiple parameters: scope (returntype) methodname: (parameter1type) parameter1name label1name: (parameter2type) parameter2name... ;
16. labelname is not required
17. This special syntax comes from smalltalk.
18. Private: [list of vars] protected: [list of vars] public: [list of vars] changed to @ private, @ protected, @ public
19. Class variable implements implicit regression using the static method
20. + (void) initialize will be called during construction
21. objc generally uses the @ symbol to represent the derivative part of the language.
22. objc uses the ID to list the pointer of the demonstration object
23. Support for dynamic Type Recognition
24. The categories mechanism can be used to add new functions without inheriting existing classes.
25. The posing mechanism allows child to replace parent
26. Protocol is equivalent to pure virtual class
27. objc is managed by two memory methods: 1) Retain and release, 2) Retain and release/autorelease
28. The foundation is equivalent to STL. nsarray corresponds to vector and nsdictionary corresponds to map.
29. objc does not support namespace
30. overload is not supported

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.