小编cds*_*per的帖子

如何限制Google Cloud Pub/Sub Queue

我正在使用Google的Pub/Sub队列来处理服务之间的消息.一些订户连接到速率限制API.

例如,我正在将街道地址推送到pub/sub主题.我有一个Cloud功能,可以订阅(通过推送)到该主题,并呼叫外部速率限制地理编码服务.理想情况下,我的街道地址可以毫不拖延地推送到主题上,主题将保留这些消息 - 以限速的方式呼叫订户.

无论如何配置这样的延迟或消息分发率限制?增加Ack窗口并没有多大帮助:我已经构建了这个系统以防止长时间运行的功能.

node.js google-cloud-pubsub google-cloud-functions

11
推荐指数
2
解决办法
1146
查看次数

使用Autolayout对齐模态视图

我正在使用presentViewController和一个自定义modalPresentationStyle呈现一个UIViewController,以实现Facebook POP动画过渡.

模态视图本身是完全动态的,使用代码中的Autolayout约束进行定义.没有用于支持模态的xib/storyboard.

我无法将模态视图置于屏幕中心!Autolayout是不够的,因为没有超级视图来添加约束!

我的呈现代码如下所示(取自FB POP代码示例):

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
    UIView *fromView = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view;
    fromView.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
    fromView.userInteractionEnabled = NO;

    UIView *dimmingView = [[UIView alloc] initWithFrame:fromView.bounds];
    dimmingView.backgroundColor = [UIColor colorWithRed:(24/255.0) green:(42/255.0) blue:(15/255.0) alpha:1.0];
    dimmingView.layer.opacity = 0.0;

    UIView *toView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;
    toView.frame = CGRectMake(0,
                              0,
                              CGRectGetWidth(transitionContext.containerView.bounds) - 104.f,
                              CGRectGetHeight(transitionContext.containerView.bounds) - 320.f);
    toView.center = CGPointMake(transitionContext.containerView.center.x, -transitionContext.containerView.center.y);

    [transitionContext.containerView addSubview:dimmingView];
    [transitionContext.containerView addSubview:toView];

    POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    positionAnimation.toValue = @(transitionContext.containerView.center.y);
    positionAnimation.springBounciness = 10;
    [positionAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
        [transitionContext completeTransition:YES];
    }]; …
Run Code Online (Sandbox Code Playgroud)

objective-c uiviewcontroller uiviewanimationtransition ios facebook-pop

10
推荐指数
1
解决办法
2086
查看次数

将指针字段添加到PFUser的子类

我想在我的PFUser子类中添加一个指针字段,由PFUser子类管理.理想情况下,指针对象将在PFUser子类上自动可用 - 在保存和提取用户时保存和提取.

对于任何其他PFObject子类,我只需添加一个Dynamic属性,并确保在查询时使用includeKey.

但是,对于PFUser子类,我实际上从未查询过.如何强制指针对象获取?

objective-c ios parse-platform

10
推荐指数
1
解决办法
329
查看次数

在 Swift Combine 中使用 Publishers.debounce() 的正确语法是什么?

在 Apple 的 2019 年 WWDC 视频中Swift Combine in Practice,他们演示了使用debounce发布者来减慢消息速度。

return $username
  .debounce(for: 0.5, scheduler: RunLoop.main)
  .removeDuplicates()
  .eraseToAnyPublisher()
Run Code Online (Sandbox Code Playgroud)

但是,每当我尝试以类似的方式使用它时,都会出现以下错误:

无法使用类型为“(for:Double,调度程序:RunLoop)”的参数列表调用“debounce”

debounce()签名是:

public func debounce<S>(for dueTime: S.SchedulerTimeType.Stride, 
                          scheduler: S,
                            options: S.SchedulerOptions? = nil) -> 
                                    Publishers.Debounce<Self, S> where S : Scheduler
Run Code Online (Sandbox Code Playgroud)

SchedulerTimeType.Stride 似乎可以用数字初始化,但它对我不起作用,或者我对 Swift 泛型缺乏经验。

调用它的正确方法是什么?

编辑

重复这个问题...

目前,搜索诸如“组合”之类的通用词相当具有挑战性......

macOS 10.15,Xcode 11

swift swift5 combine

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

Skeleton Example for Swift Combine Publisher-Subscriber

As I port some Objective-C code to Swift, I'm trying to better understand the new Combine framework and how I can use it to re-create a common design pattern.

In this case, the design pattern is a single object (Manager, Service, etc) that any number of "clients" can register with as a delegate to receive callbacks. It's a basic 1:Many pattern using delegates.

Combine看起来很适合这个,但示例代码有点薄。下面是一个工作示例,但我不确定它是否正确或按预期使用。特别是,我对对象之间的引用循环很好奇。

class Service {

  let tweets = PassthroughSubject<String, Never>()

