How to change text field placeholder color from storyboard .
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.
open the identity inspector. see the pic.
Find the User Defined Runtime Attributes and click + button.
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.
choose Type color and select the color as your choice.
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.
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.
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:
funcgreet(person: String) -> String {
letgreeting = "Hello, " + person + "!"
returngreeting
}
typealias
This will create obviously the alias of a type.
typealias (String) -> String = greetType
func callGreet(callback: greetType) {
letgreeting = callback("Hello")
// this is supposed to be greet(person: String) function
returngreeting
}
Filter
Returns an array containing, in order, the elements of the sequence that satisfy the given predicate.
letnumbers = [1,2,3,4,5]
letgreaterThan2 = 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.
letcast = ["Vivien", "Marlon", "Kim", "Karl"]
letlowercaseNames = cast.map { $0.lowercased() }
print(lowercaseNames)
["vivien", "marlon", "kim", "karl"]
letletterCounts = 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.
let s1 ='2 + 2'// creates a string primitivelet s2 =newString('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
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.
function update(o) { o.a = o.a + 1; o = { a: 100 }; }
and do the following test ,
>const obj = {a:1} >update(obj) console.log(obj)
what is the result ?
it would be 2. > console.log(obj.a)
1
note that
even if the object is const value, the object keys are not protected.
in the function update(o), first line of o.a is still seeing the value of the obj, which is out of the scope of the function, then second line, o = {a:100} , which is replacing o in the scope of function to a new object, however obj in the outside of the function is not changed.
NaN is not a number and would appear when you calculate number.
>const result = "foo" * 2;
it will give you NaN as result.
however this
>console.log(result === NaN);
it will print false
because
NaN compares unequal (via ==, !=, ===, and !==) to any other value -- including to another NaN value. Use Number.isNaN() or isNaN() to most clearly determine whether a value is NaN. Or perform a self-comparison: NaN, and only NaN, will compare unequal to itself.
>Number.isNaN(result) >isNaN(result) will return true
When Xcode said your device was not connected but actually it was connected.
it would be solved reboot however avoiding reboot, type the below command.
Here is a sample of creating your own UITabBarController and customise tab bar behaviour on ios. not only customising tint colour of icon or icon itself but also adding more functionality when switching tab, it required to make your own class inheriting UITabBarController but you want to use the views and tab bar controller scene from story board.
start from tab application default
remove segure from story board connected to views from tab bar scene
set story boad ID to each scene which would be navigated by the tab bar. (FirstView, SecondView for example)
create a new class MyTabBarController
```
class MyTabBarController: UITabBarController, UITabBarControllerDelegate {
var firstViewController: FirstViewController!
var secondViewController: SecondViewController!
// In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ } ```
set MyTabBarController as the class of tab bar controller in the story board
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.
A 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.
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@propertyWrapperstructEnvironmentObject<ObjectType> where 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"))
}
}
}
}
}
}