'_'不能转换为StringLiteralConvertible错误

时间:2015-08-25 14:04:56

标签: ios xcode string swift dictionary

我在swift中声明字典时遇到问题;我的代码如下:

var params = [
        "userComment":photo.userComment,
        "privacy":photo.privacy.value,
        "commentsPermission":photo.commentsPermission.value,
        "shouldHideExactLocation":photo.hideExactLocation,
        "tags":TagFormatConversionHelper.dictToArray(photo.hashtags)
    ] as [String: AnyObject]

用户注释字符串上的“u”上有错误“'_'不能转换为StringLiteralConvertible”。我在课堂上进一步使用了相同的代码,它工作正常。

任何和所有帮助将不胜感激。

截图:

enter image description here

照片的类定义:

@interface Photo : AWSPhoto

@property (nonatomic) NSInteger photoID;

@property (nonatomic) NSInteger userID;
@property (nonatomic) NSString *userName;
@property (nonatomic) NSString *uploaderFacebookId;
@property (nonatomic) NSString *uploaderGooglePlusId;

@property (nonatomic) NSArray *hashtags;
@property (nonatomic) NSDate *dateUploaded;
@property (nonatomic) double locationLatitude;
@property (nonatomic) double locationLongitude;

@property (nonatomic) NSString *userComment;
@property (nonatomic) Privacy privacy;
@property (nonatomic) CommentsPermission commentsPermission;
@property (nonatomic) BOOL isTrending;
@property (nonatomic) BOOL isVerifiedUser;
@property (nonatomic) PromotedStatus promotedStatus;
@property (nonatomic) NSInteger upvotes;
@property (nonatomic) NSInteger downvotes;
@property (nonatomic) Rating userRating;

@property (nonatomic) AssetType assetType;

@property (nonatomic) NSString *fileName;
@property (nonatomic) NSString *thumbnailFileName;

@property (nonatomic) GeoLocation *geolocation;
@property (nonatomic) NSInteger locationID;

@property (nonatomic) BOOL userReported;

@property (nonatomic) BOOL hideExactLocation;


@property (nonatomic) BOOL isTopGroups;
@end

和TagFormatConversionHelper:

    struct TagFormatConversionHelper {

    static func arrayToDict(tagArray: [String], knownTrendingTags: [String]) -> [[String : AnyObject]] {

        var arr = [[String : AnyObject]]()

        for tag in tagArray {

            var dict = [String : AnyObject]()

            if contains(knownTrendingTags, tag) {

                dict["isTrending"] = 1

            } else {

                dict["isTrending"] = 0

            }

            dict["tag"] = tag

            arr.append(dict)
        }

        return arr
    }

    static func dictToArray(tagDictArr: [[String : AnyObject]]) -> [String] {

        var arr = [String]()

        for tagDict in tagDictArr {

            arr.append((tagDict["tag"] as! String))

        }

        return arr
    }
}

0 个答案:

没有答案