  func start() {
    // Simulate the need …
Run Code Online (Sandbox Code Playgroud)

publish-subscribe swift swift5 combine

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

静态const与extern const有何不同?

在我的iOS/Objective C项目中,我经常使用带有API密钥的constants.h文件等.直到今天,我一直在声明我的常数static const:

static NSString * const kAPIKey = @"wembvkejrvb43789gvbiu2bvfake";
Run Code Online (Sandbox Code Playgroud)

这工作正常,但有一个不幸的缺点,我只能创建基元和NSString文字的常量.其他对象(如UIColor对象)不能存储在此常量中,因为它们无法使用静态文字语法进行初始化(我的理解,需要引用).

在阅读了一些C++文档后,我理解了一些事情:

  • static是不必要的,因为它const是隐式静态的.
  • 调用NSString * const x实际上是在x中声明一个常量和不可变的值.我无法更改值,但可以更改x指向的值.
  • 该const具有内部链接,意味着该值立即定义(在编译时可以推测).

这些结论是否正确?

怎样的extern const不同?我假设它们是外部链接的(因此是extern关键字).它们是在运行时定义的吗?我可以创建某种动态 extern const,可以使用类方法返回的值进行设置吗?

例如,我想创建一个包含UIColor值的全局范围常量.我想使用[UIColor colorWithRed:green:blue:alpha:]类方法构造此颜色值.这显然不适用于我一直在使用的内部链接常量(我假设因为它发生在编译时) - 但是可能使用外部常量,可能在+initialize方法中设置吗?

任何有关此行为细节的详细说明都会非常有用.

objective-c ios

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

Objc PromiseKit:在承诺中添加新的承诺

我正在使用PromiseKit来简化我的API请求.

在这种情况下,我从服务器获取对象ID列表.然后我需要获取每个ID的详细信息,并返回一系列详细信息.相当普遍的情况.

实际上,我需要在FIRST承诺中包含的FOR循环中向promise链添加promise.

我已经创建了开始向右移动的代码,但是链可以在第二个promise链(填充浅模型请求)之前完成.

[PMKPromise promiseWithResolver:^(PMKResolver resolve) {
    // Fetch an array of object IDs (shallow objects)
    [APIManager fetchObjectListWithCompletion:^(NSArray *resultObjects, NSError *error) {
        resolve(error ?: resultObjects[0]);
    }];
}].then(^(NSArray *objects){
    // Fill each shallow object (query details)
    PMKPromise *fetches = [PMKPromise promiseWithValue:nil];
    for(id model in objects) {
      fetches.then(^{
            [APIManager fillShallowObject:model withCompletion:^(NSArray *resultObjects, NSError *error) {
              // resolve?
            }];
        });
    }

    // Return promise that contains all fill requests
    return fetches; 
})].then(^{
    // This should be executed after all fill …
Run Code Online (Sandbox Code Playgroud)

asynchronous objective-c promisekit

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

如何处理 NSNull 值

在 Objective C 中,一个常见的做法是经常放弃检查 nil,而是依赖消息 nil 静默失败的事实。

例如,要验证字符串:

if ([myString length] > 1) { // Short and sweet
Run Code Online (Sandbox Code Playgroud)

如果myString为 nil,则此检查将失败 - 正如预期的那样。与人们可能认为的正确实现相比,这是一个巨大的改进,明确检查零:

if (myString && [myString length] > 1) { // Redundant nil check
Run Code Online (Sandbox Code Playgroud)

但是,特别是在 Web API 的情况下,可以想象 myString 是相等的[NSNull null]——类似于 nil,但具有不同的行为。主要关注的是,消息传递 NSNull 会导致异常。例如,我们之前的简短解决方案将导致异常:

// Causes an exception, because [NSNull null] is an object
NSString *myString = (id)[NSNull null];
if ([myString length] > 1) { 
Run Code Online (Sandbox Code Playgroud)

更复杂的是,一个简单的 nil 检查实际上会通过,因为它[NSNull null]是一个有效的对象:

NSString *myString = …
Run Code Online (Sandbox Code Playgroud)

objective-c ios

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

Firebase 离线 iOS:如何可靠地保持同步?

我在我的应用中离线使用 Firebase ,以在用户的​​蜂窝信号接收不佳的情况下保留功能。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {    
    FIRApp.configure()
    FIRDatabase.database().persistenceEnabled = true
    let all = FIRDatabase.database().reference(withPath:"all")
    all.keepSynced(true)
...
Run Code Online (Sandbox Code Playgroud)

但是,我注意到数据并不总是新鲜的。有时在其他地方修改的数据直到强制退出才会显示。此外,有时在注销并重新登录后不会出现新创建的数据。

是否有手动执行同步的功能?

synchronization ios firebase swift firebase-realtime-database

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