2020年2月7日金曜日

How to read the log from iOS devices.

Assuming running Xcode


  1.  Go Windows and Devices and then Simulators.
  2.  Choose the  device from the devices section on the left side screen.
  3.  Click Open Console

2020年2月1日土曜日

How to open picture with UiImage in Swift playgroud.

How to open picture with UiImage in Swift playgroud.


  1.  Open navigator side panel. 
  2.  See there are Sources and Resources folder.  select Resources
  3.  click + button at the bottom and choose add file to Resources
  4.  choose the image file 
  5.  use it on playground . ex 
    let uiImage = UIImage(named:  "testImage.jpg")



2020年1月31日金曜日

ios 13, how to change the text field placeholder color from storyboard

How to change  text field placeholder color from storyboard .


  1.  select the UITextfiled of which you want to change the color. if there are several text fields, you have to do the same procedure for each.
  2. open the identity inspector. see the pic.
  3. Find the User Defined Runtime Attributes  and click + button.
  4. Type a new row with Key Path  placeholderLabel.textColor. be reminded that this is for iOS13, Swift 5.0. if it is for lower version, type _placeholderLabel.textColor instead.
  5. choose Type color and select the color as your choice.

2020年1月28日火曜日

Swift on iOS13, UIView present

The change on iOS13,  UIView.present default style is card presentation

card presentation


to make it full screen is easy.

solution
to set .fullscreen or .overFullScreen to

modalPresentationStyle

for example

        let viewCon = SampleViewController2(nibName: "SampleViewController", bundle: .main)
        viewCon.modalPresentationStyle = .fullScreen
        self.present(viewCon, animated: true, completion: nil)



.fullScreen

Discussion

The views belonging to the presenting view controller are removed after the presentation completes.

.overFullScreen

Discussion

The views beneath the presented content are not removed from the view hierarchy when the presentation finishes. So if the presented view controller does not fill the screen with opaque content, the underlying content shows through.


2020年1月25日土曜日

swift, function type. prepare for functional programming with Swift - 1

Function Type
swift can show the type of the return value of a function.
This could be useful when implementing type matching by swift, so it is necessary to see the details of this.

see the official document 

Here is the very intro part of the explaining.

The function in the example below is called greet(person:), because that’s what it does—it takes a person’s name as input and returns a greeting for that person. To accomplish this, you define one input parameter—a String value called person—and a return type of String, which will contain a greeting for that person:
  1. func greet(person: String) -> String {
  2. let greeting = "Hello, " + person + "!"
  3. return greeting
  4. }

typealias
This will create obviously the alias of  a type.


  1. typealias (String) -> String = greetType
  2. func callGreet(callback: greetType) {
  3. let greeting = callback("Hello")
  4. // this is supposed to be greet(person: String) function
  5. return greeting
  6. }

Filter


Returns an array containing, in order, the elements of the sequence that satisfy the given predicate.

let numbers = [1,2,3,4,5]
let greaterThan2 = numbers.filter { $0 > 2}
print(greaterThan2)
[3, 4, 5]

Map

Returns an array containing the results of mapping the given closure over the sequence’s elements.


let cast = ["Vivien", "Marlon", "Kim", "Karl"]
let lowercaseNames = cast.map { $0.lowercased() }
print(lowercaseNames)
["vivien", "marlon", "kim", "karl"]
let letterCounts = cast.map { $0.count }
print(letterCounts)
[6, 6, 3, 4]

Reduce

Returns the result of combining the elements of the sequence using the given closure.

Declaration


func reduce(_ initialResult: Result, _ nextPartialResult: (Result, Element) throws -> Result) rethrows -> Result


let numbers = [1,2,3,4,5]
let numberSum = numbers.reduce(0, { x, y in
    x + y
})
print(numberSum)
15


2020年1月23日木曜日

javascript primitive string

Let's see below example

let s1 = '2 + 2'              // creates a string primitive
let s2 = new String('2 + 2')  // creates a String object
console.log(eval(s1))         // returns the number 4
console.log(eval(s2))         // returns the string "2 + 2"

String primitives and String objects

String primitives and String objects also give different results when using eval(). Primitives passed to eval are treated as source code; String objects are treated as all other objects are

ref

The new Windows Terminal

The terminal software installed as the default with WSL linux distribution is not really comfortable. (for example Ubuntu)

However finally I have the better terminal for WSL.
It is Windows terminal, as the name implying this is developed by Microsoft and is open sourced.

https://github.com/microsoft/terminal

It can be installed from Micosoft store but it is still preview.
I think i want to try to build from the source though,
the preview version is already comfortable and i feel really happy with it.