小编Aml*_*xer的帖子

在后台线程上执行的Realm写仍然阻止主UI

在我的应用程序中,我需要定期对Realm执行大量写入,在100到10,000个对象之间.显然这是一个大写,所以我试图在后台执行这个写操作,以便用户可以执行其他操作,甚至没有注意到写.不幸的是,尽管我认为我的写作是在后台线程上执行的,但主UI仍然被阻止.这是我调用以执行对域的写入的方法的jist.从我循环遍历的数组中的单个对象上重复调用此方法.看起来我做了一些明显的错误吗?任何帮助将不胜感激.

func writeCustomerToRealm(inputCustomer:Customer) {
  let qualityOfServiceClass = QOS_CLASS_BACKGROUND
  let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
  dispatch_async(backgroundQueue, {
    let realm = try! Realm()
    realm.beginWrite()
    realm.add(self.swapCustomerForRealmCustomer(inputCustomer))
    try! realm.commitWrite()
 })
}
Run Code Online (Sandbox Code Playgroud)

multithreading realm grand-central-dispatch ios swift

8
推荐指数
1
解决办法
2537
查看次数

无法从UIView扩展中调用方法

我试图通过扩展我的一个自定义UIViews来调用方法,但我得到错误"类型'MyCustomView'的值没有成员'testMethod'".以下是我的代码

extension MyCustomView {
  func testMethod() {
    //do stuff here
  }
}

//in a separate class from the extension 
class func onMoreOptionsButtonPressed(currentViewController:UIViewController) {
  for view in currentViewController.view.subviews {
    if view.isKindOfClass(MyCustomView) {
      let myCustomView = view as! MyCustomView
      myCustomView.testMethod()
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

显然我可以通过一些不同的方式实现这个功能,但是我更感兴趣的是为什么这个代码不能编译,因为它在逻辑上对我来说是正确的.非常感谢所有帮助.

uiview ios swift swift-extensions

6
推荐指数
1
解决办法
646
查看次数

引用在ActionListener中单击了JButton

我正在尝试使用swing编写Tic Tac Toe程序,但我似乎遇到了一些麻烦.在我的匿名内部类中,我尝试为每个按钮设置actionListener,但是我无法找到允许我引用按钮并将它们设置为X或Y的类型或变量.我试过了.getSource().setText()在我的匿名类中,但是返回时出现了错误.有什么想法吗?谢谢!亚历克斯

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TicTacToe  {

public JFrame frame;
public JLabel label;
public JPanel panel;

public static int counter;



public void go()
{ 
    frame = new JFrame("TicTacToe");
    frame.setSize(500, 500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    panel = new JPanel();
    panel.setLayout(new GridLayout(3,3,10,10));
    frame.add(BorderLayout.CENTER, panel);
    label= new JLabel("TIC TAC TOE");
    frame.add(BorderLayout.NORTH, label);

    ; 


    JButton button1 = new JButton("Button 1");
    JButton button2 = new JButton("Button 1");
    JButton button3 = new JButton("Button 1");
    JButton button4 = new JButton("Button 1");
    JButton …
Run Code Online (Sandbox Code Playgroud)

java swing jbutton actionlistener tic-tac-toe

4
推荐指数
1
解决办法
2万
查看次数

无法在iOS上与Chrome进行深度链接

我目前正在尝试为我正在开发的iOS应用程序构建自定义的深层链接方案。URL的格式如下所示

[scheme]://[host]/[path]
Run Code Online (Sandbox Code Playgroud)

我已经在我的应用程序中注册了URL方案,并且在Safari中一切正常。但是,在使用Chrome时,我根本无法获得深层链接。它始终只会在手机上开始Google搜索,而永远不会打开该应用程序。我知道我必须在Chrome上使用Intent标志,但是我尝试的所有操作似乎都失败了。您可以深入链接到iOS上的Chrome上的自定义方案吗?如果是这样,您如何格式化URL?

google-chrome url-routing deep-linking ios

2
推荐指数
1
解决办法
4514
查看次数