当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Monotouch to Swift conversion

问题描述:

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

}

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: