Skip to content

Instantly share code, notes, and snippets.

donchan922 donchan922

View GitHub Profile
View ContentView.swift
struct ContentView: View {
@Environment(\.managedObjectContext) var context
@State private var isShowingModal = false
var body: some View {
Button(action: {
self.isShowingModal.toggle()
}) {
Text("go to SubView")
}.sheet(isPresented: $isShowingModal) {
View swiftui-subview-coredata-error
Fatal error: Unresolved error Error Domain=Foundation._GenericObjCError Code=0 "(null)", [:]: file /Users/donchan922/Documents/swiftui-demo/swiftui-demo/ContentView.swift, line 50
2020-05-10 15:53:53.524880+0900 swiftui-demo[27664:1128900] Fatal error: Unresolved error Error Domain=Foundation._GenericObjCError Code=0 "(null)", [:]: file /Users/donchan922/Documents/swiftui-demo/swiftui-demo/ContentView.swift, line 50
(lldb)
@donchan922
donchan922 / ContentView.swift
Last active May 12, 2020
SwiftUIのタイマーアプリのサンプル。バックグラウンド再生対応で、タイマー完了時に通知する
View ContentView.swift
import SwiftUI
import UserNotifications
struct TimerView: View {
@State var start = false
@State var to: CGFloat = 0
@State var count = 0
@State var time = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
var body: some View {
@donchan922
donchan922 / ContentView.swift
Created Apr 18, 2020
SwiftUIでCore Dataを使ったToDoアプリのサンプルコードその2
View ContentView.swift
import SwiftUI
import CoreData
extension UIApplication {
func endEditing() {
sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
struct ContentView: View {
@donchan922
donchan922 / ContentView.swift
Created Apr 16, 2020
SwiftUIでグラデーションを使うサンプル
View ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
LinearGradient(gradient: .init(colors: [.yellow, .green]), startPoint: .top, endPoint: .bottom)
GeometryReader{ reader in
Button(action: {
}) {
View ContentView.swift
import SwiftUI
import GoogleMobileAds
struct AdView: UIViewRepresentable {
func makeUIView(context: Context) -> GADBannerView {
let banner = GADBannerView(adSize: kGADAdSizeBanner)
// 以下は、バナー広告向けのテスト専用広告ユニットIDです。自身の広告ユニットIDと置き換えてください。
banner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
banner.load(GADRequest())
View AppDelegate.swift
import UIKit
// import文を追加する
import GoogleMobileAds
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
View command
- Key: GADApplicationIdentifier
- Type: String
- Value: ca-app-pub-xxx
View Podfile
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'swift-demo' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for swift-demo
pod 'Google-Mobile-Ads-SDK'
You can’t perform that action at this time.