相关疑难解决方法(0)

如何在Playground中运行异步回调

许多Cocoa和CocoaTouch方法都有完成回调,实现为Objective-C中的块和Swift中的闭包.但是,在Playground中尝试这些时,永远不会调用完成.例如:

// Playground - noun: a place where people can play

import Cocoa
import XCPlayground

let url = NSURL(string: "http://stackoverflow.com")
let request = NSURLRequest(URL: url)

NSURLConnection.sendAsynchronousRequest(request, queue:NSOperationQueue.currentQueue() {
response, maybeData, error in

    // This block never gets called?
    if let data = maybeData {
        let contents = NSString(data:data, encoding:NSUTF8StringEncoding)
        println(contents)
    } else {
        println(error.localizedDescription)
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以在我的Playground时间轴中看到控制台输出,但是println我的完成块永远不会被调用...

closures asynchronous callback swift swift-playground

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

更新到1.0.0后cocoapods link_with出错

我今天更新了cocoapods到1.0.0版本.我更新pod时得到了这个字符串:

[!] Invalid Podfile file: [!] The specification of link_with in the Podfile is now unsupported, please use target blocks instead..

我已经删除了podFile中的link_with,但我无法构建项目,因为我有很多Match-O-Linkers.任何人都知道我应该如何解决这个问题?

这是我的Podfile现在:

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
inhibit_all_warnings!


pod 'pop', '~> 1.0'
    pod 'AFNetworking', '~> 1.3'
    pod 'SDWebImage', '~> 3.7'
    pod 'GoogleAnalytics', '~> 3'
    pod 'ARAnalytics' , :subspecs => ["Crashlytics", "Amplitude", "DSL"]
    pod 'FBSDKCoreKit', '~> 4.10.1'
    pod 'FBSDKLoginKit', '~> 4.10.1'
    pod 'FBSDKShareKit', '~> 4.10.1'
    pod 'Google/SignIn'
    pod 'Branch'

    pod 'Leanplum-iOS-SDK'

    pod 'Fabric', '1.6.7'
    pod 'Crashlytics', '3.7.0'
    pod 'TwitterKit'
    pod …
Run Code Online (Sandbox Code Playgroud)

xcode ios cocoapods

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

更改变量中的一个属性会触发其他属性的子目录.RxSwift

我有以下属性结构 Chat

struct Chat {
    var id = String()
    var gender = String()
    var date = Date()

    init() {}
}
Run Code Online (Sandbox Code Playgroud)

在视图控制器中,我声明了一个名为Chat的实例observablechat,然后我使用flatmap运算符来尝试并观察date属性的变化observablechat.但是,如果我更改性别属性(如图所示),则会触发订阅.我想知道为什么会这样,我如何修复此代码,以便订阅只查看date属性发生了什么,没有别的?

class ViewController: UIViewController {

    var observablechat = Variable(Chat())

        observablechat.asObservable()
        .flatMap { (Chat) -> Observable<Date> in
            return Observable.of(Chat.matchDate)
        }.subscribe(onNext: { (r) in
            print(r)
        }).addDisposableTo(disposeBag)


        self.observablechat.value.gender = "male" 
        //triggers subscription above. 
    }
}
Run Code Online (Sandbox Code Playgroud)

system.reactive ios rxjs swift rx-swift

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

将游乐场添加到现有工作区(使用cocoapods)

问题:

如果我已在此工作区中拥有应用项目和pod项目,如何向工作区添加游乐场?

它应该看起来像这样:

IM1

现在它无法从cocoapods项目中找到依赖项: IM2

我尝试了什么:
https ://github.com/segiddins/ThisCouldBeUsButYouPlaying
如何将CocoaPod框架添加到Xcode 8 Playground
如何在操场上使用cocoapods?
https://github.com/WhisperSystems/Signal-iOS/pull/1180

没工作.

xcode ios cocoapods swift-playground

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