小编Rut*_*ans的帖子

离开 DispatchGroup 会导致我的代码崩溃

我有以下函数,但它在 dispatchGroup.leave() 语句上不断崩溃,我不明白为什么。根据我在网上找到的内容,每个 dispatchGroup.leave() 都必须与一个 dispatchGroup.enter() 相关联,我认为我的函数就是这种情况。

self.kycRecords 只包含 1 个元素(目前)顺便说一句。

 @IBAction func checkCustomerList(_ sender: Any) {
        let dispatchGroup = DispatchGroup()

        for kycRecord in self.kycRecords {
            dispatchGroup.enter()
            ApiManager.sharedInstance.postUserToArtemis(kycRecord) {(response, error) in
                dispatchGroup.leave()
                if error != nil {
                    kycRecord.kycStatus = "failed"
                } else {
                    if response == true {
                        kycRecord.kycStatus = "passed"
                    } else {
                        kycRecord.kycStatus = "failed"
                    }
                }
            }
        }

        dispatchGroup.notify(queue: DispatchQueue.main, execute: {
            print("done")
            self.writeOutput()
        })
    }
Run Code Online (Sandbox Code Playgroud)

它崩溃并显示以下消息:

线程 1:EXC_BAD_INSTRUCTION(代码=EXC_I386_INVOP,子代码=0x0)

在此处输入图片说明

arrays grand-central-dispatch swift

10
推荐指数
1
解决办法
3015
查看次数

相当于 Flutter 中的 viewWillAppear()

我正在使用 Flutter 重建一个 iOS 应用程序,流程如下:每次用户登陆主页时,用户数据都会从后端重新加载以检查是否有任何更改。

我在 Swift / iOS 中实现这一点的方法是使用 viewDidLoad() 函数。

