小编Gru*_*kes的帖子

关于swift中NSError的问题

如何在Swift中为NSError分配错误代码?以下给出了一个编译错误,说"无法在'e'中分配'代码'":

        var e = NSError()
        e.code = 6;
Run Code Online (Sandbox Code Playgroud)

另外,为什么以下代码生成'Int不能转换为选择器'的错误

        if e.code == EKAuthorizationStatus.Restricted
        {
        }
Run Code Online (Sandbox Code Playgroud)

swift

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

连接到GoogleApiClient后未调用GoogleApiClient.ConnectionCallbacks方法

我有一些代码连接到GoogleApiClient但是没有调用onConnected.

public class MainActivity extends Activity implements  GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
    private GoogleApiClient mApiClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initGoogleApiClient();
    }

    private void initGoogleApiClient() {
        mApiClient = new GoogleApiClient.Builder( this )
                .addApi( Wearable.API )
                .build();
        mApiClient.connect(); // On completion onConnected() will be called
    }
    @Override
    public void onConnected(Bundle bundle) {
    }

    @Override
    public void onConnectionSuspended(int i) {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mApiClient.disconnect();
    }

    @Override
    public void onConnectionFailed(com.google.android.gms.common.ConnectionResult connectionResult) {
    }
Run Code Online (Sandbox Code Playgroud)

四个@Override方法都没有被调用,为什么会这样?

android google-api-client

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

是否可以使用@IBDesignable在故事板中显示UILabel.attributedText?

我的应用程序中的所有标签都使用了设置了间距/字距值的字体以及颜色和其他一些东西,我希望看到故事板中应用了所有这些属性的内容.

由于UILabel是UIView,我希望通过使用@IBDesignable可以实现这一点.但经过一些实验,我无法在故事板中发生任何事情.

这是代码:

@IBDesignable class CustomLabel: UILabel {
    @IBDesignable override var text: String? {
        didSet {
            guard let text = text else { return }
            let titleAttributes = [NSForegroundColorAttributeName: UIColor.green]
            let titleString = NSMutableAttributedString(string: text, attributes: titleAttributes)
            titleString.addAttribute(NSKernAttributeName, value: 5, range: NSRange(location: 0, length: text.characters.count))
            // Other attributes
            self.attributedText = titleString
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

...

@IBOutlet weak var theTitle: CustomLabel!
theTitle.text = "Some stuff"
Run Code Online (Sandbox Code Playgroud)

但在故事板中,标签显示时未应用任何属性字符串设置.

有人知道我正在尝试的是否可能,如果是的话,如何让它工作?

xcode storyboard ios swift

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

pushRegistry:didUpdate:pushCredentials未被调用

查看过去关于此的问题,但这些问题的答案已经应用于我的项目,但是没有调用pushRegistry()委托方法.

首先是这里的代码:

import UIKit
import PushKit
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate{

    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        let notificationSettings  = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil)
        application.registerUserNotificationSettings(notificationSettings)

        UNUserNotificationCenter.current().delegate = self
        UIApplication.shared.registerForRemoteNotifications()

        let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
        voipRegistry.desiredPushTypes = Set([PKPushType.voIP])
        voipRegistry.delegate = self;

        return true
    }
...
}

extension AppDelegate: PKPushRegistryDelegate {
    func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        NSLog("voip token: \(pushCredentials.token)")
    }
Run Code Online (Sandbox Code Playgroud)

已启用以下应用程序功能: - 推送通知 …

voip ios pushkit

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

如何在Framework目标中调用Objective-C的Swift代码?

当您将Swift文件添加到Objective-C项目时,Xcode将生成一个Swift-to-ObjC标头,如下所述:http://ericasadun.com/2014/08/21/swift-calling-swift-functions- 从目标-C /

如果没有此标头,则无法从Objc-C调用Swift代码.但是,Xcode不会为我的框架目标自动生成此标头.

如果我创建一个Objective-C 应用程序并将Swift文件放入其中,那么它会自动生成一个,所以我怀疑这是因为我正在构建一个框架而不是一个应用程序.没有一个它不可能使用Obj-C代码中的Swift代码.

我尝试使用为应用程序生成的那个(在重命名并将其放入相应的DerivedData文件夹之后)但Xcode没有更新它,实际上它最终会删除它,因此手动创建或尝试维护此文件不是可行.

如何让Xcode为框架目标生成此标头,以便我可以从我的Obj-C代码调用我的Swift代码?

记得大家:问题是从Obj-C调用Swift而不是从Swift调用Obj-C.

xcode objective-c swift

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

有人能告诉我这是用什么代码编写的

我有一条消息告诉我:

TFO COBRBK RKP AXOXRC PFB FK BFKBJ MBOPLBKIFZEBK DBPMOXBZE HBKKBK WR IBOKBK.YFQQB JBIABK PFB PFZE CRBO BFKB QBOJFKXYPMOXZEB QBIBCLKFPZE YBF RKP

我被告知这是一个旧代码.如果有人能告诉我它写的是哪个代码,我会非常感激.

最好的祝福.纽约大学〜

codeigniter

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