I'm currently studying the source code of Firefox-iOS app by creating my own Swift project and typing the code line by line.
In one of the source code files, it imported a packaged named Storage
But I don't think the package Storage is part of the apple API and I don't really know how I can import it.
Edit
Multiple podfiles are present in the project folder
In Swift you dont import other Swift files as they are readily available to use directly.
But you need to import another module. It looks like Storage here is a module inside the firefox-ios app workspace and hence you need to import it before using it.
I looked at the sourcecode at Github and it does contain a package named Storage.
You can read this to understand more about Modules and import statement.
Related
Is there any recommendation how to import local files. In my case I would have 2 options:
import 'package:workshop/feed/item.dart';
import 'item.dart';
I haven't found anything on that on the guide Effective Dart: Style nor on Google search.
There are at least two different recommendations, depending on who you ask.
Either works, I personally recommend the latter, shorter, variant.
It is sufficient and it avoids the issue of hard-coding your package name into every file. If you ever want to rename the package, that will be a drudge.
There is one issue which makes some people recommend the former format.
If you import a package library using a non-package: URI, say by having a file in the bin/ or test/ directory do an import like:
import "../lib/mylib.dart";
then that library is now imported using two different URIs:
package:mypkg/mylib.dart and
file:///somewhere/mypkg/lib/mylib.dart
Since Dart identifies libraries by their import URIs, these two imports will be treated as different libraries, each with their own global and static variables, which just happen to have the same source code. That's an annoying problem, and can be hard to debug. If you use the long package:... import everywhere, then at least the issue is restricted to the first library you import. If you use a relative import, import "src/helper.dart";, then that library will now also exist in two versions:
package:mypkg/src/helper.dart and
file:///somewhere/mypkg/lib/src/helper.dart
The real issue here was the first import which contained a /lib/ in the path. You must never have such an import. Using package: URIs for all imports may reduce the issue, but not remove it.
I recommend using the relative path, and making sure that you never have a /lib/ in any import path. Libraries in the /lib/ directory of a pub package are package libraries and should be referred to using package: URIs. If you do that, then relative URIs will be resolved against the package URI and again be a package URI, and all is well.
I have swift 4 project, recently pull from another branch. But whenever i want to import any class which is already exist in project show me the error "No such module...". Please suggest me what is wrong.
You don't need to import files in Swift as they are globally available. In Swift you can only import module, e.g. any framework.
In Swift, if a class already exist in project then you don't need to import it; you can directly use its properties by creating its instance. but if you have problem with it then you need to check target membership for the class. it should be checked for the project like in my example in pics
I have a library that I'm using through Cocoapods, and I'm modifying it slightly. I have a class I've created in my normal project (outside of Cocoapods) that I want to use in the Cocoapod, but when I try to import the file it says that file doesn't exist.
As pods are seemingly achieved through a separate project within the same workspace, I assume that's the reason why I can't access it. How would I access it, however? Do I have to import the file separately into the Pods project and then maintain two separate versions? Or is there a better way?
I wonder how can I import https://github.com/mozilla/firefox-ios to my existing Obj-C project. While it does not a framework, I could not import sources of it in my Obj-C project files when I added the project into workspace. I tried to convert it to a static library, but I could not figured it out. I have a little bit experience on Swift and this creating static library thing. Actually, I am not sure this is the right way to do.
Thanks
You should check the Apples documentation about using Swift in Objective-c.(The Importing Swift into Objective-C part)
You can add a Swift-module header and import your .swift files and use them in your objective-c code.
Say I got a bunch of dart scripts in a folder,
Is there anything I can do like import 'foo/*.dart'?
P.S. What if I got an array of filenames and wanna import those files?
You need to import each library individually.
What you can do is to create a library that imports all other libraries and reexports them.
you can then import this one library and get all libraries imported at once.
library all_in_one;
export library1.dart;
export library2.dart;
export library3.dart;
You could also use the "part of" library composition:
Create 1 .dart file that is your lib eg.: lib.dart and add at the start of this file.:
library lib
For every file in your folder add a:
part "somefile.dart"
part "otherfile.dart"
In all files that are part of this library add at the start:
part of lib
In other files and libs you can then import all those file just via:
import "lib.dart"
This will import all the parts of your library (folder). Keep in mind that the "lib.dart" file is now responsible for all the imports of your lib files. So to import something to "somefile.dart" you add the import to "lib.dart". All imports are then available in all the lib files.
This would be highly unsecure, this is why it is not allowed by design. An attacker would be able to run any malicious code just adding a file with the right name to your folder.