9.4. Introduction to Objective-C

发布时间 :2025-10-25 12:23:51 UTC      

Objective C is used in the development of iOS, which is an object-oriented language, so it is very simple for programmers who have mastered the knowledge of object-oriented language.

9.4.1. Interface and implementation

The files completed in Objective are called interface files, and the definition of such files is called implementation files.

A simple interface file, MyClass.h, will look like this:

@interface MyClass:NSObject{
// 类变量声明
}
// 类属性声明
// 类方法和声明
@end

执行MyClass.m文件,如下所示

@implementation MyClass
// 类方法定义
@end

9.4.2. Create object

Finish creating the object, as shown below

MyClass  *objectName = [[MyClass alloc]init] ;

9.4.3. Method (methods)

The methods declared in Objective C are as follows:

-(returnType)methodName:(typeName) variable1 :(typeName)variable2;

An example is shown below:

-(void)calculateAreaForRectangleWithLength:(CGfloat)length
andBreadth:(CGfloat)breadth;

You may wonder what an andBreadth string is, but its optional string can help us read and understand methods, especially when methods are called.

To call this method in the same class, we use the following statement.

[self calculateAreaForRectangleWithLength:30 andBreadth:20];

As mentioned above, the use of andBreath helps us understand that breath is 20. Self is used to specify that it is a class method.

类方法(class methods) You can access class methods directly without creating objects. They don’t have any variables associated with it. Examples are as follows:

+(void)simpleClassMethod;

It can be accessed by using the class name (assumed as the MyClass class name), as follows:

[MyClass simpleClassMethod];

实例方法 The object of the class that can be created only accesses the instance method and the instance variable to which memory is allocated. The method of the instance is as follows:

-(void)simpleInstanceMethod;

After creating an object of the class, it can access it. As follows:

MyClass  *objectName = [[MyClass alloc]init] ;
[objectName simpleInstanceMethod];

9.4.4. Important data types of Objective C

Serial number

Data type

1

NSString string

2

Basic types of CGfloat floating point values

3

NSInteger integer

4

BOOL Boolean type

9.4.5. Print log

NSLog is used to print a declaration that will be printed on the device log and the debug version of the console and on the separate debug mode.

Such as NSlog (@ “”)

9.4.6. Control structure

With a few additional provisions, most of the control structures are the same as those of C and C++

属性(properties)

Used to access the variable properties of the external class of the class

For example: @ property (non-atomic, strong) NSString*myString

访问属性

You can access a property using the dot operator, and to access the previous property, you can do the following

self.myString = @"Test";

You can also use the method of set, as follows:

[self setMyString:@"Test"];

类别(categories)

Class is used to add methods to an existing class. In this way, you can add methods to the class and even define the actual class in it without even executing the file. The sample category of MyClass, as follows:

@interface MyClass(customAdditions)
- (void)sampleCategoryMethod;
@end

@implementation MyClass(categoryAdditions)

-(void)sampleCategoryMethod{
   NSLog(@"Just a test category");
}

9.4.7. Array

NSMutableArray and NSArray are array classes used in ObjectiveC, the former is a mutable array, and the latter is an immutable array. It is as follows:

NSMutableArray *aMutableArray = [[NSMutableArray alloc]init];
[anArray addObject:@"firstobject"];
NSArray *aImmutableArray = [[NSArray alloc]
initWithObjects:@"firstObject",nil];

9.4.8. Dictionaries

NSMutableDictionary and NSDictionary are dictionaries used in Objective, the former mutable dictionary and the latter immutable dictionary, as follows:

NSMutableDictionary*aMutableDictionary = [[NSMutableArray alloc]init];
[aMutableDictionary setObject:@"firstobject" forKey:@"aKey"];
NSDictionary*aImmutableDictionary= [[NSDictionary alloc]initWithObjects:[NSArray arrayWithObjects:
@"firstObject",nil] forKeys:[ NSArray arrayWithObjects:@"aKey"]];
Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.