在我能做些什么来解决这个错误,任何想法,我想获得10个随机数字,所以我就可以查询火力一组包含随机数的问题.屏幕截图如下.我还添加了代码......
import UIKit
import Firebase
class QuestionViewController: UIViewController {
var amountOfQuestions = 2
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
//Use a for loop to get 10 questions
for _ in 1...10{
//generate a random number between 1 and the amount of questions you have
var randomNumber = Int(arc4random_uniform(amountOfQuestions - 1)) + 1
//The reference to your questions in firebase (this is an example from firebase …
Run Code Online (Sandbox Code Playgroud) 我使用自定义图像选择器来选择时间流逝,我想获取所选时间流逝的网址,以便我可以播放时间流逝.
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
for (PHAsset *asset in assets) {
NSURL *url = [NSURL URLWithString: assetURLgoesHere];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
AVPlayer *videoPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[videoPlayer play];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)
这就是我现在所拥有的,但我需要获得资产的网址.
我通常使用swift但这个自定义图像选择器是用objective-c编写的.所以我有点客观 - c菜鸟
更新的代码
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
for (PHAsset *asset in assets) {
- (PHImageRequestID)requestAVAssetForVideo:(PHAsset *)asset options:(PHVideoRequestOptions *)options resultHandler:(void (^)(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info))resultHandler
NSURL *url = [NSURL URLWithString: asset];
AVURLAsset *avAsset = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试查询Firebase以检查是否有任何用户,waiting: "1"
然后在返回快照时我想查看它是否等于nil.我试图这样做,但我使用的方法不起作用,如果快照不等于nil,我只有一些输出.我添加了当前的代码和Firebase中的JSON文本.
import UIKit
import Firebase
import Spring
class GamesViewController: UIViewController {
let ref = Firebase(url: "https://123test123.firebaseio.com")
var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
@IBAction func StartGamePressed(sender: AnyObject) {
print("test1")
var peopleWaiting: [String] = []
let userRef = Firebase(url:"https://123test123.firebaseio.com/users")
userRef.queryOrderedByChild("waiting").queryEqualToValue("1")
.observeEventType(.ChildAdded, withBlock: { snapshot in
print(snapshot.key)
if snapshot.key == nil {
print("test2")
let userData = ["waiting": "1"]
let usersRef = self.ref.childByAppendingPath("users")
let hopperRef = usersRef.childByAppendingPath("\(self.ref.authData.uid)")
hopperRef.updateChildValues(userData, withCompletionBlock: {
(error:NSError?, ref:Firebase!) in
if (error != nil) {
print("Data could not be …
Run Code Online (Sandbox Code Playgroud) 我正在尝试允许用户通过搜索用户名来启动游戏并关注其他用户.我需要能够确保具有该用户名的用户存在.我正在使用以下代码但是虽然它if
被调用但是else
它应该被调用.
let checkWaitingRef = Firebase(url:"https://test.firebaseio.com/users")
checkWaitingRef.queryOrderedByChild("username").queryEqualToValue("\(username!)")
.observeEventType(.ChildAdded, withBlock: { snapshot in
if snapshot.value.valueForKey("username")! as! String == username! {
} else {
}
Run Code Online (Sandbox Code Playgroud)
JSON数据树
{
"097ca4a4-563f-4867ghj0-6209288bd7f02" : {
"email" : "test1@tes1.com",
"uid" : "097ca4a4-563f-4867ghj0-6209288bd7f02",
"username" : "test1",
"waiting" : "0"
},
"55a8f979-ad0d-438u989u69-aa4a-45adb16175e7" : {
"email" : "test2@test2.com",
"uid" : "55a8f979-ad0d-438u989u69-aa4a-45adb16175e7",
"username" : "test2",
"waiting" : "0"
}
}
Run Code Online (Sandbox Code Playgroud) 是否可以仅在通过检索的对象上使用.select
(JS)/ selectKeys
(Android).include()
?
比如A类有一个指向B类的指针,当我查询A类的时候,我想要的是A类的所有内容和B类的几个选定的字段,这可能吗?
parse-platform parse-android-sdk parse-javascript-sdk parse-server back4app
我有一个随机生成的数字数组,然后我尝试查询Firebase的问题,该问题等于所选数字数组中索引[0]的值.目前的问题是我收到了错误Cannot subscript a value of type '[UInt32]'
.PS我在swift方面并不是非常有经验,因此精确的代码解决方案会非常苛刻!我还附上了我的火力架结构......
import UIKit
import Firebase
class QuestionViewController: UIViewController {
let ref = Firebase(url: "https://123test123.firebaseio.com/questions")
override func viewDidLoad() {
super.viewDidLoad()
// An empty array to hold the selected numbers
var selectedNumbers: [UInt32] = []
// A range of acceptable numbers
let randomNumberRange = 1...10
// How many numbers are needed?
let randomNumbersToChoose = 10
// Crash if asking for more numbers than are available in the range
assert(randomNumberRange.count >= randomNumbersToChoose, "Must have enough …
Run Code Online (Sandbox Code Playgroud) 我想将活动指示器放在自定义类中,以便可以从任何视图控制器启动/停止它。
以下代码在启动活动指示器但不停止时有效,我该怎么做?
static func activityIndicatorFunction(view: UIView, targetVC: UIViewController, animate: Bool) {
var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
if animate == false {
activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents()
} else {
activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
activityIndicator.backgroundColor = UIColor(red:0.16, green:0.17, blue:0.21, alpha:1)
activityIndicator.layer.cornerRadius = 6
activityIndicator.center = targetVC.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
//UIApplication.shared.beginIgnoringInteractionEvents()
}
}
Run Code Online (Sandbox Code Playgroud)
启动活动指示器的示例,如果我想停止它,则animate参数将为false。
Utils.activityIndicatorFunction(view: view, targetVC: self, animate: true)
Run Code Online (Sandbox Code Playgroud) 我arc4random
用来生成10个随机数,这样我就可以查询firebase来获取包含随机生成数字的问题.问题是我不希望任何数字出现多次,因此没有重复的问题.目前的代码如下......
import UIKit
import Firebase
class QuestionViewController: UIViewController {
var amountOfQuestions: UInt32 = 40
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Use a for loop to get 10 questions
for _ in 1...10{
// generate a random number between 1 and the amount of questions you have
let randomNumber = Int(arc4random_uniform(amountOfQuestions - 1)) + 1
print(randomNumber)
// The reference to your questions in firebase (this is an example from firebase …
Run Code Online (Sandbox Code Playgroud) swift ×6
arc4random ×4
firebase ×4
ios ×4
arrays ×1
avkit ×1
avplayer ×1
back4app ×1
int ×1
json ×1
objective-c ×1
parse-server ×1
random ×1
snapshot ×1
uint32 ×1