0
let newFeed = Feed(profilePicture: "image_boyce_avenue",artistName: "Boyce Avenue", videoUrl: "boyce_avenue-dont_let_me_down",videoTitle:"Dont let me down", videoViews: "160",likes: "200",shoutouts: "200",comments: [Comment.init(userName: "Megan Nicole", userComment: "Wow!", likes: "50", timeOfComment: Date())],votes: "50", dateCreated: Date(), feedType: FeedContentType.VIDEO_FEED.rawValue, userActivity :"This user liked your video")
ArtistProfileData.sharedInstance.add(array: newFeed,artistName: name)
print("Count in dictionary ",ArtistProfileData.sharedInstance.artistProfileDict[name]?.feeds.count as Any)
上記のコードでは、配列数は追加後に正しく戻されます。シングルトンクラスに配列を追加し、countは別のコントローラで0を返しました
私は戻っカウントが続いて0
print("Count in anotherbview",ArtistProfileData.sharedInstance.artistProfileDict[artistSelected]?.feeds.count as Any)
return (ArtistProfileData.sharedInstance.artistProfileDict[artistSelected]?.feeds.count)!
ある別のクラスで同じ配列にアクセスしよう
struct Profile {
var artistName: String
var artistDescription: String
var totalLikes: String
var totalViews: String
var totalFollowing: String
var totalFollowers: String
var imageUrl: String
var feeds : [Feed]
init(artistName: String,artistDescription:String,totalLikes:String,totalViews:String,totalFollowing:String,totalFollowers:String,imageUrl:String, feeds:[Feed]) {
self.artistName = artistName
self.artistDescription = artistDescription
self.totalLikes = totalLikes
self.totalViews = totalViews
self.totalFollowing = totalFollowing
self.totalFollowers = totalFollowers
self.imageUrl = imageUrl
self.feeds = feeds
}
}
プロファイルオブジェクトが続きシングルトンクラス
class ArtistProfileData{
static let sharedInstance = ArtistProfileData()
var artistProfileDict = [String : Profile]()
var loggedInUserProfile = Profile(artistName: "John Smith", artistDescription: "Admiral of New England, English soldier, explorer, and author.", totalLikes: "174", totalViews: "200", totalFollowing: "100",totalFollowers:"50",imageUrl:"image_singer", feeds:[])
private init() {
getProfilesDictionary()
}
func getProfilesDictionary()->[String: Profile]{
artistProfileDict["John Smith"] = loggedInUserProfile
return artistProfileDict
}
func add(array: Feed, artistName: String) {
ArtistProfileData.sharedInstance.artistProfileDict[artistName]!.feeds.append(array)
}
}
です
私はここで問題を把握することはできません。どんな助けもありがとう。ありがとうございました。このコードを置き換えることにより、
あなたの 'Profile'オブジェクトはどのように見えますか? – ingaham
私は質問@ingaham –
を編集しました残念ながら、バグはおそらくこのコードに関連していません...私はちょうどコピー&あなたのコードを(フィード構造体を作成する)、そして期待どおりに動作します。しかし、あなたの解決策は、 'feeds'配列を変更するのが本当に簡単なので、ある時点でそれをオーバーライドしたり、オブジェクトを削除したりすることはおそらくありません。 – ingaham