将NSCollectionView中的多个值转换为一个NSString

时间:2016-06-27 21:00:24

标签: objective-c nsstring nsarray nscollectionview

如果存在名为" BETA"的内容,则会检查我的收藏视图。在这种情况下,它应该看看它的itemID是什么。这应该放在一起并返回类似" 2 4"在plist文件中。

在我的日志中,我得到了#34; Teststring 2"和" Teststring 4"但我需要的是它记录" Teststring 2 4"。因此需要将这两个值结合在一起。

Click here to see the log

数组:

  self.content = [NSMutableArray arrayWithObjects:
                      @{@"itemTitle":@"Passave",
                        @"itemVersion":@"1.2.0.1",
                        @"itemBundleID":@"com.Stormar.Passave",
                        @"itemID":@"0",
                        @"itemDescription":@"Fill in your password quick.",
                        @"itemPrice":@"€19,99",
                        @"itemUrlDownload":@"https://www.dropbox.com/s/vf0wdc3bnida3mb/Passave.zip?dl=0",
                        @"itemImage":@"https://upload.wikimedia.org/wikipedia/commons/a/a1/Passave.png"},

                      @{@"itemTitle":@"TopRadio",
                        @"itemVersion":@"1.3",
                        @"itemBundleID":@"Stormar.TopRadio",
                        @"itemID":@"1",
                        @"itemDescription":@"Listen to music from TopRadio!",
                        @"itemPrice":@"FREE",
                        @"itemUrlDownload":@"http://topradiodownloalink.com",
                        @"itemImage":@"https://upload.wikimedia.org/wikipedia/commons/0/0e/TopRadio.png"},

                      @{@"itemTitle":@"Shifter",
                        @"itemVersion":@"1.0",
                        @"itemBundleID":@"com.Stormar.Shifter",
                        @"itemID":@"2",
                        @"itemDescription":@"Switch your symbols with numbers!",
                        @"itemPrice":@"BETA",
                        @"itemUrlDownload":@"http://shifterdownloalink.com",
                        @"itemImage":@"https://upload.wikimedia.org/wikipedia/commons/0/07/Shifter.png"},

                      @{@"itemTitle":@"Spammer",
                        @"itemVersion":@"1.1.0",
                        @"itemBundleID":@"com.Stormar.Spammer",
                        @"itemID":@"3",
                        @"itemDescription":@"Spam your friends ;)",
                        @"itemPrice":@"FREE",
                        @"itemUrlDownload":@"http://spammerdownloalink.com",
                        @"itemImage":@"https://upload.wikimedia.org/wikipedia/commons/c/c4/Spammerl.png"},

                      @{@"itemTitle":@"Mucow Creator",
                        @"itemVersion":@"0.1.2",
                        @"itemBundleID":@"com.Stormar.Mucow-Creator",
                        @"itemID":@"4",
                        @"itemDescription":@"Create your own Adobe Muse Widgets!",
                        @"itemPrice":@"BETA",
                        @"itemUrlDownload":@"http://mucowcreatordownloalink.com",
                        @"itemImage":@"https://upload.wikimedia.org/wikipedia/commons/0/06/Mucow_Creator.png"},

                    nil];

守则:

if ([[self.representedObject valueForKey:@"itemPrice"] isEqualToString:@"BETA"]) {
            NSLog(@"BETA YES ID : %@", [self.representedObject valueForKey:@"itemID"]);

            NSMutableString *teststring = [[NSMutableString alloc]init];
            [teststring appendString:[self.representedObject valueForKey:@"itemID"]];
            NSLog(@"Teststring %@", teststring);
            [Functions saveDataToPlist:plistPathSMSettings OfType:@"String" Value:teststring ForKey:betaDef];
        }

1 个答案:

答案 0 :(得分:0)

.h文件

NSMutableString *teststring;

.m文件

teststring = [[NSMutableString alloc]init];
NSLog(@"Teststring 1: %@", teststring);

NSString* LibraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPathSMSettings = [LibraryPath stringByAppendingString:stormarManagerSettingsPlistPath];

NSString *betaKeyDef = [SMSettingsDEF stringByAppendingString:@"BETA's"];
NSString *betaDef = [SMInAppCommunicationDEF stringByAppendingString:@"BETA App Id"];

NSString *isBeta = [Functions readDataFromPlist:plistPathSMSettings ForKey:betaKeyDef];

if ([isBeta isEqualToString:@"YES"]) {
    [Functions saveDataToPlist:plistPathSMSettings OfType:@"String" Value:@"" ForKey:betaDef];
}
else if ([isBeta isEqualToString:@"NO"]) {
    if ([[self.representedObject valueForKey:@"itemPrice"] isEqualToString:@"BETA"]) {
        NSLog(@"BETA YES ID : %@", [self.representedObject valueForKey:@"itemID"]);
        NSLog(@"Teststring 2: %@", teststring);
        NSString *theString = [teststring stringByAppendingString:[self.representedObject valueForKey:@"itemID"]];
        NSLog(@"Teststring 2 1: %@", theString);
        [teststring appendString:theString];
        NSLog(@"Teststring 3: %@", teststring);
        //[Functions saveDataToPlist:plistPathSMSettings OfType:@"String" Value:teststring ForKey:betaDef];
    }
}

日志文件

2016-06-28 00:33:49.368503 Stormar Manager[61304:4951263] Teststring 1:
2016-06-28 00:33:49.372203 Stormar Manager[61304:4951263] Teststring 1:
2016-06-28 00:33:49.377497 Stormar Manager[61304:4951263] Teststring 1:
2016-06-28 00:33:49.380680 Stormar Manager[61304:4951263] Teststring 1:
2016-06-28 00:33:49.381017 Stormar Manager[61304:4951263] Teststring 1:
2016-06-28 00:33:49.381130 Stormar Manager[61304:4951263] BETA YES ID : 2
2016-06-28 00:33:49.381148 Stormar Manager[61304:4951263] Teststring 2:
2016-06-28 00:33:49.381172 Stormar Manager[61304:4951263] Teststring 2 1: 2
2016-06-28 00:33:49.381182 Stormar Manager[61304:4951263] Teststring 3: 2
2016-06-28 00:33:49.381519 Stormar Manager[61304:4951263] Teststring 1:
2016-06-28 00:33:49.421572 Stormar Manager[61304:4951263] Teststring 1:
2016-06-28 00:33:49.421755 Stormar Manager[61304:4951263] BETA YES ID : 4
2016-06-28 00:33:49.421772 Stormar Manager[61304:4951263] Teststring 2:
2016-06-28 00:33:49.421781 Stormar Manager[61304:4951263] Teststring 2 1: 4
2016-06-28 00:33:49.421789 Stormar Manager[61304:4951263] Teststring 3: 4

Image of the log