我想通过按钮点击将ArrayList
LatLng
个Activity
个变量从一个String
传递到另一个{
}。
func checkDuplicates() {
let uniquePropertyKey = "titel"
let entityName = "entity"
let keyPathExpr = NSExpression(forKeyPath: uniquePropertyKey)
let countExpr: NSExpression = NSExpression(forFunction: "count:", arguments: [keyPathExpr])
let countExprDesc = NSExpressionDescription()
countExprDesc.name = "count"
countExprDesc.expression = countExpr
countExprDesc.expressionResultType = NSAttributeType.Integer64AttributeType
let entity: NSEntityDescription = NSEntityDescription.entityForName(entityName, inManagedObjectContext: moc)!
let uniqueAttr: NSAttributeDescription = (entity.attributesByName[uniquePropertyKey]! as? NSAttributeDescription)!
let sortDescriptor = NSSortDescriptor(key: "timestamp", ascending: true)
let fr = NSFetchRequest(entityName: entityName)
fr.resultType = NSFetchRequestResultType.DictionaryResultType
fr.propertiesToFetch = [uniqueAttr, countExprDesc]
fr.propertiesToGroupBy = [uniqueAttr]
fr.sortDescriptors = [sortDescriptor]
let fetchedDictionaries: NSArray = self.fetchDictionariesWithRequest(fr)
println(fetchedDictionaries)
var valuesWithDupes: NSMutableArray?
for dict in fetchedDictionaries {
let count: Int = dict["count"] as! Int
if count > 1 {
valuesWithDupes!.addObject(dict[uniquePropertyKey]!!)
}
}
println(valuesWithDupes)
let dupeFR = NSFetchRequest(entityName: entityName)
dupeFR.includesPendingChanges = false
dupeFR.fetchBatchSize = 20
let predicate = NSPredicate(format: "\(uniquePropertyKey) IN %@", valuesWithDupes!)
dupeFR.predicate = predicate
let dupes: NSArray = self.fetchDictionariesWithRequest(dupeFR)
println(dupes)
}
func fetchDictionariesWithRequest (request: NSFetchRequest) -> NSArray {
var fetchedResultsController = NSFetchedResultsController(fetchRequest: request, managedObjectContext: moc, sectionNameKeyPath: nil, cacheName: nil)
println(fetchedResultsController.fetchedObjects)
var error: NSError? = nil
if fetchedResultsController.performFetch(&error) {
println("Error when fetching Records: \(error)")
return nil
}
return fetchedResultsController.fetchedObjects!
}
可用的那个不起作用请帮帮我....
答案 0 :(得分:0)
将其作为Parcelable对象的ArrayList传递。
// Put the coordinates
ArrayList<LatLng> coordinates = new ArrayList<>();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("coordinates", coordinates);
// Get the coordinates
coordinates = bundle.getParcelableArrayList("coordinates");
要将您需要的包传递给用于调用其他活动的intent对象:
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtras(bundle);
startActivity(intent);
然后在SecondActivity的onCreate中获取包:
ArrayList<LatLng> coordinates = getIntent().getParcelableArrayListExtra("coordinates");
答案 1 :(得分:0)