andrew falcone8,651 Points
Are typealiases only useable in the file that they are declared?
At 5'39" Pasan says we could use JSON as a typealias, but I'm getting an error "use of undeclared type 'JSON'". The weather.swift file seems to be unaware of the typealias declared in the JSONDownloader.swift file.
Justin HornerTreehouse Guest Teacher
I believe type aliases in Swift have the same scoping rules as variables. If you want the type alias to be available globally, define it outside of the class, otherwise, define it in a class to keep the scope at the class level.
I hope this helps. Happy coding 🙂
Cory Cromer5,072 Points
I'll also add that you can access the the type alias from another class and use it through dot notation. So, using the example in the video, you could access the type alias in JSONdownloader in the Weather extension by using JSONdownloader.JSON.