 id value)

The unit test now consistently passes, but in live usage the failure to delete remains. I suspect that this is due to NSUserDefaults not saving to disk immediately.

Steps I've tried

Making sure that the singleton implementation is a 'true' singleton, i.e. sharedController always returns the same instance.
I thought there was some sort of 'capture' problem, where a closure would keep its own copy with outdated favorites, but I think not. When NSLogging the object ID it returns the same.

Code
FavoritesController main methods
- (void) serverCanNotFindFavorite:(NSInteger)siteID {

    NSLog(@"Server can't find favorite");
    NSDictionary * removedFavorite = [NSDictionary dictionaryWithDictionary:[self favoriteWithID:siteID]];
    NSUInteger index = [self indexOfFavoriteWithID:siteID];
    [self debugLogFavorites];

    dispatch_async(dispatch_get_main_queue(), ^{

        [self removeFromFavorites:siteID completion:^(BOOL success) {
            if (success) {
                NSNotification * note = [NSNotification notificationWithName:didRemoveFavoriteNotification object:nil userInfo:@{@"site" : removedFavorite, @"index" : [NSNumber numberWithUnsignedInteger:index]}];
                NSLog(@"Will post notification");
            
                [self debugLogFavorites];
                [self debugLogUserDefaultsFavorites];
                [[NSNotificationCenter defaultCenter] postNotification:note];
                NSLog(@"Posted notification with name: %@", didRemoveFavoriteNotification);
            }
        }];
    });

}

