小编Rau*_*nak的帖子

如何在xcode的Playground中导入RxSwift?

我试图在xcode playground中导入rxswift:

gem install cocoapods-playgrounds
Run Code Online (Sandbox Code Playgroud)

在那之后

pod playgrounds RxSwift
Run Code Online (Sandbox Code Playgroud)

但它没有发生.怎么做?

xcode cocoapods swift rx-swift

7
推荐指数
2
解决办法
4647
查看次数

嵌入在UITableViewCell中的UICollectionViewCell在重新出现时更改滚动位置

我有一个带有水平集合视图的单元格的tableview.我有多个具有相同风格的单元格.假设索引0和5处的tableView单元格具有相同的样式(我在dequeueReusableCellWithIdentifier中使用相同的UITableViewCell子类).

  1. 用户在索引5处滚动到tableViewCell.他向左滚动水平集合视图(假设现在隐藏了red-1和yellow-2单元格,而最左边的是cyan-3).
  2. 用户在索引0处滚动回tableViewCell.虽然它是一个不同的UITableViewCell实例,但集合视图偏移设置为与索引5处的单元格相同.

在此输入图像描述

简而言之,当我重新使用tableview单元格时,UITableViewCell内部滚动视图的内容偏移量被设置为之前重用的单元格.

有一些我可以禁用此行为,以便每个单元格保持它自己的偏移量,无论另一个单元格上的任何滚动活动.

uitableview uiscrollview ios uicollectionview

6
推荐指数
2
解决办法
764
查看次数

使用自定义kext在MAC OS X上隐藏USB音频设备

我正在开发一个应用程序,该应用程序执行自定义音频处理并将处理过的音频发送到USB耳机。我的要求是,在“系统偏好设置”的“音频输出设备”列表中,USB耳机对用户不可见。使用Apple的“ SampleUSBAudioOverrideDriver”无代码kext示例代码,我可以更改接口名称,但我确实需要隐藏它。可以将AppleUSBAudioDevice子类化吗?

macos usb iokit core-audio kernel-extension

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

如何在Mac OS X上使用Core Audio API以编程方式设置扬声器配置?

我有一个7.1声道音频输出设备和一个自定义kext来驱动它.我的自定义应用程序需要向设备发送7.1后置声道音频数据,但设备只接收2声道音频数据.我在"音频MIDI设置"应用程序中选中了"配置扬声器"选项,并将其设置为立体声.当我将它设置为"7.1后环绕"时一切正常.在我的最终产品中,我不希望用户必须手动完成所有这些操作.所以,问题是 - 是否有任何Core Audio API或任何其他方式以编程方式执行此操作?

在此输入图像描述

macos iokit core-audio kernel-extension

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

在 try 中使用零合并运算符?for 抛出并返回可选值的函数

我想在以下两种情况下使用 nil-coalescing 运算符设置默认值:

  1. 函数抛出错误
  2. 函数返回 nil

请看一下下面的代码片段。我有以下问题:

  1. 为什么 item1 为零?
  2. item1 和 item2 的初始化有什么区别
enum VendingMachineError: Error {
    case invalidCode
}

class VendingMachine {
    func itemCode(code: Int) throws -> String? {
        guard code > 0 else {
            throw VendingMachineError.invalidCode
        }
        if code == 1 {
            return nil
        } else {
            return "Item #" + String(code)
        }
    }
}

let machine = VendingMachine()

// Question: Why is this nil?
let item1 = try? machine.itemCode(code: 0) ?? "Unknown"
print(item1)
// nil

// …
Run Code Online (Sandbox Code Playgroud)

error-handling swift option-type

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

设置self.delegate = self是不好的设计

我有一个UIViewController子类(比如MyViewController).

MyViewController.h

@protocol TargetChangedDelegate
    -(void) targetChanged; 
@end

@interface MyViewController

@property (weak) id<TargetChangedDelegate> targetChangedDelegate;

-(void) doSomethingOnYourOwn;

@end
Run Code Online (Sandbox Code Playgroud)

MyViewController.m

@implementation MyViewController <TargetChangedDelegate>

-(void) doSomethingOnYourOwn
{
  // DO some stuff here

  // IS THIS BAD ??
  self.targetChangedDelegate = self;
}

-(IBAction) targetSelectionChanged 
{
  [self.targetChangedDelegate targetChanged];
}

-(void) targetChanged
{
   // Do some stuff here
}

@end
Run Code Online (Sandbox Code Playgroud)

基于某些条件,实例化MyViewController实例的类可能决定将自己设置为委托.

Foo.m

@property(strong) MyViewController *myVC;

-(void) configureViews
{
  self.myVC = [[MyViewController alloc] init];
  [self.view addSubview:self.myVC];

  if (someCondition) 
  {
    self.myVC.targetChangedDelegate = self;
  }
  else
  {
    [self.myVC doSomethingOnYourOwn]
    //MyViewController …
Run Code Online (Sandbox Code Playgroud)

delegates protocols objective-c ios

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

为什么Swift库使用"enum CommandLine"而不是"struct CommandLine"?

Swift标准库声明CommandLine为枚举.

/// Command-line arguments for the current process.
public enum CommandLine {

    /// Access to the raw argc value from C.
    public static var argc: Int32 { get }

    /// Access to the raw argv value from C. Accessing the argument vector
    /// through this pointer is unsafe.
    public static var unsafeArgv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?> { get }

    /// Access to the swift arguments, also use lazy initialization of static
    /// properties to safely initialize the swift arguments.
    public static …
Run Code Online (Sandbox Code Playgroud)

enums struct swift

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