Viewing posts for the category Omarine User's Manual

Swift: Definition of overloaded operators

In order to avoid the compiler from complaining and requesting data type conversion, when doing addition a Double number plus an Int number the operator + needs to be overloaded. In the code below, the four binary operators +, -, *, / are overloaded where the left side is a Double and the right side is an Int

Swift: Working with files

We can use file handling functions in C to work with file pointers.
In the example below, we declare the file pointer fp, open the file hello.txt and then write to the file two lines of text, the first line is "Hello", the second line is "World!"

Swift: Virtual base class and polymorphism

The protocol in Swift is similar to the virtual base class in C ++ except that it not only requires the classes using the protocol to implement the declared methods, the protocol also adds requirements that the classes must conform to.

In the program below both Triangle and Square classes use the Shape protocol

Optional type in Swift

Optional type is used when the value may be absent. A variable or constant is optional if there is a question mark after the type name. For example

var index: Int? = nil

Because the value of an optional type may be nil, the compiler does not allow access to its data. For example, the print(index) statement will report an error.
However, we can check its value condition using if. For example

if index != nil { ... }

We can also check for the condition of the value initialization of another constant where the optional value is assigned to the constant. For example

if let i = index { print(i) }

If the value of index is nil, the constant initialization fails and returns false, then the statement block in the body of the conditional expression is not executed. Conversely, if the index has a value, that value is rendered

AppArmor vs SELinux

SELinux controls access based on the labels of the files and processes while AppArmor controls access based on the paths of the program files. While AppArmor is easier in administration, the SELinux system is more secure.
AppArmor's motto is to allow everything then tighten gradually. In contrast, SELinux refuses everything then loosens up gradually. Right here we have seen that SELinux places more emphasis on security. For example, for preventing applications from accessing the password file (/etc/shadow), SELinux only needs to grant a few dedicated programs permission while AppArmor is difficult to prevent thousands of applications if don’t want to say impossible in the case of a strange program that has no profile and is therefore not confined. The AppArmor's App prefix shows us that it cares about the apps rather than the system. Below is a detailed comparison in the present moment