Skip to content

Instantly share code, notes, and snippets.

View MarcoEidinger's full-sized avatar
🍫

Marco Eidinger MarcoEidinger

🍫
View GitHub Profile
@MarcoEidinger
MarcoEidinger / Snippets.json
Last active June 19, 2022 20:01
Snippets.json example
{"list":[{"IDECodeSnippetCompletionPrefix":"fnv","IDECodeSnippetCompletionScopes":["ClassImplementation"],"IDECodeSnippetContents":"- (void)<#method name#> {\n <#code#>\n}","IDECodeSnippetIdentifier":"6B47EC5A-B22B-4155-8C3F-632CCDFC4502","IDECodeSnippetLanguage":"Xcode.SourceCodeLanguage.Objective-C","IDECodeSnippetPlatformFamily":"all","IDECodeSnippetTitle":"创建一个返回值为空的方法","IDECodeSnippetUserSnippet":true},{"IDECodeSnippetCompletionPrefix":"swiftmark","IDECodeSnippetCompletionScopes":["ClassImplementation"],"IDECodeSnippetContents":"\/\/ MARK: - <#section#>","IDECodeSnippetIdentifier":"A54D18ED-62B6-4468-9F9F-880DEF598DAF","IDECodeSnippetLanguage":"Xcode.SourceCodeLanguage.Swift","IDECodeSnippetPlatformFamily":"all","IDECodeSnippetTitle":"swiftmark","IDECodeSnippetUserSnippet":true},{"IDECodeSnippetCompletionPrefix":"backItem","IDECodeSnippetCompletionScopes":["All"],"IDECodeSnippetContents":"[UIBarButtonItem qmui_backItemWithTarget:self action:@selector(<#selector name#>)];","IDECodeSnippetIdentifier":"4
@MarcoEidinger
MarcoEidinger / ContentView.swift
Created May 26, 2022 00:01
Gists for "Dump SwiftUI Environment efficiently" article
struct ContentView: View {
var body: some View {
VStack {
HStack {
Text("What is the magic color for this leaf node?")
}
.environment(\.magicColor, .blue)
}
.environment(\.magicColor, .red)
}
struct DumpingEnvironment<Content>: View where Content: View {
@Environment(\.self) var environmentValues
var optimizePrint = true
let content: Content
init(optimized: Bool = true, content: Content) {
self.optimizePrint = optimized
self.content = content
}
@MarcoEidinger
MarcoEidinger / ContentView.swift
Last active September 4, 2021 22:20
Gists for "Rich and interactive cards in SwiftUI" blog post. Original: https://github.com/MarcoEidinger/ms-adaptivecards-ios-example
import SwiftUI
struct ContentView: View {
var body: some View {
AdaptiveCardView(cardJson: "{ \"type\": \"AdaptiveCard\", \"version\": \"1.0\", \"body\": [ { \"type\": \"Image\", \"url\": \"http://adaptivecards.io/content/adaptive-card-50.png\", \"horizontalAlignment\":\"center\" }, { \"type\": \"TextBlock\", \"horizontalAlignment\":\"center\", \"text\": \"Hello **Adaptive Cards!**\" } ], \"actions\": [ { \"type\": \"Action.OpenUrl\", \"title\": \"Learn more\", \"url\": \"http://adaptivecards.io\" }, { \"type\": \"Action.OpenUrl\", \"title\": \"GitHub\", \"url\": \"http://github.com/Microsoft/AdaptiveCards\" }
}
}
@MarcoEidinger
MarcoEidinger / AdaptiveCardViewController.swift
Last active September 4, 2021 22:19
Gists for "Rich and interactive cards in SwiftUI" blog post. Original: https://github.com/MarcoEidinger/ms-adaptivecards-ios-example
import Foundation
import UIKit
import SafariServices
class AdaptiveCardViewController: UIViewController, ACRActionDelegate{
internal var cardJson: String = "serialized Adaptive Card JSON to be set"
override func viewDidLoad() {
super.viewDidLoad()
@MarcoEidinger
MarcoEidinger / AdaptiveCardView.swift
Last active September 4, 2021 22:19
Gists for "Rich and interactive cards in SwiftUI" blog post. Original: https://github.com/MarcoEidinger/ms-adaptivecards-ios-example
import Foundation
import SwiftUI
struct AdaptiveCardView: UIViewControllerRepresentable {
var cardJson: String
func makeUIViewController(context: Context) -> AdaptiveCardViewController {
let vc = AdaptiveCardViewController()
vc.cardJson = cardJson
@MarcoEidinger
MarcoEidinger / BridgingHeader.h
Last active September 4, 2021 22:19
Gists for "Rich and interactive cards in SwiftUI" blog post. Original: https://github.com/MarcoEidinger/ms-adaptivecards-ios-example
#ifndef BridgingHeader_h
#define BridgingHeader_h
#import "AdaptiveCards/ACFramework.h"
#endif /* BridgingHeader_h */
@MarcoEidinger
MarcoEidinger / Podfile
Last active September 4, 2021 22:19
Gists for "Rich and interactive cards in SwiftUI" blog post. Original: https://github.com/MarcoEidinger/ms-adaptivecards-ios-example
platform :ios, '14.0'
target 'MSAdaptiveCardExample' do
use_frameworks!
pod 'AdaptiveCards'
end
@MarcoEidinger
MarcoEidinger / MySchemeHandler.swift
Created August 24, 2021 00:17
Example for WKURLSchemeHandler implementation to replace custom url scheme with "https"
class MySchemeHandler: NSObject, WKURLSchemeHandler {
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
print("started for \(urlSchemeTask.request.url?.absoluteString)")
guard let url = urlSchemeTask.request.url else { return }
var components = URLComponents(url: url, resolvingAgainstBaseURL: true)
components?.scheme = "https"
guard let finalUrl = components?.url else { return }
print("proxy to \(finalUrl.absoluteString)")
let task = URLSession.shared.dataTask(with: URLRequest(url: finalUrl)) { receivedData, urlresponse, error in
guard let response = urlresponse, let data = receivedData else { urlSchemeTask.didFinish(); return }
// ...
#if DEBUG
struct ObjectMessageView_Previews: PreviewProvider {
static var singleButtonPreview: some View {
ObjectMessageView(model: UIModelDataContent(text: "text1", list: nil, form: nil, picture: nil, video: nil,
header: UIModelDataHeader(title: UIModelDataValue(value: "A very long title which is maybe even too long but who knows :) who can really tell? I don't know. That is a real interesting question. What do you think?", dataType: UIModelData.ValueType.text.rawValue, rawValue: nil,
label: nil,
valueState: nil),
subtitle: UIModelDataValue(value: "A very long subtitle which is maybe even too long but who knows :) who can really tell