iOS_@class_#import ""_#import <>_#include<>_#include ""

1681 ワード

一、概念
@class、#import"、#import<>、#include<>、#include"」は、クラスがインポートした文です.
二、区別
1. OC:@class 、#import ""、#import <>   OC  。
  1)@class :    ,          (    ,         ,      ,       ),              ,               。
  2)#import "":                 。
  3)#import <>:       (        )。
2. C/C++:#include <>、#include ""   C  。
  1)#include "":                   。(    )
  2)#include <>:                   。(     ,        ,            )。

三、事例
  • @class:ここにはViewControllerクラスとTwoViewControllerクラスがあり、2つのクラスが相互に参照されています.

  • まず、展示:ViewController.hファイル
    //
    //  ViewController.h
    //  forGoogle
    //
    //  Created by    on 2018/8/28.
    //  Copyright © 2018  OrganizationNameZL. All rights reserved.
    //
    
    #import 
    //     .m         TwoViewController  
    @class TwoViewController;
    
    @interface ViewController : UIViewController
    
    @property (nonatomic, strong) TwoViewController *two;
    
    @end
    

    次に、ViewController.mファイル
    //
    //  ViewController.m
    //  forGoogle
    //
    //  Created by    on 2018/8/28.
    //  Copyright © 2018  OrganizationNameZL. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "TwoViewController.h"
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    }
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    @end
    
    

    では、現在TwoViewControllerクラスの参照方式は同じなので、その参照方式を本稿に表示しません.
  • #import""と#import<>はクラスファイルで、引用符に直接インポートすればいいです.あまり言わない.