IOS9 new characteristics of the generic type

Source: Internet
Author: User

Generics: restriction type

Why quit generics: catering to Swift

The role of generics: 1. Type of restriction; 2. Improve code specifications, reduce communication costs, see what's in the collection at a glance

Generic definition Usage: type < restriction type >

Generic declaration: When declaring a class, after the class < generic name >

Generic usage errors are reported only as warnings in OC

Benefits of Generics: 1. Remove from the array, you can use dot syntax

2. Add an element to the array with hints

Usage scenarios for generics in development: 1. To restrict collection types

ID is not used for dot syntax

Why can a collection use generics? To use generics, you must first declare the generic type. = "How to declare a generic type

Custom generics? When do I use generics? When declaring a class, it is not certain that some property or method type is determined when using this class, and it can take a generic

such as: Custom person class, some programming language (Ios,java), in the Declaration of people, not sure what the man will be, in the use of someone only to know what language. If generics are not defined, the default is ID

For parent-child type conversion generics: _coveriant: Covariant subclass to Parent class

_contravariant: Inverter-Parent Rotor class

Generics Note: In an array, the generic variable group adds a method, the generics do not take effect, and if you add elements using an immutable group, the generics have no effect.

IOS9 new characteristics of the generic type

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.