偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Objective-C中一些關(guān)鍵字 學(xué)好必知

移動開發(fā) iOS
本文介紹的是Objective C中一些關(guān)鍵字 學(xué)好必知,本文屬于幫助性質(zhì)的一片文章,幫助快速有效的去學(xué)習(xí)Objective C,先來看內(nèi)容。

本文介紹的是Objective-C中一些關(guān)鍵字 學(xué)好必知,本文屬于幫助性質(zhì)的一片文章,幫助快速有效的去學(xué)習(xí)Objective-C,先來看內(nèi)容。

關(guān)于變量的作用域

  1. protected —Methods defined in the class and any subclasses can directly access the instance variables that follow.This is the default case. 

該類和所有的子類中的方法可以直接訪問這樣的變量,這是默認的。

  1. private —Methods defined in the class can directly access the instance variables that follow, but subclasses cannot. 

該類中的方法可以訪問這樣的變量,子類不可以。

  1. public —Methods defined in the class and any other classes or modules can di- rectly access the instance variables that follow. 

除了自己和子類中的方法外,也可以被其他類或者其他模塊中的方法所訪問。開放性最大。

  1. package —For 64-bit images, the instance variable can be accessed anywhere within the image that implements the class. 

對于64位圖像,這樣的成員變量可以在實現(xiàn)這個類的圖像中隨意訪問。

全局變量(extern)

在程序的開始處,沒有在一個方法里面寫了

  1. int gMoveNumber=0

那么我們說這個變量就是全局變量,也就是說在這個模塊中的任何位置可以訪問這個變量。

這樣的變量也是外部全局變量,在其他文件中也可以訪問它。但是訪問的時候要重新說明下這個變量,說明的方法是:

  1. extern int gMoveNumber; 

當然我們也可以在聲明的時候加上extern關(guān)鍵字。

  1. extern int gMoveNumber=0

這樣的話在其他的類中使用還是需要重新說明一下了,而且這時候編譯器會給出警告。

如果這個全局變量只是在自己的類中使用,或者其他的類使用的它情況也比較小,那么我們把它定義成第一種情況,如果在外部文件使用的也比較多的話,那么我們把它定義成第二種情況。

這種定義其實違背了封裝性。

靜態(tài)變量(static)

因為全局變量是全局的,影響封裝,所以有時候要用靜態(tài)變量。

  1. static int gMoveNumber; 

這是這個變量是這個類中的靜態(tài)變量。如果不定義初始值的話為零。

如果靜態(tài)變量定義在方法中,那么這個變量在方法執(zhí)行完之后還是有效的,如果在第一次調(diào)用的時候改變了這個變量的值,那么在第二次調(diào)用的時候,這個變量的值是被改變過的值。

如果被定義在類中,那么這種改變也是有效的,就是作用域發(fā)生了改變。一個在方法中,一個在類中。

  1.   atomic和nonatomic 

nonatomic是告訴系統(tǒng)不要使用mutex(互斥)鎖定。這種鎖定會導(dǎo)致系統(tǒng)的性能低下,所以一般在多線程的時候使用atomic,平時多數(shù)用nonatomic。

  1.   @synthesize和@dynamic  
  2.   @synthesize will generate getter and setter methods for your property.  
  3.   @dynamic just tells the compiler that the getter and setter methods are implemented not by the 
  4. class itself but somewhere else (like the superclass)  
  5.   Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an 
  6. outlet for a property defined by a superclass that was not defined as an outlet:  
  7.   Super class: 

C代碼

  1.   @property(nonatomic, retain)NSButton* someButton;  
  2.   ...  
  3.   @synthesize someButton;  
  4.   @property(nonatomic, retain)NSButton* someButton;  
  5.   ...  
  6.   @synthesize someButton;  
  7.   Subclass:  
  8.   C代碼  
  9.   @property(nonatomic, retain)NSButton* someButton;  
  10.   ...  
  11.   @dynamic someButton; 

小結(jié):關(guān)于Objective-C中一些關(guān)鍵字 學(xué)好必知的內(nèi)容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-19 13:49:19

Objective-C 數(shù)據(jù)類型

2011-08-01 11:49:05

Objective-C

2013-07-10 11:31:10

iOS面試題Objective-CiOS開發(fā)

2011-08-04 13:55:10

Cocoa Objective- 文件

2009-08-13 09:49:16

C#關(guān)鍵字

2012-01-18 10:13:50

Objective-CiOSself

2013-08-26 14:58:48

App Store關(guān)鍵字優(yōu)化App營銷

2013-08-26 15:19:44

應(yīng)用商店AppStore關(guān)鍵字選取

2013-06-20 10:40:32

Objective-C實現(xiàn)截圖

2013-03-27 12:54:00

iOS開發(fā)Objective-C

2011-05-11 15:58:34

Objective-C

2011-05-11 11:20:26

Objective-C

2009-09-02 09:24:03

C# this關(guān)鍵字

2011-08-10 18:07:29

Objective-C反射

2009-08-21 14:58:56

C# this關(guān)鍵字

2009-06-22 15:36:00

如何學(xué)好java

2025-01-07 07:20:00

C++代碼開發(fā)

2011-08-03 16:55:05

Objective-C 代理

2011-08-04 09:35:09

Objective-C 編碼規(guī)范

2014-04-30 10:16:04

Objective-CiOS語法
點贊
收藏

51CTO技術(shù)棧公眾號