swift - NSScanner scanString: intoString: not working in playground -
i'm trying make swift version of xml parser som weather data: import cocoa import foundation let string2: nsstring? = "cdefg jajaja <time> bbb" let scanner = nsscanner(string: string2) scanner.string let searchstring:nsstring? = "<time" var result: nsstring? = nil //= autoreleasingunsafepointer<nsstring?> scanner.characterstobeskipped = nil scanner.scanstring(searchstring, intostring: nil) // not working (false) scanner.scanuptostring( ">", intostring: &result) // working result // result = "cdefg jajaja <time" why "scanner.scanstring(searchstring, intostring: nil)" returning nil? actually, problem has nothing swift (equivalent objective-c code same) – you're using nsscanner wrong. docs scanstring:intostring: return value yes if string matches characters @ scan location, otherwise no. basically, scanstring:intostring: either finds searchstring @ current position (...