Memory management in Rust

Ownership is Rust’s most unique feature, and it enables Rust to make memory safety guarantees without needing a garbage collector. Therefore, it’s important to understand how ownership works in Rust

Ownership

Ownership is how Rust manages memory. It's a set of rules that the compiler checks at compile time which don't slow down the program while running.

The Stack and the Heap

  • both stack and heap, are parts of memory available to a program during run time
  • data on the stack must have known, fixed size at compile time
  • data with unknown size at compile time or size that might change must be stored on the…


How would you describe a Swift language?

It’s a type-safe language for protocol-oriented programming
Safe — fast — expressive
Swift language features

  • Closures unified with function pointers
  • Tuples and multiple return values
  • Generics
  • Fast and concise iteration over a range or collection
  • Structs that support methods, extensions, and protocols
  • Functional programming patterns, e.g., map and filter
  • Powerful error handling built-in
  • Advanced control flow with do, guard, defer, and repeat keywords

POP (Protocol oriented programming)

the protocol is a blueprint of methods.

protocol-oriented is an approach or programming paradigm
In Swift, value types are preferred over classes. However, object-oriented concepts don’t work well with structs and enums: a…


Chapter 2 :- Naming

How much time do you spend writing code vs reading code?!
Indeed, the ratio of time spent reading versus writing is well over 10 to 1
“Uncle Bob”

Names are everywhere in software.
We name our variables, our functions, our arguments, classes, and packages.
We name our source files and the directories that contain them.
We name our jar files and war files and ear files.
We name and name and name.
Because we do so much of it, we’d better do it well.
What follows are some simple rules for creating good names.

Use Intention-Revealing Names

Basically, don’t…


Photo by Max Duzij on Unsplash

By default, all methods listed in a Swift protocol must be implementing in a conforming type. However, there are two ways you can work around this restriction depending on your need
The first option is to mark your protocol using the @objc attribute ( this means it can be adopted only by classes, it does mean you mark individual methods as being optional )

@objc protocol PaymentActionViews {   @objc optional  func hideView(view: UIView)
@objc optional func showView(view: UIView)
func setSelectButton(button: UIButton)
}

the second option
write default implementations of the optional methods that do nothing or do default implementation ( this is better option )

protocol Printable{
func canPrint() -> Bool
}
extension Printable{ func canPrint() -> Bool{
return true
}
}


Photo by Emile Perron on Unsplash

Problem

You have a conditional that performs various actions depending on object type or properties.

  • You do not have to read the following code ( it’s a piece of shit ) *
{   
if canBook == false{
hideWhileCash()
bookedStatus.text = "Locked"
paymentTypeStack.isHidden = true
process.isHidden = true…


CLeanCode

chapter 1

I used this summary of some key points that I made to study the book Clean Code.
I hope it helps others.

(Note: this summary doesn’t exclude the need to read the book.)

first of all , I would like to highlight a few quotes


Clean Swift VIP

Clean Swift (a.k.a VIP) is Uncle Bob’s Clean Architecture applied to iOS and Mac projects. The Clean Swift Architecture is not a framework. It is a set of Xcode templates to generate the Clean Architecture components for you. That means you have the freedom to modify the templates to suit your needs.

  • View Controller
  • Models
  • Router
  • Worker
  • Interactor
  • Presenter

View Controller

View Controller starts and ends the VIP cycle sends data to the Interactor though it doesn’t get responses from the Interactor This class has a one-sided interaction with the Presenter View Controller gets responses from the Presenter but can’t transfer anything…

Ahmed Adam

iOS Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store