Mario tsai

under iOS13

class viewModel: {    var reloadCount: Int = 0    //ViewModel send to View   => react the event
var reloadCollectionView: ( ()->() )?

//View call ViewModel => user touch the Buttom (event)
func onTapCellButton() {
//changeDataFirst
reloadCount += 1 self. reloadCollectionView?()
}
}

--

--

It’s a true story. It happens by accident.

class VC1 :UIViewController() {  let viewModel = VC1ViewModel()  func callVC2(){     let vc2 = UIViewController()     vc2.onTap = { (value) in         self.viewModel.callMom()  }  deinit(){
print("VC1 dead")
}
}

So, When VC1 dismiss or popup. VC2 and viewModel still in alive.

It prints nothing.

Change callVC2 like this

func callVC2(){    let vc2 = UIViewController()    vc2.onTap = { [weak self] (value) in        self?.viewModel.callMom()}

When VC1 dismiss or popup, Your memory is free!!!

--

--

快速入門

use Realm

let realm = try! Realm()

Make a Model

import Foundation

import RealmSwift

class LogData: Object{

@Persisted(primaryKey: true) var _id: ObjectId

@Persisted var date: String?

@Persisted dynamic var time: String?

convenience init(content: String){

self.init()

}

}

func addNewLog(_ time:String,_ date:String) -> LogData{

let newLog = LogData()

newLog.time = time

newLog.date = date

return newLog

}

func save() {

let newLog = self.addNewLog(selectedTime, didSelectDate)

try! realm.write{

realm.add(newLog)

}

print(newLog)

}

--

--

增刪改檔案後記得下 composer dump-autoload

### 顯示路由
php artisan route:list

### new 一個controller
//做一個ProductController
php artisan make:controller ProductController

//做一個ProductController 包含基本的增刪修改
php artisan make:controller ProductController — resource

ps: Laravel8 用router 要在RouteServiceProvider 裡面增加變數 protected $namespace = ‘App\Http\Controllers’;

### new 一個table
//做一張表 members
php artisan make:migration create_members

##### Route Bug
-> php artisan serve 後連接有正常accept close,但是沒有畫面
-> 有重複的路徑 檢查Route 然後下 php artisan optimize 清掉cache

--

--

Big company has lots of ObjC code

/## Swift

class Person: NSObject {

var _name: String

init(name: String){

_name = name

}

function setName(name:String){

_name = name

}

}

run in playground

Person.setName(“Dancer”)

/##ObjC

@interface Person : NSObject {

NSString* _name;

}

-(void)setName: (NSString*) name;

-(NSString*) name;

@end

@Implementation Person

-(void)setName: (NSString * )name {

_name = name;

}

-(NSString*) name {

return _name;

}

Actually, run in Main.m

Person* p1 =[Person new];

[p1 setName:@”Dancer”];

NSLog(@”%ld”, [p1 age]);

--

--

Big company has lots of ObjC code

Swfit -> ObjC

/##Swift

var name:String = Mario

print(name)

/## ObjC

@interface ViewController ()

@property (nonatomic, strong) NSString* userName;

@end

@implementation ViewController

NSLog(@”%@”, self.userName);

@end

--

--

MySQL DB make Table

use Illuminate\Support\Facades\DB;

  1. getData from DB

Within Function

{

$data = DB::table(‘table_name’)-> getData();

}

2. make a table

Command

php artisan make:migration create_AAAAAs

Set your Column

public function up()
{
Schema::create('AAAAAs', function (Blueprint $table) {
$table->id();
$table->string('title') ;
$table->string('content');
$table->integer('price');
$table->timestamps();
});
}

And Command

php artisan migrate

--

--

Basic move

Show all Route

>php artisan route:list
  • > ps.
RouteServiceProvider 
protected $namespace = 'App\Http\Controllers';

New a controller

>php artisan make::controller NewController --resource
  • (resource including CRUD)

--

--

Mario tsai

Mario tsai

Major in physical education. Football referee. And high interest in looking the world through the numbers.