Renamed issues in Swift
Several basic types have dropped the "NS" prefix in Swift 3.0. Earlier in swift 2.2, we used to have NSUserDefaults
, NSURLSession
, NSFileManager
etc. Now, most of them dropped their prefix "NS" and changed to UserDefaults
, URLSession
, FileManager
etc.
Your code contains a lot of types with 'NS' prefix. By simply removing it, your code can be converted to Swift 3. Your converted code looks like as shown below:
protocol HomeModelProtocal: class {
func itemsDownloaded(items: NSArray)
}
class HomeModel: NSObject, URLSessionDataDelegate {
//properties
weak var delegate: HomeModelProtocal!
var data : Data = Data()
let urlPath: String = "http://testurl.com/service.php" //this will be changed to the path where service.php lives
func downloadItems() {
let url: URL = URL(string: urlPath)!
var session: URLSession!
let configuration = URLSessionConfiguration.default
session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
let task = session.dataTask(with: url)
task.resume()
}
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
self.data.append(data);
}
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if error != nil {
print("Failed to download data")
}else {
print("Data downloaded")
self.parseJSON() // This class doesn't have a function parseJSON(). So, it's giving you an error like this
}
}
}
Also, I don't see any function called parseJSON()
in your class. I believe you have to add it.
Facing issues after renaming XCode project
The solution was quite simple. I had to chang in Project directery the Bridging-Header titel from the OldName to the new name.
after adding a ViewController.swift and renaming it won't link my viewController with that swift class
The list of classes populated in your Interface Builder is based on the class names and not the file names. Single files can hold multiple classes.
In addition to changing the file name, you need to also change the class name if you want the class name to be different in Interface Builder and other locations.
If, after changing the class name, it still does not appear in Interface Builder, try building your project by pressing Cmd+B, and looking again.
Consider the following file:
ViewController.swift
import Foundation
import UIKit
class FooController: UIViewController {
//stuff
}
class BarController: UIViewController {
// stuff
}
Despite the file being named ViewController.swift
, ViewController
will not appear in the drop down list for my view controllers.
Instead, I get default, built in UIKit
view controllers, and the two controllers I defined in this file, FooController
, and BarController
:
xcode iOS App Crashes after the renaming of view controller
There is two ways to change the name of ViewController:
1)
Ex.: class LoginViewController: UIViewController - just select the "LoginViewController", then right click -> Refactor -> Rename
This will change the name file name, class name and take care of the storyboard class name.
2) If you not able to use Method 1, then manually rename the file Name(.swift), then you have to go to the storyboard and replace the class name of the view controller. You may have issues with the outlets.
3) After that close the Xcode and then again start your project.
Xcode - renaming project causes problem
In 3.2.1 on Snow Leopard, there is a "Project->Rename..." menu item that works like a charm. I think it was introduced in 3.2. Shame that it's Snow Leopard only.
Add THIS has been renamed to THAT for my own framework in iOS
You can achieve the same behaviour by using @available attribute.
struct Foo {
@available(*, unavailable, renamed: "shared")
static let defaults = Foo()
static let shared = Foo()
}
It will give you an exact behaviour as shown here:
Note:
You can do the same with functions as well, only thing is you have to have the same number of parameters.
struct Foo {
@available(*, unavailable, renamed: "sharedFun(fName:lName:)")
static func defaultFun(first: String, last: String) {}
static func sharedFun(fName: String, lName: String) {}
}
Renaming of Xcode project merge issues
The library path and another path in Xcode build settings seems to be hard coded instead of using $(PROJECT_DIR)
.
You can go to XCode build settings, search for the Library Search path. You need to start the path with:
$(PROJECT_DIR)/your_library_name
Other Build settings you need to search are:
- Check info.plist path
- Header search path
- bridging header path (if using objC and swift)
Related Topics
How to Add Documentation to Enum Associated Values in Swift
Parse.Com Pfgeopoint.Geopointforcurrentlocationinbackground Not Doing Anything
Sort Dictionary Keys by Value, Then by Key
How to Add Icon to a Share Sheet in Swift
Limit Textfield to X Amount of Characters Using Swiftui
Swift Lazy Stored Property Versus Regular Stored Property When Using Closure
Swift How to Convert Parse Createdat Time to Time Ago
How to Resolve Error in Unit Testing When We Have Date Comparison in Codable
How to Delete Item from Collection View
Usage of Withmemoryrebound with Apples Swift 3 Beta 6
Swift 4.2 - _Shared Attribute Near Type
Why Can't I Use Subscripting on a Ckrecord Object in Swift
Tapping an Mkmapview in Swiftui
Swift 5, How to Execute Code After Fetching All Childadded from Firebase