Socialbase
Socialbase is a framework for building SNS in Cloud Firestore.
❗️
Requirements - iOS 10 or later
- Swift 4.0 or later
- Firebase firestore
- Cocoapods 1.4
❗️ gem install cocoapods
Installation ⚙
CocoaPods
- Insert
pod 'Socialbase'
to your Podfile. - Run
pod install
.
Usage
Make your User defined by Pring compliant with Socialbase.
@objcMembers
final class User: Object, Socialbase {
dynamic var name: String = "USER_NAME"
dynamic var type: String = UserType.none.rawValue
// Organizable
let organizations: ReferenceCollection<User> = []
let peoples: ReferenceCollection<User> = []
// Followable
let followers: ReferenceCollection<User> = []
let followees: ReferenceCollection<User> = []
}
extension User {
typealias Invitation = Test.Invitation
}
class Test {
@objcMembers
class Invitation: Object, InvitationProtocol {
typealias Element = User
dynamic var status: String = Status.none.rawValue
dynamic var message: String?
dynamic var toID: String = ""
dynamic var fromID: String = ""
}
}
extension User {
typealias FollowRequest = Test.FollowRequest
}
extension Test {
@objcMembers
class FollowRequest: Object, FollowRequestProtocol {
typealias Element = User
dynamic var status: String = Status.none.rawValue
dynamic var message: String?
dynamic var toID: String = ""
dynamic var fromID: String = ""
}
}
Invite users to your organization.
let user0: User = User(id: "user0", value: [:]) // Organization user
let user1: User = User(id: "user1", value: [:])
let invitation: Test.Invitation = Test.Invitation(fromID: user0.id, toID: user1.id)
invitation.save()
Following users.
let user0: User = User(id: "user0", value: [:])
let user0: User = User(id: "user1", value: [:])
user1.follow(from: user0)