How to move a room on the list (WWDC 2019 video 204)? - swiftui

So I'm following along making the SwiftUI list of rooms and I'm stuck on how to fix the move function.
I've looked through the list of methods but I can't seem to determine which one it would be as it seems that the move method no longer exists.
func move(from source: IndexSet, to destination: Int)
{
store.rooms.move(fromOffSets: source, toOffset: destination)
}
Value of type '[Room]' has no member 'move'; did you mean 'remove'?
I don't mean to remove but simply to be able to move the room on the list.

I fought with this as well. My best guess is that for the presentation they are using an api surface area that isn't part of the preview yet. I've found several things that were presented that are not available. Form View is another one for instance.

Related

Android NavController get backstack

We use NavController.OnDestinationChangedListener and the provided parameter NavDestination to hide/show the bottom navigation bar (which is anchored in the root activity) depending on the current destination. But our logic requires also to know which was the previous destination for the current destination in order to hide/show the bottom navigation bar.
NavController.OnDestinationChangedListener also provides a NavController parameter, and NavController has an internal property called mBackStack which seems to be precisely what we need. So, is there a way to access the NavController backstack without using reflection?
Thanks!
There is a way to infer the NavDestination(s) which are currently in the backstack by accessing all the destinations in the graph and then calling navController.getBackStackEntry in each one of them.
val destinationsInBackStack = navController.graph.mapNotNull { dest ->
try {
navController.getBackStackEntry(dest.id)
dest
} catch (e: IllegalArgumentException) {
null
}
}

Update an element that already has a plugin

Zurb Foundation 6.5.3
I have an accordion menu which needs to be updated via ajax after the initial page load. So initially the menu contains 2 items, then $(document).foundation(); is called. Later after an ajax response is received elements are added (and potentially removed/replaced) within the menu.
I would like to be able to re-use the same elements however, I can't update the plugin to re-style the changed elements. I've tried:
$("#my-menu").foundation(); which doesn't work and shows the error:
Tried to initialize accordion-menu on an element that already has a Foundation plugin.
Foundation.reflow(menu, 'accordion'); which doesn't work.
menu.foundation('reflow'); which doesn't work and shows the error:
Uncaught ReferenceError: We're sorry, 'reflow' is not an available method for AccordionMenu.
I have made it work by destroying and removing the existing menu, re-creating the whole thing, then calling $("#my-menu").foundation(); however this isn't ideal in my opinion.
I found that my issue was due to no one solution working in all 3 cases:
foundation has not yet been initialised
foundation is initialised and the entire element has been replaced since
foundation is initialised and the element has been updated since
Unless someone has a better answer, I solved using this approach:
// this can happen before, or after code creates the menu
$(document).foundation();
console.log("foundation run");
__foundationRun = true;
...
function foundationUpdate(el) {
if (__foundationRun) {
if (el.data('zfPlugin'))
// already initialised, update it
Foundation.reInit(el);
else
// new element, initialise it
el.foundation();
}
// else leave for foundation initialise
}
....
// ... do updates (modify or replace entirely) and then:
foundationUpdate($("#my-menu"));

Entity component architecture : want to split big entity -> hard to refactor

In the first step of development, I design Car and AI as 1 entity.
It works nice (pseudo code):-
for(every entity that is "racing car"){
//^ know type by using flag
// or iterate special component (e.g. "RacingCarComponent")
Entity entity=...
AI* ai=get<AI>(entity);
ai->setInformation(...)
}
for(every entity that is "bicycle"){
Entity entity=...
AI* ai=get<AI>(entity);
ai->setInformation(...) //the info is very different from "racing car"
}
Later, I want a new feature : switch in-out Driver (which effect AI).
I split the entity as shown in the following diagram :-
The above code will be updated to be :-
for(every entity that is "racing car"){
Entity entity=...
AttachAI* aiAttach=get<AttachAI>(entity); //<-- edit
aiAttach->ai->setInformation(...) //<-- edit
}
for(every entity that is "bicycle"){
Entity entity=...
AttachAI* aiAttach=get<AttachAI>(entity); //<-- edit
aiAttach->ai->setInformation(...) //<-- edit
}
Problem
It works nice both before and after the change, but it is hard to maintain.
If there are N types of vehicle in version1 e.g. truck, motercycle, plane, boat, rocket,
I will have to edit N*2 lines of which potentially have already scattered around many .cpp.
Main issue : If I forget to refactor any code, it will still compile fine.
Problem will appear in only run-time.
In real life, I face such issue whenever new design wish to divide an entity into many simpler entities.
The refactoring is always just adding another one indirection.
Question
Suppose that in version1, I don't expect that I will want to switch in/out Driver.
Is it possible to prevent the problem? How?
I may be mistaken, but it seems as though you may be looping through all of the entities multiple times, checking a condition. I am not exactly sure about c++ syntax, so please bear with me:
for (entities as entity) {
info = null;
//Check type to get specific info
if (type is a "racing car"){
info = "fast car";
}
elseif (type is a "bicycle") {
info = "rad spokes";
}
//If we found info, we know we had a valid type
if (info isnt null) {
aiAttach = get(entity);
aiAttach->ai->setInformation(info);
}
}
I'm not sure if the get function requires anything specific for each type. In my pseudocode example, I assume we are only sending the entity and not something type specific. If it does, an additional variable could be used.

Crash during UICollectionViewCell reordering after Swift 3.0 migration

I do have a strange issue in using the reorder feature in my app's UICollectionView. We have a custom layout which is implemented to show a decoration view. The collection view uses a flow based layout. When I move the first cell from its position to last cell position for reordering of the cells, the app crashes before it calls the collection view delegate's collectionView(moveItemAt: to) method.
Attached the stack trace of this issue. You can see that crash is happening in the bridging between NSIndexPath and IndexPath. I am not sure why it is happening inside UIKit. Searching for this issue found that it appears to be bug inside UIKIt which got introduced in Swift 3.0. I tested my old build which was built before swift 3.0 migration and it works without any crashes.
Can someone tell me how can I fix this issue?
Related bugs links
UICollectionView broken after Swift 3 migration?
https://bugs.swift.org/browse/SR-2103
https://bugs.swift.org/browse/SR-2417
func handleLongGesture(_ gesture: UILongPressGestureRecognizer) {
switch(gesture.state) {
case UIGestureRecognizerState.began:
if let movingPageIndexPath = collectionView.indexPathForItem(at: gesture.location(in: collectionView)) {
collectionView.beginInteractiveMovementForItem(at: movingPageIndexPath)
}
case UIGestureRecognizerState.changed:
collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: collectionView))
case UIGestureRecognizerState.ended:
collectionView.endInteractiveMovement()
default:
collectionView.cancelInteractiveMovement()
}
}

Having trouble creating my own adapter

So I'm going along with a lynda.com video on creating a custom list layout. I have gone along with the video but I am not able to change my constructor in order to change the code so it is an array of strings. In both places where I have written MyAdapter, there is a red squiggle below and the top one tells me MyAdapter cannot be resolved to a type. Please assist.
setListAdapter(new MyAdapter<String>(CustomList2Activity.this,
android.R.layout.simple_list_item_1, R.id.textView1, getResources().getStringArray(R.array.companies2)));
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource,
int textViewResourceId, List<String> objects) {
super(context, resource, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
Make sure you are declaring the MyAdapter class in the right place. Make sure you're not declaring it within a function. Also, go to the source menu (assuming you're using eclipse) and press "organize imports" to make sure your imports are right.