我的 Flutter 代码是这样的:

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  User user = User();

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    _fetchData(context);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        color: RColor.COLOR_main,
        child: Column(
          children: [
            Container(
              height: MediaQuery.of(context).size.height / 7,
              width: MediaQuery.of(context).size.width,
              padding: EdgeInsets.all(20),
              child: Container(
                child: Text("This is the homepage"),
                alignment: Alignment.bottomCenter,
              ), …
Run Code Online (Sandbox Code Playgroud)

ios dart flutter

7
推荐指数
1
解决办法
4723
查看次数

如何使用路由处理 Flutter 中的深度链接

我正在尝试构建深度链接功能,到目前为止,应用程序的初始启动和从深度链接检索参数进展顺利。

但是,在深度链接到应用程序后,我在导航到屏幕时遇到问题。我该怎么做?

我的代码如下所示:

void main() { 
    runApp(MyApp()); 
}

class MyApp extends StatefulWidget {   
    @override   
    _MyAppState createState() => _MyAppState(); 
}

class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {   
   Uri _latestUri;  
   Object _err;

  StreamSubscription _sub;

  @override   void initState() {
    super.initState();
    _handleIncomingLinks();
  }

  @override void dispose() {
    _sub?.cancel();
    super.dispose();   
  }

  void _handleIncomingLinks() {
    _sub = uriLinkStream.listen((Uri uri) {
      if (!mounted) return;
      print('got uri: $uri'); // printed: got uri: myapp://?key1=test
      setState(() {
        _latestUri = uri;
        _err = null;

        Navigator.pushNamed(context, 'login'); // This doesn't work because …
Run Code Online (Sandbox Code Playgroud)

deep-linking navigator flutter

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

一直向下滚动到UITableView的底部

我有一个UITableView,我正在尝试加载36行,然后一直向下滚动到最后一个单元格.

我试过这个:

func reloadData(){
    chatroomTableView.reloadData()
    chatroomTableView.scrollToBottom(true)
}


extension UITableView {
    func scrollToBottom(animated: Bool = true) {
        let sections = self.numberOfSections
        let rows = self.numberOfRowsInSection(sections - 1)
        if (rows > 0){
            self.scrollToRowAtIndexPath(NSIndexPath(forRow: rows - 1, inSection: sections - 1), atScrollPosition: .Bottom, animated: true)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但它只会向下滚动一半.

uitableview ios swift

5
推荐指数
1
解决办法
8613
查看次数

APNs 身份验证密钥是否会过期?

我已在我们的系统上设置 Firebase Cloud Messaging 以设置推送通知。在我们的 APNs 证书过期之前,我们因此遇到了一些问题。

然后我能够生成一个 APNs 身份验证密钥,并且我认为该密钥不会过期。有人能告诉我这个假设是否正确吗?

在此输入图像描述

apple-push-notifications ios firebase swift firebase-cloud-messaging

5
推荐指数
1
解决办法
4056
查看次数

计算2个NSDates之间的工作日和周末天数

我正在尝试计算2个NSDates之间的工作日+工作日数,但我似乎找不到合适的解决方案.我现在可以找到两个NSDates之间的天数,如下所示:

func reloadData(){
    let cal = NSCalendar.currentCalendar()

    var daysInt = 0

    let days = cal.components(.Day, fromDate: selectedDateTimePointTwo, toDate: selectedDateTimePointOne, options: [])
    daysInt = days.day

    workDaysLabel.text = "work days: \(daysInt)"
    weekendDaysLabel.text = "weekend days: "
}
Run Code Online (Sandbox Code Playgroud)

谁能指出我正确的方向?

calendar date nsdate nscalendar swift

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

如何在 Swift 项目中使用 Objective-C 桥接头

我被要求在我的 Swift 项目中使用 Objective-C 框架。

但我不知道如何实现这一点。

我添加了这个文件:

Objective-CBridgingHeader.h
Run Code Online (Sandbox Code Playgroud)

我在这个文件中放入了:

#ifndef Objective_CBridgingHeader_h
#define Objective_CBridgingHeader_h

#import <FMShop/FMShop.h>

#endif /* Objective_CBridgingHeader_h */
Run Code Online (Sandbox Code Playgroud)

现在我期望能够:

Import FMShop
Run Code Online (Sandbox Code Playgroud)

并使用 Swift 代码访问该框架。然而当我尝试

Import FMShop
Run Code Online (Sandbox Code Playgroud)

我的项目不再编译并声称存在:“没有这样的模块‘FMShop’”

我在这里缺少什么?

我的基础 SDK 是 iOS 8.0,我使用的是 Xcode 7.3.1

这就是我的项目的样子:

在此输入图像描述

xcode objective-c ios swift

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

在 Flutter / Dart 中解析列表

我有一个如下所示的列表:

[{id: 1, user_id: 3, challenge_id: 1, created_at: 2019-06-09 06:36:39, image_caption: Enter your image caption here, image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560062199/zex61jegvqwkevq6qrmd.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}, {id: 2, user_id: 2, challenge_id: 1, created_at: 2019-06-12 09:17:07, image_caption: , image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560331027/dj94sjzufx8gznyxrves.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}, 
{id: 2, user_id: 3, challenge_id: 1, created_at: 2019-06-09 06:36:39, image_caption: Enter your image caption here, image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560062199/zex61jegvqwkevq6qrmd.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}, {id: 2, user_id: 2, challenge_id: 1, created_at: 2019-06-12 …
Run Code Online (Sandbox Code Playgroud)

json dart flutter

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

使用Alamofire和multipart/form-data

我无法以正确的方式接近我提供的API,以便为我提供我正在寻找的响应.我一直在使用Swift和Alamofire,但这是我第一次使用multipart/form-data上传图像.我可以使用Postman上传图像,但我无法通过我的应用程序使用Alamofire框架发送相同的消息.

我的邮差截图

我的Swift代码:

func postFulfilWish(wish_id: Int, picture : UIImage, completionHandler: ((AnyObject?, ErrorType?) -> Void)) {

    var urlPostFulfilWish = Constant.apiUrl;
    urlPostFulfilWish += "/wishes/";
    urlPostFulfilWish += String(wish_id);
    urlPostFulfilWish += "/fulfill/images"  ;

    let image : NSData = UIImagePNGRepresentation(UIImage(named: "location.png")!)!

    Alamofire.upload(.POST, urlPostFulfilWish, headers: Constant.headers, multipartFormData: { multipartFormData in
        multipartFormData.appendBodyPart(data: image, name: "file")
        },
        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .Success(let upload, _, _):
                upload.responseJSON { response in
                    //This is where the code ends up now
                    //So it's able to encode my message into …
Run Code Online (Sandbox Code Playgroud)

iphone multipartform-data ios swift alamofire

3
推荐指数
1
解决办法
3598
查看次数

如何使用Stripe和Swift获得卡牌

    STPAPIClient.shared().createToken(withCard: cardParams) { (token, error) in
        if error != nil {
            //fail
        } else if let token = token {
            print(token.card?.brand) //Optional(__C.STPCardBrand)
            print(token.card?.brand.hashValue) //Optional(0)
            print(token.card?.brand.rawValue) //Optional(0)
        }
    }
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么Stripe没有退回卡牌?我正在使用条纹测试卡,其余信息将被退回.

ios stripe-payments swift

3
推荐指数
1
解决办法
1542
查看次数

试图在Mac上安装Scrapy

当我尝试使用终端在OS X上安装Scrapy时出现错误.

我使用的命令:

sudo pip install -U scrapy
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 736, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 742, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 299, in move
    copytree(src, real_dst, symlinks=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 208, in copytree
    raise Error, errors …
Run Code Online (Sandbox Code Playgroud)

python pip scrapy

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

Swift中的UIButton动画

我正试图在按下按钮时在按钮上制作动画.案例如下.按钮将有一个苹果的图片.按下时,它将变为image1,image2,image3(如.gif),然后它将是梨的图片.现在我只是看到它从一个苹果变成一个梨,并跳过我正在尝试创建的动画.

这是动画部分的代码:

    var image1:UIImage = UIImage(named: buttonAnimationImage1)!;
    var image2:UIImage = UIImage(named: buttonAnimationImage2)!;
    var image3:UIImage = UIImage(named: buttonAnimationImage3)!;

    sender.imageView!.animationImages = [image1, image2, image3];
    sender.imageView!.animationDuration = 1.5;
    sender.imageView!.startAnimating();
Run Code Online (Sandbox Code Playgroud)

animation ios swift

0
推荐指数
1
解决办法
1729
查看次数

UILabel没有像预期的那样出现延迟序列

我想让我的UILabel以延迟的顺序出现.因此一个接一个.当我使用alpha值使它们淡入时,下面的代码可以正常工作,但是当我使用UILabels的.hidden属性时它不会做我想要它做的事情.

代码使我的UILabel同时出现而不是sum1TimeLabel在5秒后出现,sum2TimeLabel在30秒后出现秒,最后sum3TimeLabel出现在60秒后出现.我究竟做错了什么?

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    UIView.animateWithDuration(5.0, animations:  {
        self.sum1TimeLabel!.hidden = false;
    })

    UIView.animateWithDuration(30.0, animations: {
        self.sum2TimeLabel!.hidden = false;
    })

    UIView.animateWithDuration(60.0, animations: {
        self.sum3TimeLabel!.hidden = false;
    })
}
Run Code Online (Sandbox Code Playgroud)

core-animation uiview ios swift

0
推荐指数
1
解决办法
71
查看次数