小编Mic*_*owe的帖子

将Objective-C指针类型'NSString*'转换为C指针类型'CFStringRef'(又名'const struct __CFString*')需要桥接转换

将Objective-C程序转换为Objective-C ARC时,我收到错误:

"cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast "
Run Code Online (Sandbox Code Playgroud)

代码如下:

- (NSString *)_encodeString:(NSString *)string
{
    NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, 
                                   (CFStringRef)string, // this is line in error
                                   NULL, 
                                   (CFStringRef)@";/?:@&=$+{}<>,",
                                   kCFStringEncodingUTF8);
    return [result autorelease];
}
Run Code Online (Sandbox Code Playgroud)

什么是桥接演员?

错误的屏幕截图

casting objective-c automatic-ref-counting

40
推荐指数
3
解决办法
4万
查看次数

WatchOS2的调试建议

我一直在阅读RayWenderlich团队的WatchOS 2 By Tutorial一书中的例子,特别是第18章.它们都运行良好.在我自己的应用程序中,我试图从手表发送按钮按下iPhone应用程序上的按钮.以下是手表和手机中Swift的相关代码:

看:

//
//  InterfaceController.swift
//  Wasted Time Extension
//
//  Created by Michael Rowe on 7/21/15.
//  Copyright © 2010-2015 Michael Rowe. All rights reserved.
//

import WatchKit
import WatchConnectivity
import Foundation


class InterfaceController: WKInterfaceController,WCSessionDelegate {

    @IBOutlet var wasteLabel: WKInterfaceLabel!
    @IBOutlet var costLabel: WKInterfaceLabel!
    @IBOutlet var counter: WKInterfaceLabel!
    @IBOutlet var statusButton: WKInterfaceButton!

    // our watchconnective session
    var session : WCSession?


    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
    }

    override func willActivate() {
        // This method …
Run Code Online (Sandbox Code Playgroud)

swift watchkit watchos-2

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

'Bool' 在 SwiftUI 中不能转换为 'Binding&lt;Bool&gt;'

我有一个我正在开发的SwiftUI原生 Watch 应用程序。我有一个Combine基础类,它允许我存储 `\userDefaults,其中之一是一个简单的切换。

import SwiftUI  
import Foundation  
import Combine  


class MeetingSetup: BindableObject {  

    let willChange = PassthroughSubject<Void, Never>()  

    var twitterEnabled: Bool = false {  
        didSet {  
            willChange.send()  
        }  
    }  

    init() {  
        let prefs:UserDefaults = UserDefaults(suiteName: "group.com.appname")!  
        twitterEnabled = prefs.bool(forKey: "keyTwitterEnabledBool")  
    }  
} 
Run Code Online (Sandbox Code Playgroud)

SwiftUI我收到Bool无法转换为的错误消息Binding<Bool>

import SwiftUI  
import Combine  

struct SetupView : View {  

    @ObjectBinding var meetingSetup: MeetingSetup = delegate.meetingSetup  

    var body: some View {  

                HStack{  
                    Toggle(isOn: self.meetingSetup.twitterEnabled){  // <== 'Bool' in …
Run Code Online (Sandbox Code Playgroud)

swiftui combine

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

将应用程序升级到Swift 4和iOS 11 - TwitterKit问题

我正在尝试将我的应用升级到最新的iOS支持.我通过CocoaPods添加了TwitterKit,并将标题放在我的Bridge Header中.然而; 我收到一个错误说:

使用未解决的'推特' - 你的意思是'TWTRTTwitter'.

func application(_ application: UIApplication, didFinishLaunchingWithOptions lauunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Twitter.sharedInstance().start(withConsumerKey:"MYKEY", consumerSecret:"MYSECRET")
    return true
}
Run Code Online (Sandbox Code Playgroud)

这是推特推荐的代码.我也得到了:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    let handled:Bool = true

    Twitter.sharedInstance().application(app, open: url, options: options)

    return handled
}
Run Code Online (Sandbox Code Playgroud)

有什么指针吗?

twitterkit swift4 ios11.2

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

“发生未知错误”尝试启动我的 Siri 快捷方式时

我正在将 siri Shortcuts 添加到我现有的应用程序中。共有三种快捷方式,一种是使用特定值启动应用程序,一种是将值增加一个数量,另一个是将值减少一个数量。用于启动应用程序的快捷代码附在此处:

//
//  StartMeetingIntentHandler.swift
//


import Intents
import SwiftUI

class StartMeetingIntentHandler: NSObject, StartMeetingIntentHandling {


    @ObservedObject var meeting = Meeting()

    func handle(intent: StartMeetingIntent, completion: @escaping (StartMeetingIntentResponse) -> Void) {
        if let attendees = intent.attendees {
            meeting.meetingStarted()
            meeting.addAttendee(numberToAdd: Int(truncating: attendees))
            completion(StartMeetingIntentResponse.success(result: attendees))
        } else {
            print("failure")
        }
    }

    func resolveAttendees(for intent: StartMeetingIntent, with completion: @escaping (StartMeetingAttendeesResolutionResult) -> Void) {
        let people = Int(truncating: intent.attendees ?? 0)
        if people < 0 {
            completion(StartMeetingAttendeesResolutionResult.unsupported(forReason: StartMeetingAttendeesUnsupportedReason.negativeNumbersNotSupported))
        } else if people > 1000 …
Run Code Online (Sandbox Code Playgroud)

sirishortcuts

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

无法将 SwiftUI.ExtensionDelegate 转换为 ExtensionDelegate

使用 SwiftUI 架构 WatchOS 应用程序,如果您想使用 ExtensionDelegate,您需要创建自己的。我已经这样做了,但是当我尝试实际访问代码中的委托时,我收到以下错误消息无法转换类型的值SwiftUI.ExtensionDelegate' (0x7fff8441b480) to 'TestMe_WatchKit_Extension.ExtensionDelegate' (0x10c3b36d0).
我已将 ExtensionDelegate 定义为 -

class ExtensionDelegate: NSObject, WKExtensionDelegate {
    var meetingStatistics:  MeetingStatistics = MeetingStatistics()
    override init(){
        super.init()
    }
    func applicationDidFinishLaunching() {
        // Perform any final initialization of your application.
        print("applicationDidFinishLaunching for watchOS")
    }
    func applicationDidBecomeActive() {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }
    func applicationWillResignActive() { …
Run Code Online (Sandbox Code Playgroud)

watchos swiftui

3
推荐指数
2
解决办法
626
查看次数

UIActionSheet在iPad /非iPhone上崩溃

当我查看控制台时,我收到此消息

2010-09-18 17:04:05.284 Wasted Time[8998:207] *** Assertion failure in -[UIActionSheet showInView:], /SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073
2010-09-18 17:04:05.286 Wasted Time[8998:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil'
2010-09-18 17:04:05.286 Wasted Time[8998:207] Stack: (
    42272848,
    43430700,
    42010379,
    811796,
    3796273,
    3862560,
    9631,
    3616645,
    3688229,
    3682846,
    3690662,
    3686119,
    4983946,
    71264534,
    71263781,
    71207378,
    71206706,
    3003734,
    3030334,
    3011831,
    3043800,
    51265916,
    41552028,
    41547944,
    3002913,
    3036018,
    8314
)
terminate called after throwing an instance of 'NSException'

代码如下:

- (void)viewDidLoad {
    BOOL    continueYesNo; …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch uiactionsheet ipad ios

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