I have 2 question. First, I can't convert String array to Int array from core data
let sum = recordFilter.map{$0.amount!.dropFirst()} //["9.99", "6.58"]
let intSum = sum.map({Int($0)}) //[nil, nil]
My array format:
[<Record: 0x600000099fa0> (entity: Record; id: 0xd0000000003c0000 <x-coredata://913F25A5-B2C9-4646-9091-5EFE7F906908/Record/p15> ; data: {
accountbook = "first book";
amount = "\U00a59.99";
assest = nil;
category = "\U6295\U8d44";
createdAt = "2017-11-16 16:00:00 +0000";
date = nil;
id = 15;
recordtype = "\U6536\U5165";
remark = "";
toAccBook = nil;
}), ...})]
Second, I want to sum it by .reduce but I got Cannot invoke 'reduce' with an argument list of type '(Int, _)' How to fix it?
let sum = recordFilter.map{$0.amount!.dropFirst()}.reduce(0, +)
let intSum = sum.map({Int($0)}).reduce(0, +)
//Cannot invoke 'reduce' with an argument list of type '(Int, _)'
Intis integer without decimal places. The strings do have decimal places and even seem to start with a linefeed character in the record. Why do you use a string type for a numeric value anyway?