2020年1月16日木曜日

state property swift memo

what is @state property

Overview

SwiftUI manages the storage of any property you declare as a state. When the state value changes, the view invalidates its appearance and recomputes the body. Use the state as the single source of truth for a given view.
State instance isn’t the value itself; it’s a means of reading and mutating the value. To access a state’s underlying value, use its value property.
Only access a state property from inside the view’s body (or from functions called by it). For this reason, you should declare your state properties as private, to prevent clients of your view from accessing it.
You can get a binding from a state with the `binding` property, or by using the `$` prefix operator.

@Environment

Environment

A dynamic view property that reads a value from the view’s environment.

EnvironmentObject

A dynamic view property that uses a bindable object supplied by an ancestor view to invalidate the current view whenever the bindable object changes.

2020年1月14日火曜日

Javascript packages for Latex

mathjax

jsMath

katex

2020年1月10日金曜日

Swift Dictionary Grouping


     There is the comment in the Dictionary souce code.

    /// Creates a new dictionary whose keys are the groupings returned by the

    /// given closure and whose values are arrays of the elements that returned
    /// each key.
    ///
    /// The arrays in the "values" position of the new dictionary each contain at
    /// least one element, with the elements in the same order as the source
    /// sequence.
    ///
    /// The following example declares an array of names, and then creates a
    /// dictionary from that array by grouping the names by first letter:


let students = ["Kofi", "Abena", "Efua", "Kweku", "Akosua"]
let studentsByLetter = Dictionary(grouping: students, by: { $0.first! })

EnvironmentObject Swift

EnvironmentObject in Swiftaccording to apple's Document A dynamic view property that uses a bindable object supplied by an ancestor view to invalidate the current view whenever the bindable object changes.

Declaration

@frozen @propertyWrapper struct EnvironmentObject<ObjectTypewhere ObjectType : ObservableObject

what does that mean ?


my understanding is that variable wrapped @EnvironmentObject can be shared 
across all views and update view when the variable is updated.
This is like the way React/Redux store doing.
final class UserData: ObservableObject  {
    @Published var showFavoritesOnly = false
    @Published var landmarks = landmarkData
}
struct LandmarkList: View {

    @EnvironmentObject var userData: UserData

    var body: some View {
        NavigationView{
            List {
                Toggle(isOn: $userData.showFavoritesOnly  , label: {Text("Favorites only")})
                ForEach(userData.landmarks) { landdata in
                    if (!self.userData.showFavoritesOnly || landdata.isFavorite) {
                        NavigationLink(destination: ContentView(landmark:   landdata)) {
                            LandmarkRow(landmark: landdata)
                            }.navigationBarTitle(Text("Landmark"))
                        }
                    }
                }
        }
    }
}


2020年1月7日火曜日

Book for functional Analysis

I fond this book
It is a math book , not for functional programming.
Introductory Functional Analysis With Applications

2018年5月7日月曜日

port forwading to ssh on Debian on VirtualBox

I have used Linux subsystem for windows 10, however the performance was not really good. especially it's Io works very slow when it write on the drive. it takes more time when downloading source or compiling codes, it is really slow. I will try to use Debian on virtualBox to compare which is the better choice for developments.
VirtualBox to open port 22 on 127.0.1.1  so let host port 3022 and forward it to 22.

name Protocol Host IP Host Port Guest IP guest Port
ssh 3022 22
$ssh -p 3022 username@127.0.0.1  
since the default ip address is 127.0.0.1 it should be changed later.

2018年4月8日日曜日

Bash on Windows subsystem with VcXcrv

Here simple what to do list for lunching xterm from bashonwindows
  1. install VcXsrv
  2. $ echo "export DISPLAY=:0.0" >> ~/.bashrc
  3. sudo sed -i 's$.*$tcp:host=localhost,port=0$' /etc/dbus-1/session.conf
  4. $ xterm &
https://sourceforge.net/p/vcxsrv/wiki/Home/
https://www.reddit.com/r/Windows10/comments/4rsmzp/bash_on_windows_getting_dbus_and_x_server_working/