Initializers, also known as constructors in other programming languages, have two types: Designated init and Convenience init. They are used to initialize properties or customize a variable or object for classes or structs.

Designated init

This type of the Initializer is frequently seen in Swift class, also named as primary Initializer

  • Designated initializers are the primary initializers for a class
  • A class must have at least one Designated initializer
  • A struct can have Designated initializers, if not the compiler will automatically generate one with all properties
  • Used to initialize the property values

Example of designated init for a class:


TLDR

Both git rebase and git merge are used to synchronise changes between branches. The difference is git rebase will revise the commits but keep a clean organised history, while git merge will keep all the original commits and add ones automatically but gives out a circuit board like history.

Real world scenarios

Image you have two branches: feature and master. feature is from master, after some time, for some reason, master has some changes which feature doesn't have

Git merge


Actions and func are another ways to create delegates.

Action is a delegate that points to a method which in turn accepts one or more arguments but returns no value.

Func is a delegate that points to a method that accepts one or more arguments and returns a value.

  • Action and Func can be used with delegates
  • Action and Func can be used as method parameters

Example of Action

Action doesn’t return any value.

// action with generic type
Action<Book> printBookTitle = delegate(Book book)
{
Console.WriteLine(book.Title);
};
printBookTitle(book);


// action without generic type
Action printLog = delegate {
Console.WriteLine("log");
};
printLog();

Example of Func

Takes one…


Recently I was working on a legacy project written in Objective-C, which reminded me of the early days when working on Objective-C projects.

In the code I saw few things like the following which defines a constant:

#define car_price 300

#define creates a macro which simply do the replacement for the compiler. In the above code, compiler doesn't know the type of the card_height. It must be converted to a float value when using. So it is not type-safe.

Instead of using a macro to define a constant, it is a better way to use const to define a constant…


This article demonstrates how to connect iMessage service to your Android phone/pad so that you can contact your iPhone friends freely from now on. To finish the article will take 5 mins.

Prerequisite

  • A mac laptop or server
  • Android Phone
  • iPhone (optional for testing)

Features of AirMessage:

  • Safe: all the messages are stored and transited through your own mac and network
  • FREE

Install the AirMessage

This part has two main steps:

1, Install the AirMessage server on your Mac

This will forward new iMessages to your Android devices. Download the AirMessage Server for macOS from https://airmessage.org/install/


What is Swift Package?

According to Apple’s doc:

For developers, Swift Package has the native support from Apple, which is recommended way of using 3rd libraries.

How to use

Go to FileSwift PackageAdd Package Dependency:


Recently I joined a project where the architecture follows the Clean-Swift VIP Pattern. This article is an overview and some thoughts from a mobile developer’s perspective who have NEVER touched the VIP architecture before. This article will show the basic concepts of VIP Architecture and how are they work, hope to help someone who puts their hands on this like me.

Why VIP Architecture

As a government project, there are several developers working on the same repo, and there are many PR and merging happening every day. The VIP architecture is more suitable for a project if:

  1. Many developers are working on the…

Needone App

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