0

I have a current version of an iOS app I made using Xamarin and Monotouch, but Im looking to port it to Swift due to the high price of Xamarin's subscription. Now my problem is trying to figure out how to port everything. Im looking to change some more C# specific things to Swift such as Collections.

Here is the C# code I need to switch to Swift:

records = new List<Record> {
    new Record{ Album = "Homesick", Artist = "A Day to Remember" },
    new Record{ Album = "What Seperates Me from You", Artist = "A Day to Remember" },
    new Record{ Album = "A lesson in Romantics", Artist = "Mayday Parade" }
};
filteredRecords = new List<Record> ();

Would that be properly translated to this?

let records = [
    Record(album: "A Lesson in Romantics", artist: "Mayday Parade", genre: "Emo", size: 12, speed: "33 1/3", year: 2007)
]

Heres the Record.cs for the structure:

public class Record
{
    public string Artist { get; set; }
    public string Album { get; set; }
    public string Genre { get; set; }
    public int Year { get; set; }
    public string Speed { get; set; }
    public int Size { get; set; }

    public Record ()
    {
    }
}

and the Record.swift:

class Record {
    var album: String!
    var artist: String!
    var genre: String!
    var size: Int64!
    var speed: String!
    var year: Int64!

    init(album: String, artist: String, genre: String, size: Int64, speed: String, year: Int64) {
        self.album = album
        self.artist = artist
        self.genre = genre
        self.size = size
        self.speed = speed
        self.year = year
    }
}
hightekjonathan
  • 581
  • 1
  • 9
  • 29
  • Your array looks okay. Regarding the `Record` class - there's no need to use implicitly unwrapped optionals. Also, there's no need (that I can see) that you need to specify `Int64`, as opposed to `Int`. Have a look at [What's the difference between Int and Int32 in Swift?](http://stackoverflow.com/questions/27440100/what-is-the-difference-between-int-and-int32-in-swift). Finally, you may want to consider using a struct instead of a class for your `Record`; take a look at [Why choose struct over class](http://stackoverflow.com/questions/24232799/why-choose-struct-over-class). – ABakerSmith Sep 13 '15 at 01:40
  • What do you mean 'implicitly unwrapped optionals'? – hightekjonathan Sep 13 '15 at 01:41
  • If you're unfamiliar with Optionals I'd definitely recommend you take a look at [The Swift Programming Language](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/). – ABakerSmith Sep 13 '15 at 01:42
  • So instead of adding ! to the end I don't have to add either? – hightekjonathan Sep 13 '15 at 01:44

0 Answers0