小编Dav*_*vid的帖子

NSKeyedUnarchiver decodeObjectForKey:]:无法解码类的对象

我有一个具有多个目标的应用程序(每个目标是另一个客户端作为具有不同名称,捆绑标识符等的单独应用程序).

我有方法:

fileprivate static func loadSessionFromKeychain() -> UserSession? {
    if let sessionData = KeychainWrapper.standard.data(forKey: UserSession.sessionDefaultsKey) {

        print("sessionData:")
        print(sessionData.debugDescription)
            if let session = NSKeyedUnarchiver.unarchiveObject(with: sessionData) as? UserSession {
                _current = session
                return session
            } else {
                print("ERROR: Could not parse UserSession from Keychain")
            }
        return nil
    }
    return nil
}
Run Code Online (Sandbox Code Playgroud)

该行if let session = NSKeyedUnarchiver.unarchiveObject(with: sessionData) as? UserSession {抛出错误:

*由于未捕获的异常'NSInvalidUnarchiveOperationException'终止应用程序,原因:'* - [NSKeyedUnarchiver decodeObjectForKey:]:无法解码类(_test__MyApp.UserSession)对象的密钥(root); 该类可以在源代码中定义,也可以在未链接的库中定义

我试图抓住,do {} catch {}但它没有抓住并抛出相同的错误+ xCode说

catch'block无法访问,因为'do'block`中没有抛出错误

任何想法如何解决这一问题?

UserSessionSwift.swift

    import UIKit
    import SwiftKeychainWrapper

    class …
Run Code Online (Sandbox Code Playgroud)

xcode throw ios swift

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

InApp购买 - paymentQueue:不会从特定位置调用updatedTransactions

我有两个地方,当我发起相同的UIView有可能购买InApp可购买的产品.1.用户入职结束2.菜单中的标准位置

从第一个开始付款我通过SKPaymentTransactionStatePurchasing到达updatedTransactions:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray     *)transactions
{
  DLog(@"updatedTransactions");
  for (SKPaymentTransaction *transaction in transactions)
  {
    switch (transaction.transactionState)
    {
        case SKPaymentTransactionStatePurchased:
            // I get here when the controller is initiated from menu, not from my user onboarding
            break;
        case SKPaymentTransactionStateFailed:
            [self failedTransaction:transaction];
            break;
        case SKPaymentTransactionStateRestored:
            [self restoreTransaction:transaction];
            break;
        case SKPaymentTransactionStatePurchasing:
            // I get here
            break;
        default:
            break;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,当用户完成事务时,永远不会调用此方法.

当我从菜单启动相同的控制器时,一切正常.

有任何想法吗?

谢谢

objective-c in-app-purchase ios

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

码头工人:gitlab + traefik&端口22

我需要在Traefik之后建立Gitlb。

除了通过命令行对应用程序进行身份验证以外,其他所有操作都有效-我不知道如何通过traefik公开端口22。

知道如何设置吗?如何通过traefik暴露docker容器的端口22?

我将默认端口从22更改为10022。

我正在通过 netstat -tulpn

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1132/sshd           
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN      1126/systemd-resolv 
tcp6       0      0 :::22                   :::*                    LISTEN      1132/sshd           
tcp6       0      0 :::443                  :::*                    LISTEN      1590/docker-proxy   
tcp6       0      0 :::10022                :::*                    LISTEN      1440/docker-proxy   
tcp6       0      0 :::5355                 :::*                    LISTEN      1126/systemd-resolv 
tcp6       0      0 :::80                   :::*                    LISTEN      1602/docker-proxy   
tcp6       0      0 :::8080                 :::*                    LISTEN      1578/docker-proxy   
udp        0 …
Run Code Online (Sandbox Code Playgroud)

gitlab docker traefik

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

model.create 上未调用 before_create

我有这个代码:

class Project < ActiveRecord::Base
    acts_as_paranoid

    belongs_to :user
    belongs_to :organization
    accepts_nested_attributes_for :organization


    attr_accessible :name, :permalink, :organization_id, :user_id

    validates_length_of :name, :minimum => 4
    validates_presence_of   :permalink
    validates_uniqueness_of :permalink, :case_sensitive => false, :scope => :deleted_at

     
    validates_presence_of :user        
    validates_presence_of :organization

    before_create :generate_permalink

    protected

    def generate_permalink
      binding.pry
      self.permalink = "123456789"
    end    
    
end
Run Code Online (Sandbox Code Playgroud)

当我调用 ProjectsController#create 时

p = Project.new
p.name = "abcdef"
p.save
Run Code Online (Sandbox Code Playgroud)

应用程序不会停止在generate_permalink中的binding.pry上,并且该项目无效且未保存,因为permalink == nil. 为什么没有调用generate_permalink方法?

ruby-on-rails ruby-on-rails-3

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

Swift 在 Storyboard 中设置 UIButton setBorderColor

我正在尝试在 Storyboard 上设置 UIButton 边框颜色:

设置按钮颜色

但是按钮仍然是黑色的。当我尝试使用 layer.borderColor 时,它根本不显示边框。

怎么选颜色?

谢谢

// 更新

我已将基于 @dfd 的设置方式更改为:

import Foundation
import UIKit

@IBDesignable

public class OnboardingButton: UIButton {
    @IBInspectable public var borderColor:UIColor? {
        didSet {
            layer.borderColor = borderColor?.cgColor
        }
   }
   @IBInspectable public var borderWidth:CGFloat = 0 {
        didSet {
            layer.borderWidth = borderWidth
        }
   }
   @IBInspectable public var cornerRadius:CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0
        }
   }
}
Run Code Online (Sandbox Code Playgroud)

在 Storyboard 自定义类中设置到*OnboardingButton应用程序后开始构建但失败。日志中没有错误。我在哪里可以找到错误以及如何修复它?

xcode storyboard swift

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

迅捷3-WKWebView中的HTTP身份验证

我正在尝试构建一个显示网页的简单WebView-该页面要求所有页面都使用http身份验证(出于测试目的)。

这是我的代码:

class ViewController: UIViewController, WKUIDelegate {

    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }

    // #1 variant
    func webView(webView: WKWebView, willSendRequestForAuthenticationChallenge challenge:
        URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        let user = "user"
        let password = "pass"
        let credential = URLCredential(user: user, password: password, persistence: URLCredential.Persistence.forSession)
        challenge.sender?.use(credential, for: challenge)
    }

    // #2 variant
    func webView(webView: WKWebView, didReceiveAuthenticationChallenge challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> …
Run Code Online (Sandbox Code Playgroud)

http-authentication swift wkwebview swift3

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

文本在图像上的绝对位置

我有一个图像,我需要在右下角添加一个标签.

当我把它推到那里时,它比图像低4px,没有填充也没有边距.

.postImage {
    position: relative;
    display: inline-block;
}
.post img.thumbnail {
    width:100%;
    height: 100%;
}
.commercial {
    position: absolute;
    bottom: 0;
    right: 0;
    background-color: #666;
    color: #fff;
    padding: 3px;
    font-size: 14px;
    font-weight: 100;
}
Run Code Online (Sandbox Code Playgroud)
<div class="postImage">
  <img class="thumbnail" src="https://dummyimage.com/600x400/f00/fff">
  <span class="commercial">commercial</span>
</div>
Run Code Online (Sandbox Code Playgroud)

修复它的最佳方法是什么?我不认为

bottom: 4px;
Run Code Online (Sandbox Code Playgroud)

是正确的.

谢谢

html css css-position

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