This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| For explanation please go to the post: https://needone.app/compiler-directives-in-swift/ | |
| */ | |
| // Environment Checking | |
| var url = "" | |
| #if DEBUG | |
| // use localhost while under debug mode | |
| url = "https://localhost" | |
| #else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use launch to create coroutines | |
| // https://needone.app/introduction-to-coroutine-in-kotlin/ | |
| import kotlinx.coroutines.* | |
| fun main() { | |
| // Start a coroutine using the launch function | |
| val job = GlobalScope.launch { | |
| // Perform a long-running task in the background |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| // example of string key and value is string | |
| Dictionary<string, string> openWith = new Dictionary<string, string>(); | |
| // example of int key and value is a list | |
| Dictionary<int, string[]> OtherType = new Dictionary<int, string[]>(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @interface ViewController () | |
| @property (nonatomic) float value; | |
| @end | |
| @implementation ViewController | |
| - (float)value { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyClass { | |
| lazy var names: NSArray = { | |
| let names = NSArray() | |
| print("Only run at the first time access") | |
| return names | |
| }() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // action with generic type | |
| Action<Book> printBookTitle = delegate(Book book) | |
| { | |
| Console.WriteLine(book.Title); | |
| }; | |
| printBookTitle(book); | |
| // action without generic type | |
| Action printLog = delegate { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct PurchaseButtonView_Previews: PreviewProvider { | |
| static var previews: some View { | |
| VStack { | |
| PurchaseButtonView(title: "Buy") { | |
| print("Buy button clicked") | |
| }.padding() | |
| PurchaseButtonView(title: "Sell") { | |
| print("Buy button clicked") | |
| }.padding() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct PurchaseButtonView: View { | |
| var title: String | |
| var callback: () -> Void | |
| var body: some View { | |
| Button( | |
| action: { self.callback() }, | |
| label: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| disabled_rules: # rules you don't want to use | |
| - trailing_comma | |
| opt_in_rules: # rules you want to use | |
| - array_init | |
| - closure_body_length | |
| - closure_end_indentation | |
| included: # include directories | |
| - Source |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do | |
| swiftformat "${line}"; | |
| git add "$line"; | |
| done | |
| swiftlint --quiet --strict |
NewerOlder