Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在带Xcode的设备上运行与在不带Xcode的设备上运行的行为差异_Ios_Objective C_Xcode_Singleton - Fatal编程技术网

Ios 在带Xcode的设备上运行与在不带Xcode的设备上运行的行为差异

Ios 在带Xcode的设备上运行与在不带Xcode的设备上运行的行为差异,ios,objective-c,xcode,singleton,Ios,Objective C,Xcode,Singleton,我是一个处理旧的Objective C XCode项目的新手,当时我注意到一些意想不到的行为:当我从XCode在iPhone XSMax上运行该项目时,单例的行为与预期的一样。当我在没有Xcode的iPhone上运行它时,它的行为会有所不同。 在这个无线电台应用程序中,我使用Basemodel Cocoapod()作为一个单身者存储和保存用户在收听广播时选择的喜爱歌曲的基础。每个收藏夹项由字符串的多个属性组成,包括曲目名称、标题、唱片集,包括一个NSDictionary项,其中包含关于艺术家的某

我是一个处理旧的Objective C XCode项目的新手,当时我注意到一些意想不到的行为:当我从XCode在iPhone XSMax上运行该项目时,单例的行为与预期的一样。当我在没有Xcode的iPhone上运行它时,它的行为会有所不同。

在这个无线电台应用程序中,我使用Basemodel Cocoapod()作为一个单身者存储和保存用户在收听广播时选择的喜爱歌曲的基础。每个收藏夹项由字符串的多个属性组成,包括曲目名称、标题、唱片集,包括一个NSDictionary项,其中包含关于艺术家的某些html的四个值/键对

用户按下VC上的按钮,将当前曲目信息(trackInfoSRK)保存到其他喜爱曲目的可变数组中,然后保存

//FavoriteItem.h
#import <Foundation/Foundation.h>
#import "BaseModel.h"

@interface FavoriteItem : BaseModel;

@property (nonatomic, retain) NSDate *time;
@property (nonatomic, retain) NSTimeZone *listenedTimeZone;
@property (nonatomic, retain) NSString *artist;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *album;
@property (nonatomic, retain) NSString *year;
@property (nonatomic, retain) NSString *duration;
@property (nonatomic, retain) NSURL *albumURL;
@property (nonatomic, retain) UIImage *albumImg;
@property BOOL albumErr;
@property BOOL albumLoaded;
@property(nonatomic, retain) NSMutableDictionary *trackInfo;

@end
在VC中设置属性时:

//trackInfoSRK is currently playing trackInfo dict, and it set up in viewDidLoad:

trackInfoSRK = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                 @"", @"PAArtistHTML",
                 @"", @"PAArtistLink",
                 @"", @"lastFMArtistHTML",
                 @"", @"lastFMArtistLink",nil];

//trackInfoSRK is populated along the way. Then when it's favorited:

FavoriteItem *thisFavorite =[[FavoriteItem alloc] init];
thisFavorite.artist = artistName;
thisFavorite.title = songTitle;
.
.
.
thisFavorite.trackInfo = trackInfoSRK;
[[FavoriteList sharedInstance].favorites insertObject:thisFavorite atIndex:0];
        NSLog(@"Adding Favorite at index 0");
BOOL saveGood=[[FavoriteList sharedInstance] save];
当应用程序在从Xcode启动的iPhone XSMax上运行时,这一点很好。但是,当应用程序在手机上自行运行时,所有收藏和包含的属性都会正确保存到可变数组中,但字典trackInfo属性除外:制作的任何新收藏的trackInfo将立即显示当前播放曲目trackInfoSRK的trackInfo(所有其他字符串属性都可以)

就像喜爱的曲目的trackInfo成为指向当前播放曲目中设置的变量的指针,并且它将始终镜像该变量,直到重新启动应用程序为止(此时,喜爱的曲目将冻结到其处于“镜像”状态的最后一个trackInfoSRK

  • 为什么从在设备上的Xcode中运行它到在设备上独立运行它,任何行为都会发生变化

  • 从这个意义上说,我应该寻找什么来告诉我如何解决这个问题?我觉得我错过了一些大而简单的东西

  • 我在SDK 12.2中使用Xcode 10.2.1。部署目标是iOS 11.0


    提前感谢!

    我想你用“收藏的曲目的trackInfo成为变量的指针”来描述它。改为复制trackInfoSDK。类似于,
    thisFavorite.trackInfo=[NSDictionary Dictionary WithDictionary:trackInfoSDK];
    我想你用,“收藏夹曲目的trackInfo成为指向变量的指针”。改为复制trackInfoSDK。类似于,
    thisFavorite.trackInfo=[NSDictionary Dictionary WithDictionary:trackInfoSDK];
    //FavoriteList.h
    @interface FavoriteList : BaseModel
    @property (nonatomic, strong) NSMutableArray *favorites;
    @end
    
    
    //FavoriteList.m
    #import "FavoriteList.h"
    #import "FavoriteItem.h"
    
    @implementation FavoriteList
    
    - (void)setUp
    {
        self.favorites = [NSMutableArray array];
    }
    
    + (BMFileFormat)saveFormat
    {
        //return BMFileFormatHRCodedJSON;
        return BMFileFormatHRCodedXML;
    }
    
    @end
    
    //trackInfoSRK is currently playing trackInfo dict, and it set up in viewDidLoad:
    
    trackInfoSRK = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                     @"", @"PAArtistHTML",
                     @"", @"PAArtistLink",
                     @"", @"lastFMArtistHTML",
                     @"", @"lastFMArtistLink",nil];
    
    //trackInfoSRK is populated along the way. Then when it's favorited:
    
    FavoriteItem *thisFavorite =[[FavoriteItem alloc] init];
    thisFavorite.artist = artistName;
    thisFavorite.title = songTitle;
    .
    .
    .
    thisFavorite.trackInfo = trackInfoSRK;
    [[FavoriteList sharedInstance].favorites insertObject:thisFavorite atIndex:0];
            NSLog(@"Adding Favorite at index 0");
    BOOL saveGood=[[FavoriteList sharedInstance] save];