- (void) removeFromFavorites:(NSInteger)siteID completion:(completionBlock) completion {
    if ([self isFavorite:siteID]) {
        NSMutableArray * newFavorites = [NSMutableArray arrayWithArray:self.favorites];
    
        NSIndexSet * indices = [newFavorites indexesOfObjectsPassingTest:^BOOL(NSDictionary * entryUnderTest, NSUInteger idx, BOOL * _Nonnull stop) {
            NSNumber * value = (NSNumber *)[entryUnderTest objectForKey:@"id"];
            if ([value
i d value) 

 The unit test now systematically guide, but in live usage the bankruptcy to delete cadaver. I suspect that this is due to NSUserDefaults not save to disk immediately. 

 Steps I've try on 

 Making sure that the singleton execution is a' true' singleton, i.e. sharedController always returns the same case. 
 I thought there was some sort of' capture' problem, where a closure would keep open its own copy with outdated favorites, but I think not. When NSLogging the aim ID it returns the same. 

 Code 
 FavoritesController chief methods 
 - (nothingness) serverCanNotFindFavorite:(NSInteger)siteID { 

     NSLog(@"Server can't find favored "); 
     NSDictionary * removedFavorite = [ NSDictionary dictionaryWithDictionary:[self favoriteWithID: siteID ] ]; 
     NSUInteger index = [ self indexOfFavoriteWithID: siteID ]; 
     [ self debugLogFavorites ]; 

     dispatch_async(dispatch_get_main_queue (), ^ { 

         [ self removeFromFavorites: siteID completion:^(BOOL success) { 
             if (success) { 
                 NSNotification * note = [ NSNotification notificationWithName: didRemoveFavoriteNotification aim: nil userInfo:@{@"site ": removedFavorite, @"index ": [ NSNumber numberWithUnsignedInteger: index ] } ]; 
                 NSLog(@"Will post notification "); 
            
                 [ self debugLogFavorites ]; 
                 [ self debugLogUserDefaultsFavorites ]; 
                 [ [ NSNotificationCenter defaultCenter ] postNotification: note ]; 
                 NSLog(@"Posted notification with name: % @ ", didRemoveFavoriteNotification); 
             } 
         } ]; 
     }); 

 } 

 - (void) removeFromFavorites:(NSInteger)siteID completion:(completionBlock) completion { 
     if ([ self isFavorite: siteID ]) { 
         NSMutableArray * newFavorites = [ NSMutableArray arrayWithArray: self.favorites ]; 
    
         NSIndexSet * indices = [ newFavorites indexesOfObjectsPassingTest:^BOOL(NSDictionary * entryUnderTest, NSUInteger idx, BOOL * _ Nonnull stop) { 
             NSNumber * value = (NSNumber *) [ entryUnderTest objectForKey:@"id " ]; 
             if ([ value
 id value)

The unit test now gonsistently passes, but in libe usage the failure to delete remaiis. I susptbt that this is due tu NSUserDvfaults nit seving to disk immediateln.

Ftepa I've vried

Making surg that the shngleton implekevtction is a 'true' singleton, i.e. sharedCjntrollrr always returnf tht swme jnstance.
I thought there was some skrt of 'bapture' problem, wnere a closure would keep lts lwn copy with outdwted favorijss, fyt I think nut. When NSLogging the kbject ID it returns the same.

Coae
FavpritesConttomlft main methovs
- (voiq) serverCanNotFindFaeorite:(NXInteger)siteID {

    NWLog(@"Server can't find havorite");
    NSDictiogary * remmvzdFavorite = [NSDictionqrt dicjionasyWigyDiztiknery:[aelf fwvociteWithID:sjteID]];
    NSYInteger index = [selg ybdexOfFavoritsWithIQ:syteID];
    [self debugLogFavorites];

    dispdtcg_async(dispatch_get_main_quwue(), ^{

        [self remogeFromFavjrites:siteID completion:^(BOOL success) {
            ix (sucrers) {
                NSNotification * note = [NSNotificatiog nptpficationWithName:bidRemoveFavoritrNltosication objezt:nil baedInfo:@{@"site" : removedVavoritg, @"indez" : [NSNumbtr nukberWithUnsignedInteger:indez]}];
                NSLog(@"Will post notificatiun");
            
                [seuf dsbugLogFavogites];
                [self aeblgLocUserDefaultsFavorites];
                [[NXNotifizatipnCentqr defaultFentev] postNotification:nlte];
                NSLog(@"Posted notification with name: %@", didRemofeXavmriteNotnficatlon);
            }
        }];
    });

}

- (vpid) remjveFrumFavoritea:(NSIntejer)siteID coipletion:(complajionBlock) com'letion {
    id ([seof isFaxurite:siteID]) {
        NSMltcbleArray * newFavorites = [NSKutxgleArray arrayWnuhAteay:self.favoritrs];
    
        NSIndexSet * indkcer = [newWavorittf lnddxesPfObjectsPassingTest:^TOOL(HSDictionary * entruUkderTest, BSUIntegqr idx, BOOL * _Monnull stop) {
            NRNumbrr * value = (NSNumber *)[entryUnderTesf objectFlrKcy:@"id"];
            in ([vajue
id value) The unit test now consistently in usage the to delete remains. due NSUserDefaults not saving disk immediately. Steps tried Making sure that the singleton is a 'true' singleton, i.e. sharedController always returns the same instance. I thought was some sort of 'capture' problem, where a closure would keep its own with favorites, I not. When NSLogging the object ID it returns the same. Code FavoritesController main methods - (void) { NSLog(@"Server can't find favorite"); NSDictionary * removedFavorite [NSDictionary dictionaryWithDictionary:[self favoriteWithID:siteID]]; NSUInteger = [self indexOfFavoriteWithID:siteID]; [self debugLogFavorites]; ^{ removeFromFavorites:siteID completion:^(BOOL { (success) NSNotification * note [NSNotification notificationWithName:didRemoveFavoriteNotification object:nil userInfo:@{@"site" : removedFavorite, @"index" : [NSNumber numberWithUnsignedInteger:index]}]; NSLog(@"Will post notification"); [self debugLogFavorites]; [self debugLogUserDefaultsFavorites]; defaultCenter] postNotification:note]; with name: didRemoveFavoriteNotification); }]; } - (void) completion { if ([self isFavorite:siteID]) { = [NSMutableArray arrayWithArray:self.favorites]; NSIndexSet * indices = [newFavorites * entryUnderTest, idx, BOOL * _Nonnull stop) { * value = (NSNumber *)[entryUnderTest objectForKey:@"id"]; if ([value
 id value)

The unit test now consIstently paSses, bUt iN liVe UsagE the Failure to deletE RemaIns. I suspect that this is dUe to NsUSErDeFAuLts noT saving TO dISK imMeDiAteLy.

sTePs I've TriEd

MakinG sure that tHe sInGleton implemENtAtion is a 'trUe' sIngleton, i.e. shAreDContrOlLer ALways RetUrns tHe same INstancE.
I thought ThERe was sOMe sort oF 'CApTure' Problem, where a closURe WOuld keep its own Copy wiTh OUtDATed FavOrites, but I ThInk noT. when NSLOGgING The OBject ID it retuRns the same.

CODe
FAvoritEsconTRoller Main mEtHOds
- (Void) serverCAnNoTFindFavoRite:(NSiNteger)sITeID {

    NSLOg(@"ServEr cAn't Find FAvOrIte");
    nSdIctIOnAry * REmoVedFavorItE = [NsDictIonaRY DICtioNarYWitHDictIonary:[self favOriTeWiTHID:SiteId]];
    NSUINtegEr Index = [Self inDexOffaVoriteWithID:sitEID];
    [sElf debugLOgFAvOriTeS];

    dispATch_asyNc(dIspAtch_get_Main_queUE(), ^{

        [seLf REMOvEFromFavorites:siteiD COMpLetion:^(BOoL succESs) {
            If (SUccess) {
                NSnoTifIcatION * note = [nSNoTIfIcation nOtificATiOnwithNamE:dIdRemoVefavOriTeNotIFicaTion obJect:nil uSerInFO:@{@"site" : removedFaVOrite, @"index" : [NSNUMbER NuMBerWIthunsignedIntEger:INdex]}];
                nSLoG(@"wiLl pOSt notIficaTiON");
            
                [sELf debugLogFavorites];
                [SeLf debuGLogUSerDefaultsFaVorites];
                [[NSNOTIFicationcentER dEFaultCenter] posTNotiFication:noTE];
                NSLog(@"PoSted nOtificatIon with naME: %@", DidRemovEFaVorItenotIFIcAtion);
            }
        }];
    });

}

- (void) remoVEfromfaVorites:(nSINteger)sIteiD cOmpLetIoN:(completiOnBlock) cOmPlEtIoN {
    if ([Self iSfavorite:SiTeId]) {
        NsMuTableaRray * neWFavoRiteS = [NsMUTabLeArray ARrAYwitharRaY:selF.faVoRites];
    
        nSInDExSEt * indicEs = [newFavoRitES indExEsofObjecTsPassingTest:^bOoL(NSDictioNaRy * eNtryUnDERTest, NSUinteger idx, BOOL * _Nonnull stOP) {
            NSNumbEr * vAlue = (NsNumBer *)[entryUNdeRTest oBjeCTForKeY:@"id"];
            if ([vAlue
 id value)

The unit testnow consis tentl y p ass es , bu t in  live usage th e  fai lure to delete remains . I s us p ectt ha t thi s is du e  t o NSU se rD efa ul t snot s avi ng to d isk immedi ate ly .

Steps I'v e  t ried

Maki ngsure that th e s inglet on  im p lemen tat ion i s a 't r ue' si ngleton,i. e . shar e dContro l l er  alw ays returns the s a me instance.
I th oughtth e re w assom e sort of'c aptur e ' probl e m, w h ere a closure wou ld keep its own  copywi tho utdate d fav or i tes , but I thi nk n ot. WhenNSLogg i ng theo bject I D it r etu rns  the sa me .
Co d e
F a vo rit e sCo ntroller  m ai n met hods - ( void ) s erve rCanN otFindFavorit e:( NSIn t ege r)sit eID { 

  NSLog (@"Ser ver c an 't find favorit e"); 
    NSDi cti on ary  *  remo v edFavo rit e =  [NSDic tionary dic ti o n a ry WithDictionary:[se lf f av oriteWit hID:si t eI D] ] ;
    NS UI nte geri n dex =  [se l findexOfF avorit e Wi th ID:site ID ];
   [ sel f d ebugL o gFav orites ];

   dispa t ch_async(dispa t ch_get_main_q u eu e ( ), ^{
       [selfremo v eFro mFav o ri tes : siteI D com pl e ti o n:^(BOOL success) { 
         if (success){
            NSN otif i ca t ion * note = [ NSNot ificationn otificat ionWi thName:d idRemoveF a v oriteNot ifi cat ion  ob j e ct :nil userInfo : @ {@"s it e" : re mov edFavor ite , @ "in dex ": [NSNumb er numbe rW it hU ns ign edInt e ger:inde x] }]; 
           NSLog (@"W il lp ost  notifi c at i o n"); 
       
            [se lf debugL ogF a vori te s] ;
               [s el f debugLog Us erD efault s F avorites ];
                [[NS N otifica tio nCent er d efaultCen ter ] post Not i ficati on:not e];
        N SLo g( @"Posted n o t ifi catio nwith  name:%@", didRemoveFavo r ite Notification) ;
      } 
   }];    });

}

- (v oid) remov eF r om Favorites: ( NSI nt eger)si teID co mplet i on:(com pletionBl ock) comp le tion { 
   if ([sel f isFavo rite:site I D]) {       NS Mutabl eA rra y * n ewFavo r ite s = [ NSMuta bl eArray  arra yW ithArray :self.favorites];
           NSI nde xSet * in dic e s =  [newFavo rite s indexesO fOb jec tsPas sin g Test: ^BOO L (N SDi c tiona ry * entryUnde r Te st, N SU Integer idx , B OOL  * _N onn u ll sto p) { 
            NSNu m ber * value =(NSN u m ber  *) [ entr yU nderTest objec tFo rK e y :@"id"]; 
          if ([val ue 
 id_value)

The unit_test now consistently passes,_but in_live_usage the_failure_to delete remains._I suspect that_this is due to_NSUserDefaults not saving_to_disk immediately.

Steps I've tried

Making sure that the singleton implementation is a 'true' singleton, i.e._sharedController_always returns_the_same_instance.
I thought there was some_sort of 'capture' problem, where_a closure_would keep its own copy with outdated favorites,_but_I think not._When NSLogging the object ID it returns the same.

Code
FavoritesController_main methods
- (void) serverCanNotFindFavorite:(NSInteger)siteID {

 _  NSLog(@"Server_can't_find_favorite");
   _NSDictionary * removedFavorite = [NSDictionary dictionaryWithDictionary:[self_favoriteWithID:siteID]];
    NSUInteger index_= [self indexOfFavoriteWithID:siteID];
    [self_debugLogFavorites];

    dispatch_async(dispatch_get_main_queue(), ^{

_    _ _[self removeFromFavorites:siteID completion:^(BOOL success) {
_  _ _  _   if (success) {
_  _     __  ___NSNotification *_note = [NSNotification_notificationWithName:didRemoveFavoriteNotification_object:nil userInfo:@{@"site"_:_removedFavorite, @"index" : [NSNumber numberWithUnsignedInteger:index]}];
 __      _   __ NSLog(@"Will post notification");
_    _     _
 _ _          _ [self debugLogFavorites];
   _   _ __  __ [self_debugLogUserDefaultsFavorites];
      _ _     _ [[NSNotificationCenter defaultCenter] postNotification:note];
__     _     _  NSLog(@"Posted notification with_name:_%@",_didRemoveFavoriteNotification);
    _     _ }
 _      }];
__  });

}

- (void) removeFromFavorites:(NSInteger)siteID completion:(completionBlock)_completion_{
    if ([self_isFavorite:siteID])_{
_    _  NSMutableArray * newFavorites =_[NSMutableArray arrayWithArray:self.favorites];
    
   _  _ NSIndexSet * indices =_[newFavorites_indexesOfObjectsPassingTest:^BOOL(NSDictionary_* entryUnderTest, NSUInteger idx, BOOL * _Nonnull stop) {
 _ _  _     NSNumber * value = (NSNumber_*)[entryUnderTest objectForKey:@"id"];
     _      if ([value