Swift find() method throwing error - xcode

When i opened my app today, Xcode asked if i wanted to update some syntax. I followed through the update prompts and after all was said and done my app now has this error on one of the "find" methods. Ive been scratching my head over this one for about an hour now. Any advice on what might have changed?

As discussed here, Swift 2.0 removed the find method and replaced it with indexOf (as indicated by the error Xcode is giving you).
You can fix your code as follows:
if let index = playlistArray.indexOf(playlistImageView)

Read the error message carefully. It says
find(haystack, needle) is unavailable, call haystack.indexOf(needle)

Related

Script 'Game_Actor' line 335 (Cannot open menu in RPG Maker XP due to missing code?)

I'm very new to coding. I've been using RPG Maker XP recently and have been able to fix most issues I've come across by Googling what needs to be done, however I seem to come across something I can't find an answer for.
I had deleted a class in the database (no script editing involved) so that I could rewrite it entirely, and when I finished and opened the game, I found a couldn't open the menu and the game shut down after showing this error message.
Script 'Game_Actor' line 335 : NoMethodError occured. Unable to find
method 'name' for nil:NilClass.
I looked at line 335 under the 'Game_Actor' window and saw this:
return $data_classes[#class_id].name
As I've said, I know very little about code and so I can't actually see anything wrong with this. I didn't rewrite or edit any of the actual script so I'm not sure how I have affected the script. (I haven't touched any script on the principle I have no idea how to fix it.)
I have searched for answers but unfortunately most people seem to be using later version of the RPG Maker like Ace or MV, and they're different enough to XP that the answers are not relevant to this issue.
If anyone could point me in the right direction, or tell me how to fix this, I would be very appreciative. I've worked really hard on this project and I would hate to have to scrap it and start over.
Thanks again!
Basicaly the error message sais that $data_classes[#class_id] is nil (and that's why $data_classes[#class_id].name is unavailable), so you have to check where it becomes nil and why. I'm afraid further help is impossible without you showing us more code of your app (presumably the full code).
It is likely that the code still tries to access the 'class' you deleted in the database. I take it you deleted a database table, is that right?
The error Unable to find method 'name' for nil:NilClass. means that the variable on which the code is trying access the method name is actually nil. The code expects it to contain an object instead.
From the look of it, $data_classes[#class_id] is a hash which is filled with definitions of 'classes'. It gets filled at some earlier point and since you did delete a class, it cannot find a definition for it.
Important here is that it still knows that it needs the class you deleted. It means this class is mentioned somewhere else before this hash initialization takes place. It might be in a config file or another 'class'. Without seeing the complete code it's hard to ponpoint where exactly.
If you cant find this location, try to restore the class you deleted and instead of deleting it altogether just remove anything from it that you don't need. This way the class itself will still be present and this error will not happen. You will be then able to add what you want in that class instead.

Swift location program wont update

Can someone please tell me what is wrong with this program?
I'm using swift and I'm trying to create an app which will give me values such as longitude/latitude etc. When I run the program, the build has 'succeeded' however, nothing prints to the logs or changes in the simulator.
However, the these are the errors that pop up.
Command /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
and
Command /usr/bin/ditto failed with exit code 1
[
Can someone please tell me what I need to do. I already added the CoreLocation framework too and imported it into my program.
I recently updated to Version 7.1 beta.
thanks in advance.
First, try to clean the project: Product > Clean, or empty the DerivedData folder.
Then if it's not fixed, this error happened to me when I use functions with ambiguous declaration (for example, using .Case instead of MyEnum.Case).
Edit your message by adding your code if the issue still occurs.

How to use "distanceTo", "advancedBy" to handle String in Xcode7 beta6

I have an extension on String, it works fine on Xcode7 beta5.
However, I upgraded to beta 6 yesterday. It seems Swift syntax has some changes. There are some errors while compiling my code.
==================================================
Yes. it shows which methods I should use and also finds some information on apple website. https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS81APIDiffs/modules/Swift.html
When I change the "distance" => "distanceTo". I got the error "Use of unresolved identifier 'distance to'". Does anyone know how to use "distanceTo", "advancedBy" exactly ??
What's happened is that the global functions distance and advance have been replaced by instance methods distanceTo and advancedBy.
OK, I figure out how to use these.

Ninject 3.0 MVC kernel scan not working

What happened to kernel.Scan in Ninject 3.0?
kernel.Scan(scanner =>
{
scanner.FromAssembliesMatching("LR.Service.*");
scanner.FromAssembliesMatching("LR.Repository.*");
scanner.BindWithDefaultConventions();
}
Get a build error.
'Ninject.IKernel' does not contain a definition for 'Scan' and no extension method 'Scan' accepting a first argument of type 'Ninject.IKernel'
Been banging my head for hours trying to figure out what to change it to.
Have not seen any good site or posts explaining how to fix this simply.
This all was working perfectly fine, some piece of ninject got upgraded. After hours of figuring out why nothing was working. I did not reinstall it(knowingly), not sure what happened, but now I've reinstalled everything to 3.0, figured it woulf be better, now I'm stuck with a lack of any help.
Will be checking out this later. Think this is what i was looking for.
http://sharpfellows.com/post/Ninject-Auto-registration-is-changing-in-version-3.aspx
UPDATE:
See out my other ninject3 question on auto discovery
Ninject 3.0 MVC kernel.bind error Auto Registration
I ran into a very similar issue recently because of some library documentation incorrectly referenced “AutoLoadModules”. I had a hard time finding out this was actually a thing from the past. And half of the accepted answer is now a dead link. So in case this can be useful to someone else…
There has been, with NInject3, several breaking changes around Ninject.Extensions.Conventions.
So if you are looking for AutoLoadModules, IKernel.Scan and the like, tough luck.
Instead, you are now left with only IKernel.Bind extension method:
_kernel = new StandardKernel();
_kernel.Bind(s=> s.FromAssembliesMatching("LR.Service.*", "LR.Repository.*")
.SelectAllClasses()
.BindDefaultInterface());

residual header space for TTTableViewController on iOS 5

I have a class that inherits from TTTableViewController, and overwrites the "createDelegate" method to use the TTTableViewDragRefreshDelegate instead of the default Delegate.
The problem that I am seeing right now is that there is some header space that appears before my table content (supplied by data source, of course) for iOS 5, but this isn't there on pre-iOS 5 versions.
I searched around and found this article (http://stackoverflow.com/questions/6651367/how-to-make-the-blue-bar-on-the-top-disappear-for-tttableview-with-list-datasourc), but it doesn't quite help me as I did not overwrite tableView:viewForHeaderInSection: method.
What I have noticed is that for all my TableViewControllers that have this problem, they all seem to overwrite the "createDelegate" method and return TTTableViewDragRefreshDelegate, as mentioned above.
My question is: anyone ran into the same issue? How can I fix this problem?
Okay, figured it out. The problem is with an old three20 library that I was using. Once I upgraded to the latest, it was fixed.

Resources