小编Ver*_*erd的帖子

sortedArrayUsingComparator的时间复杂度(大O)是多少?的iOS/OSX

我需要知道NSArray类的sortedArrayUsingComparator函数的时间复杂度 .一个消息来源会很棒,因为我可能会在我的学士论文中提到它.我正在按距离到当前位置对一系列位置进行排序.

我能找到的唯一答案是有人说它至少是T(n)= O(n)但可能是T(n)= O(n log n)

我怎么知道?

algorithm macos ios

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

检查用户是否允许本地通知.iOS 8. Obj-C

如果用户允许本地通知,是否没有简单的测试方法?在我拒绝发送本地通知后,我在控制台中发现了警告.当相关事件发生时,它表示该应用程序尝试发送通知,即使用户不允许它.我想在尝试显示通知之前检查是否允许它.在我的情况下看评论,我该怎么做?

我的代码是:

app = [UIApplication sharedApplication];
-(void)showBackgroundNotification:(NSString *) message {
//check if app is in background and check if local notifications are allowed.
    if (app.applicationState == UIApplicationStateBackground /*&& LocalNotificationsAreAllowed*/){
        UILocalNotification *note = [[UILocalNotification alloc]init];
        note.alertBody = message;
        note.fireDate = [NSDate dateWithTimeIntervalSinceNow:0.0];
        [app scheduleLocalNotification :note];
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到用户的提示,如下所示:

UIUserNotificationSettings *settings;
if ([app     respondsToSelector:@selector(registerUserNotificationSettings:)])
{
    settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotification    TypeSound) categories:nil];
    [app registerUserNotificationSettings:settings];
}
Run Code Online (Sandbox Code Playgroud)

我不能使用设置对象?

编辑:我想我已经解决了.这似乎有效.

-(void)showBackgroundNotification:(NSString *) message {
    if (app.applicationState == UIApplicationStateBackground && [app currentUserNotificationSettings].types != UIUserNotificationTypeNone){
        UILocalNotification *note = …
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification ios8

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

iOS中的Singleton Objective C不会阻止多个实例

我知道这有几个主题,但没有人回答我的问题.

我已经像这样实现了我的单例类(了解有关单身人士的争议):

+ (MyClass*) sharedInstance {
    static MyClass *_sharedInstance = nil;
    static dispatch_once_t oncePredicate;
    dispatch_once(&oncePredicate, ^{
        _sharedInstance = [[MyClass alloc] init];
    });
    return _sharedInstance;
}

- (instancetype)init{
    self = [super init];
    if (self) {
        //setup code
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

我尝试实例化一个不同的对象,并将它与sharedInstance返回的'=='进行比较,它们确实不同.

问题:

  1. 不应该创建单个类的多个对象是不可能的吗?这不是重点吗?Java中的单例实现可以防止它.
  2. 如果是这样,怎么样?我应该创建一个设置方法并调用它而不是实现init并执行它吗?
  3. 这是正确的实施吗?

singleton objective-c ios

6
推荐指数
3
解决办法
3382
查看次数