小编Leo*_*Leo的帖子

如何在Swift中调用deinit

我写了一个代码块如下:

class Person{
        let name:String;
        init(name:String){
         self.name = name;
          println("\(name) is being initialized.");
     }

     deinit{
         println("\(name) is being deInitialized.");

    }
 }

var person:Person?;
person = Person(name:"leo");
person = nil;
Run Code Online (Sandbox Code Playgroud)

初始化时,没问题print.设置人员时nil,deinit不调用该方法.

ios swift

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

DISPATCH_QUEUE_CONCURRENT和DISPATCH_QUEUE_SERIAL有什么区别

我实现了以下类:

class GCDStudy {

    func asyncSerial(time:Double){
        let queue = dispatch_queue_create("DISPATCH_QUEUE_SERIAL",DISPATCH_QUEUE_SERIAL)

        dispatch_async(queue){

            var i:Double = 0
            while(i < 3){
                i++
                print("asyncSerial -wait:\(time)-\(i)")

            }
        }

    }

    func asyncConcurrent(time:Double){

        let queue = dispatch_queue_create("DISPATCH_QUEUE_CONCURRENT",DISPATCH_QUEUE_CONCURRENT)

        dispatch_async(queue){
            var i:Double = 0
            while(i < 3){
                i++
                print("asyncConcurrent -wait:\(time)-\(i)")
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并运行如下:

运行A:

gCDStudy = GCDStudy()
gCDStudy.asyncSerial(1)
gCDStudy.asyncSerial(2)
Run Code Online (Sandbox Code Playgroud)

跑B

vgCDStudy2 = GCDStudy()
gCDStudy2.asyncConcurrent(1)
gCDStudy2.asyncConcurrent(2)
Run Code Online (Sandbox Code Playgroud)

结果RunA:

asyncSerial -wait:1.0-1.0
asyncSerial -wait:2.0-1.0
asyncSerial -wait:1.0-2.0
asyncSerial -wait:2.0-2.0
asyncSerial -wait:1.0-3.0
asyncSerial -wait:2.0-3.0
Run Code Online (Sandbox Code Playgroud)

RunB的结果:

asyncSerial -wait:1.0-1.0
asyncSerial -wait:2.0-1.0
asyncSerial -wait:1.0-2.0
asyncSerial -wait:2.0-2.0 …
Run Code Online (Sandbox Code Playgroud)

grand-central-dispatch ios swift

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

原型中自定义函数和本机函数之间的区别

“ For In”可以遍历数组(值/属性/函数)。

let arr = [1,2,3,4];
arr.__proto__.con = function(){console.log('from array');}
for(let item in arr){
 console.log(item);
}

Run Code Online (Sandbox Code Playgroud)

结果将是:

1,2,3,4,con
Run Code Online (Sandbox Code Playgroud)

为什么不打印“ toString” /“ split”之类的本机功能?有什么不同?

在我看来,它们(contoString)都属于Array的原型。

javascript

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

使用avplayer播放音频时如何将音频缓存到本地

我使用 AVPlayer 在线播放音频,并希望在 avplayer 完成加载流时将音频数据/流保存到本地。

我按如下方式实现它:

    let fileUrl =  NSURL(string: strUrl)!
    let asset = AVURLAsset(URL: fileUrl)
    asset.resourceLoader.setDelegate(self, queue:dispatch_queue_create("AVARLDelegateDemo loader", nil))
    self.pendingRequests = [AVAssetResourceLoadingRequest]()

    asset.loadValuesAsynchronouslyForKeys(["playable"]){
        dispatch_async( dispatch_get_main_queue()){
            self.prepareToPlayAsset(asset, requestedKeys: ["playable"])
        }
    }


  func resourceLoader(resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
    .......
    return false
}
Run Code Online (Sandbox Code Playgroud)

当 url 为http/https 时,它不调用resourceLoader(resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource .... - 当 url 是自定义的(例如:'test')时,它调用resourceLoader(resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource...

谁知道原因,resourceLoader不支持http/https吗?

ios avplayer avurlasset avasset swift

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

“找不到资源android:attr / fontVariationSettings。” 反应性地

我有一个本机反应项目,昨天对于android来说还可以,但是今天运行时发生错误react-native run-android。今天我在android上运行之前,什么都没有改变,只能在中打开它AndroidStudio。错误如下:

.gradle / caches / transforms-1 / files-1.1 / appcompat-v7-27.0.2.aar / d1dde4fd0fa50f7f7336597688c557a9 / res / values / value s.xml:252:5-69:AAPT:错误:资源android:attr / fontVariationSettings未找到。

.gradle / caches / transforms-1 / files-1.1 / appcompat-v7-27.0.2.aar / d1dde4fd0fa50f7f7336597688c557a9 / res / values / value s.xml:252:5-69:AAPT:错误:资源android:attr / ttcIndex未找到。

错误:链接引用失败。

失败:构建失败,发生异常。

  • 出了什么问题:任务':app:processDebugResources'的执行失败。

    无法处理资源,有关详细信息,请参见上面的aapt输出。

并且主要配置如下:

"react": "16.6.3",
"react-native": "0.57.8"

gradle plugin:com.android.tools.build:gradle:3.1.0

compileSdkVersion 27
buildToolsVersion "27.0.3"
minSdkVersion 19
targetSdkVersion 27
Run Code Online (Sandbox Code Playgroud)

我花了很多时间解决它,但失败了。

大多数解决方案是将android升级到AndroidX,但是我不能,因为我的项目有很多依赖项,其中有些不支持AndroidX。

所以我想知道为什么android:attr/ttcIndex我运行它时需要它,以及如何修复它和不要升级Android版本并保持compileSdkVersion 27

android aapt react-native

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

如果在GCD中为队列创建相同的名称,它是否是相同的队列?

Q1:如果在GCD中为队列创建相同的名称,它是否是相同的队列?

class Sample {
private var time:Int64 = 0
func asyncSerial(time:Int64){
    let queue = dispatch_queue_create("test",DISPATCH_QUEUE_SERIAL)

    dispatch_async(queue){
        let delayTime = dispatch_time(DISPATCH_TIME_NOW, time)
        self.time = time
        print("async:\(self.time)")

        dispatch_after(delayTime, queue){
            print("wait:\(self.time)")

        }
    }

    print("sync:\(self.time)")
}
}

let s = Sample()
s.result(10)
let s2 = Sample()
s1.result(1)
Run Code Online (Sandbox Code Playgroud)

我在游乐场(Xcode 7.1)运行它,结果如下:

同步:100异步:100同步:0异步:1等待:100等待:1

我瘦的结果应该是:

同步:100同步:0异步:100异步:1等待:100等待:1

grand-central-dispatch ios swift

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

我只能在标签栏项中显示文本并更改样式和位置吗

我在情节提要板中添加了一个标签栏,并且不想将图像设置到标签栏项,如下所示:

在此处输入图片说明

如何在Storybord中更改栏项目标题的字体和位置?

uitabview uitabbaritem ios swift

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

订阅未定义

我实现了一个react-native app,运行正常.但是在模拟器中启用"远程调试js"时发生了"未定义订阅"错误. 在此输入图像描述

reactjs react-native

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