所以我有一个postDict
as [String: AnyObject]
,我有一个模型类Post
.
是否有一种快速转换postDict
为Post
对象数组的方法,以便在将单元格出列时,它将是:
cell.textLabel.text = posts[indexPath.item].author
import UIKit
import Firebase
class ViewController: UIViewController {
var posts = [Post]()
override func viewDidLoad() {
super.viewDidLoad()
let ref = FIRDatabase.database().reference().child("posts").queryLimitedToFirst(5)
ref.observeEventType(FIRDataEventType.ChildAdded, withBlock: { (snapshot) in
let postDict = snapshot.value as! [String : AnyObject]
print(postDict)
//convert postDict to array of Post objects
})
}
}
class Post: NSObject {
var author: String = ""
var body: String = ""
var imageURL: String = "" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试React-Hook-form
复选框的简单代码如下:
import React from 'react'
import { useForm } from 'react-hook-form'
export default function App() {
const {
register,
handleSubmit,
formState: { errors },
} = useForm()
const onSubmit = (data: any) => console.log(data)
console.log(errors)
return (
<div className='mx-auto justify-center p-32 flex'>
<form onSubmit={handleSubmit(onSubmit)}>
<div className='p-2'>
<label htmlFor=''>January</label>
<input
type='checkbox'
placeholder='January'
{...register('January', {})}
className='mx-3'
checked
/>
</div>
<div className='p-2'>
<label htmlFor=''>February</label>
<input
type='checkbox'
placeholder='February'
{...register('February', {})}
className='mx-3'
/>
</div>
<input type='submit' />
</form>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
我可以正确提交表单,但我喜欢一月复选框作为复选框开始,但是当我如代码中所示放置“选中”时,我不知何故无法“取消选中”它。
我似乎错过了一些东西,任何帮助将不胜感激。
我有一个 React/nextjs 应用程序,并且有 firebase.js,如下所示:
import firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/analytics'
import 'firebase/firestore'
const firebaseConfig = {
apiKey: '...'
}
try {
firebase.initializeApp(firebaseConfig)
firebase.analytics()
} catch (err) {
if (!/already exists/.test(err.message)) {
console.error('Firebase initialization error', err.stack)
}
}
export default firebase
Run Code Online (Sandbox Code Playgroud)
我不断得到
Firebase初始化错误ReferenceError:导航器未定义
将分析添加到 firebase.js 文件后。将分析添加到应用程序的正确方法是什么?
我正在使用Firebase提供的代码进行Google身份验证,并且以某种方式,身份验证成功,但是电子邮件未正确导入到Firebase。
https://firebase.google.com/docs/auth/ios/google-signin
如您在以下屏幕截图中所见,该电子邮件为空白。当我看着调试器时,它显示为nil。
我单击了“允许在身份验证期间查看电子邮件”,但是我认为仍有一些设置未正确完成。有人可以帮我看看吗?我有兴趣使用电子邮件为每个用户创建用户名。
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
if let error = error {
print(error.localizedDescription)
return
}
let authentication = user.authentication
let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,
accessToken: authentication.accessToken)
FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
if error != nil {
print(error?.localizedDescription)
return
}
print("User logged in with Google...")
self.performSegueWithIdentifier("ToHome", sender: nil)
}
}
Run Code Online (Sandbox Code Playgroud) google-authentication ios firebase swift firebase-authentication
I have this NextJS site where there is this getStaticProps that load data from Firestore.
I have this:
return {
props: {
allPosts: posts,
},
revalidate: 60,
}
Run Code Online (Sandbox Code Playgroud)
where from what I know will load data from firebase every one minute. However, it doesn't seem to work and data are just not updated.
Is this revalidate an experimental feature? Anyway that I can get it to work? Else I would have to rebuild and export frequently.
javascript reactjs server-side-rendering next.js google-cloud-firestore
不久前,我尝试使用以下方式提交应用程序Xcode version 11.1 (11A1027)
,但收到了一封来自 Apple 的电子邮件,其中包含以下消息:
ITMS-90424:无效的 Swift 支持 - SwiftSupport 文件夹为空。使用当前公共 (GM) 版本的 Xcode 重新构建您的应用程序并重新提交。
据我所知,11A1027
已经是发布版本了,所以我不太确定为什么需要使用 Xcode 的 GM 版本。有人有什么主意吗?
我尝试了其他帖子中建议的一些方法,但不知何故无法解决它。
这是 Xcode 中的错误吗?
我对 Django 很陌生。
我正在使用 Django 3,当我创建一个新的 Django 项目时,urls.py 文件包含以下代码:
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
Run Code Online (Sandbox Code Playgroud)
我认为这个正则表达式代码适用于旧版本的 Django。较新的 Django 3 应该使用path
.
我做错了什么吗?
如何为 flutter 2.0 的 firestore 快照构建 flutter 类
我尝试过这样的事情:
import 'package:cloud_firestore/cloud_firestore.dart';
class Post {
final String pid;
final String description;
final DocumentReference reference;
Post.fromMap(Map<String, dynamic> map, this.pid, this.description, {required this.reference})
Post.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data(), reference: snapshot.reference);
@override
String toString() => "Post<$pid:$description>";
}
Run Code Online (Sandbox Code Playgroud)
但出现错误,指出需要 3 个位置参数,但找到了 1 个。
如果您使用过像阿拉伯语这样的 RTL 语言,也许您可以给我一些关于如何在 swiftui 中正确显示语言的指南。
\n我尝试了类似下面的方法,但实际上不正确,因为它们仍然保持对齐。
\n if nativeLanguage == "Arabic" {\n HStack {\n Spacer()\n Text("\xd9\x85\xd8\xb1\xd8\xad\xd8\xa8\xd8\xa7 \xd9\x87\xd8\xb0\xd8\xa7 \xd9\x86\xd8\xb5 \xd8\xb7\xd9\x88\xd9\x8a\xd9\x84 \xd9\x88\xd9\x84\xd9\x83\xd9\x86\xd9\x87 \xd8\xa8\xd8\xa7\xd9\x84\xd9\x84\xd8\xba\xd8\xa9 \xd8\xa7\xd9\x84\xd8\xb9\xd8\xb1\xd8\xa8\xd9\x8a\xd8\xa9 \xd9\x81\xd9\x83\xd9\x8a\xd9\x81 \xd9\x8a\xd9\x85\xd9\x83\xd9\x86 \xd8\xb9\xd8\xb1\xd8\xb6\xd9\x87 \xd8\xa8\xd8\xb4\xd9\x83\xd9\x84 \xd8\xb5\xd8\xad\xd9\x8a\xd8\xad")\n .font(.system(size: 16))\n .foregroundColor(Color.gray)\n }\n } else {\n HStack {\n Text("Hello there")\n .font(.system(size: 16))\n .foregroundColor(Color.gray)\n Spacer()\n }\n }\n
Run Code Online (Sandbox Code Playgroud)\n 在 firestore 中你可以有如下规则:
service cloud.firestore {
match /databases/{database}/documents {
match /products/{document=**} {
allow read, write: if true;
}
}
Run Code Online (Sandbox Code Playgroud)
if true
这行中的意思是什么: allow read, write: if true;
?
如果是的话怎么办if false
?
swift ×4
firebase ×3
javascript ×3
reactjs ×3
next.js ×2
django ×1
django-urls ×1
flutter ×1
ios ×1
python ×1
swiftui ×1
typescript ×1
vue.js ×1
xcode ×1
xcode11 ×1